1 usingNpoi. HSSF. Usermodel;2 usingMicrosoft.VisualStudio.TestTools.UnitTesting;3 usingSystem.IO;4 namespaceNpoi. Sample15 {6 /// <summary>7 ///Create an Excel file8 /// </summary>9 [TestClass]Ten Public classCreateexcelfile One { A /// <summary> - ///use Npoi to create a standard Excel file - /// </summary> the [TestMethod] - Public voidCreateexcel () - { - //Create a workbook +Hssfworkbook Hssfworkbook =NewHssfworkbook (); - + //Create a standard Excel file Microsoft rules standard Excel file with 3 sheet (table) AHssfworkbook. Createsheet ("Sheet1"); atHssfworkbook. Createsheet ("Sheet2"); -Hssfworkbook. Createsheet ("Sheet3"); - - //Create a file stream -FileStream filestream=NewFileStream (@"C:\demo.xls", FileMode.Create); - //Excel file write to file stream in Hssfworkbook. Write (fileStream); - //Close File Stream to filestream.close (); + } - } the}
Npoi-excel Series-1000. Create a standard Excel file