当前位置:   article > 正文

EPPlus 读取Excel表格_epplus读取excel

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("完成");
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/118531
推荐阅读
相关标签
  

闽ICP备14008679号