To use npoi to create multiple sheets in the same Excel file, you only need to create multiple sheets in the same workbook. Note that the sheet name must be unique. The following is the implementation code:
Private void buttontest_click (Object sender, eventargs e) {hssfworkbook workbook = new hssfworkbook (); // isheet Sheeta = workbook. createsheet ("Sheeta"); // isheet sheetb = workbook. createsheet ("sheetb"); createsheet (workbook, "Sheeta"); createsheet (workbook, "sheetb"); createsheet (workbook, "sheetc"); string Path = application. startuppath + @ "\ test.xls"; if (file. exists (PATH) {file. delete (PATH);} u Sing (filestream file = new filestream (path, filemode. Create) {Workbook. Write (File); // create an Excel file. File. close ();} MessageBox. show ("OK");} private isheet createsheet (hssfworkbook workbook, string sheetname) {isheet sheet = workbook. createsheet (sheetname); irow rowhead = sheet. createrow (0); For (INT icolumnindex = 0; icolumnindex <10; icolumnindex ++) {rowhead. createcell (icolumnindex ). setcellvalue (guid. newguid (). tostring () ;}for (INT irowindex = 0; irowindex <20; irowindex ++) {irow rowbody = sheet. createrow (irowindex + 1); For (INT icolumnindex = 0; icolumnindex <10; icolumnindex ++) {rowbody. createcell (icolumnindex ). setcellvalue (datetime. now. millisecond); sheet. autosizecolumn (icolumnindex) ;}} return sheet ;}