EPPlus 读取Excel表格

EPPlus 读取Excel表格

注意所有表格的索引从1开始
using System;
using System.IO;
using OfficeOpenXml;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            ReadData("zzsTest.xlsx",1);
            Console.ReadKey();
        }

        private static void ReadData(string path,int sheetIndex)
        {
            var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            var excel = new ExcelPackage(fs);
            var sheet = excel.Workbook.Worksheets[sheetIndex];

            var row = sheet.Dimension.End.Row;
            var col = sheet.Dimension.End.Column;
            Console.WriteLine(row);
            Console.WriteLine(col);

            for (var i = 1; i <= row; i++)
            {
                for (var j = 1; j <= col; j++)
                {
                    Console.WriteLine(sheet.Cells[i, j].Value);
                }
            }
            
            excel.Dispose();
            fs.Dispose();
            Console.WriteLine("完成");
        }
    }
}

你可能感兴趣的:(C#,c#)