c# .Net :Excel NPOI導入導出操作教程之讀取Excel文件信息及輸出
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
//創建文件流對象
using (FileStream filesrc = File.OpenRead(@"C:\Users\Administrator\Desktop\123.xls"))
{
//工作簿對象獲取Excel內容
IWorkbook workbook = new HSSFWorkbook(filesrc);
for (int i = 0; i < workbook.NumberOfSheets; i++)
{
////獲得工作簿裡面的工作表
ISheet sheet = workbook.GetSheetAt(i);
Console.WriteLine(sheet.SheetName);
for (int r = 0; r <= sheet.LastRowNum; r++)
{
//獲取每張表的信息
IRow row = sheet.GetRow(r);
for (int c = 0; c < row.LastCellNum; c++)
{
//獲得每行中每個單元格信息
ICell cell = row.GetCell(c);
Console.WriteLine(cell.ToString() + " | ");
}
}
}
————————分享End————————