C #. Net: Excel NPOI Import and Export tutorial-reading Excel File Information and output,
C #. Net: Excel NPOI Import and Export tutorial-reading Excel File Information and Output
Using NPOI. HSSF. UserModel;
Using NPOI. SS. UserModel;
Using System;
Using System. Collections. Generic;
Using System. IO;
// Create a file stream object
Using (FileStream filesrc = File. OpenRead (@ "C: \ Users \ Administrator \ Desktop \ 123.xls "))
{
// Obtain the Excel content from the workbook object
IWorkbook workbook = new HSSFWorkbook (filesrc );
For (int I = 0; I <workbook. NumberOfSheets; I ++)
{
//// Obtain the worksheet in the workbook
ISheet sheet = workbook. GetSheetAt (I );
Console. WriteLine (sheet. SheetName );
For (int r = 0; r <= sheet. LastRowNum; r ++)
{
// Obtain the information of each table
IRow row = sheet. GetRow (r );
For (int c = 0; c <row. LastCellNum; c ++)
{
// Obtain information about each cell in each row
ICell cell = row. GetCell (c );
Console. WriteLine (cell. ToString () + "| ");
}
}
}
-------- Share End --------