This is an excel file exported through Microsoft office. Why is it exported through Microsoft office? Because npoi office is used for export, it does not support one format (excel file in html format ), however, office support is supported. Therefore, write a blog, share it with you, and share it with you.
Method of thinking: Read the excel file of the file, and then export the corresponding format through the template format
////// Export excel //////Read File Path///Save File ContentPublic static void ReadFile (string readFileName, string saveFileName) {Microsoft. office. interop. excel. workbookClass wbclass; WorkbookClass wkTemp; Worksheet ws; Worksheet wsTemp; Microsoft. office. interop. excel. application excelApp; DirectoryInfo di = new DirectoryInfo (readFileName); // traverses the folder if (di. exists) {foreach (FileInfo item in di. getFiles ("*. xls ") {excelApp = new Microsoft. office. interop. E Xcel. application (); object objOpt = System. reflection. missing. value; // item. fullName reads the execl file wbclass = (WorkbookClass) excelApp. workbooks. open (item. fullName, objOpt, false, objOpt, true, objOpt, objOpt, true, objOpt, objOpt); ws = (Worksheet) wbclass. worksheets. get_Item (1); // get the total number of record rows (including the title column) int rowsint = ws. usedRange. cells. rows. count; // get the number of rows // int columnsin T = mySheet. usedRange. cells. columns. count; // obtain the number of columns Range rng1 = ws. cells. get_Range ("C1", "C" + rowsint); // rang Range rng2 = ws. cells. get_Range ("D1", "D" + rowsint); // rang Range rng3 = ws. cells. get_Range ("E1", "E" + rowsint); // rang Range rng4 = ws. cells. get_Range ("F1", "F" + rowsint); // rang object [,] CallType = (object [,]) rng1.Value2; object [,] activeCall = (object [,]) rng2.Value2; object [,] Passi VityCall = (object [,]) rng3.Value2; object [,] CallDate = (object [,]) rng4.Value; // read wkTemp = (WorkbookClass) excelApp through a template. workbooks. open ("D :\\ Template.xls", objOpt, false, objOpt, true, objOpt, objOpt, true, objOpt, objOpt ); wsTemp = (Worksheet) wkTemp. worksheets. get_Item (1); Range rngD = (Range) wsTemp. columns ["D", Type. missing]; // set the cell format Range rngE = (Range) w STemp. columns ["E", Type. missing]; // set the cell format rngD. numberFormat = "yyyy-mm-dd hh: mm: ss"; rngE. numberFormat = "hh: mm: ss"; // write the information excel file for (int I = 1; I <rowsint; I ++) {wsTemp. cells [I, 1] = CallType [I, 1]. toString (); wsTemp. cells [I, 2] = ActiveCall [I, 1]. toString (); wsTemp. cells [I, 3] = PassivityCall [I, 1]. toString (); wsTemp. cells [I, 4] = PassivityCall [I, 1]. toString ();} wsTemp. saveAs (saveFile Name + "\ 1.xls", Missing. value, Missing. value, Missing. value, Missing. value, Missing. value, Missing. value, Missing. value, Missing. value, Missing. value); excelApp. workbooks. close (); // Close the opened document. Otherwise, the student ID will display the scientific notation. ExcelApp. Quit ();}}}