1.
1 usingNpoi. HSSF. Usermodel;2 usingNpoi. HPSF;3 usingNpoi. Poifs. FileSystem;4 usingMicrosoft.VisualStudio.TestTools.UnitTesting;5 usingSystem.IO;6 usingSystem;7 namespaceNpoi. Sample18 {9 /// <summary>Ten ///Create an Excel file One /// </summary> A [TestClass] - Public classCreateexcelfile - { the /// <summary> - ///Create an Excel file with document Summary information and Summary information - /// </summary> - [TestMethod] + Public voidcreateexcelandsummary () - { + //1. First create a workbook AHssfworkbook Workbook =NewHssfworkbook (); at - //2. Create summary information for Excel files (documentsummaryinformation) -Documentsummaryinformation dsi =propertysetfactory.createdocumentsummaryinformation (); -Dsi.company ="Npoi Study Team";//Unit name - - //3. Create SummaryInformation inSummaryInformation si =propertysetfactory.createsummaryinformation (); - toSi. Author ="Wang Guangxu";//author +Si. Createdatetime = DateTime.Now;//creation Time -Si. Subject ="Create an Excel document with Npoi and document summary information";//Theme the * //Set Document information for a workbook $Workbook. Documentsummaryinformation =DSi;Panax NotoginsengWorkbook. SummaryInformation =si; - the //Create a worksheet (note: A standard Excel file needs to create 3 sheet) +Workbook. Createsheet ("Sheet1"); A the //Create a file stream +FileStream FileStream =NewFileStream (@"C:demo1.xls", FileMode.Create); - $ //to write a workbook to an Excel file by using a file stream $ workbook. Write (fileStream); - //Close File Stream - filestream.close (); the } - Wuyi } the}
2. The effect is as follows:
Npoi-excel Series-1002. Create an Excel file with document Summary information and Summary information