To get the template file path:
string " \\xls\\ file name. xls "; The front "\\xls\\ is the file path", can be as follows: \\Users\\Administrator\\Desktop\\
Hssfworkbook Hssfworkbookdown; Create an Excel object // read into the Excel file that you just copied usingthenew FileStream ( Modelexlpath, FileMode.Open, FileAccess.Read)) //path, open permissions, Read permissions { new Hssfworkbook ( file); File. Close ();}
//a page of the template in the Getsheetat method, the first page here is 0Hssfsheet Sheet1 = (hssfsheet) hssfworkbookdown.getsheetat (0); //start writing data to an Excel table//Modify Cell, this is 2nd row 5th columnHssfcell cell = (Hssfcell) Sheet1. GetRow (2). Getcell (5); Here 25 is 3F, which is F3 cell. Setcellvalue (Double. Parse ("2.5")); Here the set type is double, the value written is 2.5//Modify Cell, this is 2nd row 9th columnCell = (Hssfcell) Sheet1. GetRow (2). Getcell (9); Cell. Setcellvalue (Double. Parse ("2.9"));
Next Save the file:
New" file name. xls"; // file name sfd. Filter = Excel Workbook (*.xls) |*.xls"; File type sfd. ShowDialog (); // Create a file New FileStream (SFD). FileName, FileMode.Create); hssfworkbookdown.write (files); Files. Close ();
To save to a new directory in a new file after reading the Excel template modification data