Create an Excel file using NPOI and an excel file using npoi
I. NPOI function Syntax:
There are seven NPOI writing scripts, and NPOI writing can be used in the http://npoi.codeplex.com. The difference is:
NPOI. DLL: NPOI core handler.
NPOI. DDF. DLL: NPOI compression function.
NPOI. HPSF. DLL: NPOI file summary information.
NPOI. HSSF. DLL: NPOI Excel BIFF statement.
NPOI. Util. DLL: NPOI tool.
NPOI. POIFS. DLL: npoi ole format.
ICSharpCode. SharpZipLib. DLL.
Ii. Use NPOI to create an Excel file
Using NPOI. HSSF. userModel; using NPOI. SS. userModel; using System. IO; namespace NPOI. writeExcel {class Program {/* NPOI. DLL: NPOI core function handler. NPOI. DDF. DLL: NPOI compression function. NPOI. HPSF. DLL: NPOI file summary information. NPOI. HSSF. DLL: NPOI Excel BIFF statement. NPOI. Util. DLL: NPOI tool. NPOI. POIFS. DLL: npoi ole format. ICSharpCode. SharpZipLib. DLL. */Static void Main (string [] args) {new Program (). createExcel (); new Program (). insertContext () ;}/// <summary >/// create an Excel file /// </summary> private void CreateExcel () {HSSFWorkbook workbook = new HSSFWorkbook (); fileStream filestream = new FileStream (AppDomain. currentDomain. baseDirectory + DateTime. now. toString ("yyyyMMddHHmmss") + ". xls ", FileMode. create); // Add an external computing table. Workbook. createSheet ("compute Table A"); workbook. createSheet ("compute table B"); workbook. createSheet ("compute Table C"); workbook. write (filestream); workbook. close (); filestream. close (); filestream. dispose () ;}/// <summary> /// add content in image Excel /// </summary> private void InsertContext () {HSSFWorkbook workbook = new HSSFWorkbook (); fileStream filestream = new FileStream (AppDomain. currentDomain. baseDirectory + DateTime. now. toStr Ing ("yyyyMMddHHmmss") + ". xls", FileMode. Create); // Add a partition table. ISheet sheet1 = workbook. createSheet ("alias Table A"); ISheet sheet2 = workbook. createSheet ("compute table B"); ISheet sheet3 = workbook. createSheet ("Calculate Table C"); // create rows and columns for (int I = 0; I <10; I ++) in sequence) {IRow row1 = sheet1.CreateRow (I); IRow row2 = sheet2.CreateRow (I); IRow row3 = sheet3.CreateRow (I); for (int j = 0; j <10; j ++) {ICell cell1 = row1.CreateCell (j); cell1.SetCellValue ("th" + (I + 1) + "Row, Nth" + (j + 1) + "column "); ICell cell2 = row2.CreateCell (j); cell2.SetCellValue ("th" + (I + 1) + "Row, Nth" + (j + 1) + "column "); ICell cell3 = row3.CreateCell (j); cell3.SetCellValue ("th" + (I + 1) + "Row, th" + (j + 1) + "column ");}} workbook. write (filestream); workbook. close (); filestream. close (); filestream. dispose ();}}}
3. view the file: