码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-10-14 20:19:19      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://www.cnblogs.com/jicheng/p/5961566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!