Create an Excel file using NPOI and an excel file using npoi

Source: Internet
Author: User

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:

 

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.