C # create multiple sheets in the same Excel file using npoi

Source: Internet
Author: User

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 ;}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.