C #. Net:excel npoi Import and export operation Tutorial read 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"))
{
Workbook objects Get Excel content
Iworkbook workbook = new Hssfworkbook (FILESRC);
for (int i = 0; i < workbook. Numberofsheets; i++)
{
Get a worksheet in a workbook
isheet sheet = workbook. Getsheetat (i);
Console.WriteLine (sheet. SheetName);
for (int r = 0; r <= sheet. Lastrownum; r++)
{
Get information for each table
IRow row = sheet. GetRow (r);
for (int c = 0; c < row. Lastcellnum; C + +)
{
Get information for each cell in each row
Icell cell = row. Getcell (c);
Console.WriteLine (cell. ToString () + "| ");
}
}
}
———————— Share End ————————
C #. Net:excel npoi Import and export operation Tutorial read Excel file information and output