c# .Net :Excel NPOI导入导出操作教程之读取Excel文件信息及输出

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————————

上一篇:NPOI操作Excel导入DataTable中


下一篇:NPOI操作EXCEL(四)——反射机制批量导出excel文件