epplus读取excel里的数据
Posted 二狗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了epplus读取excel里的数据相关的知识,希望对你有一定的参考价值。
FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
using (ExcelPackage pck = new ExcelPackage(fs))
{
ExcelWorksheet ws = pck.Workbook.Worksheets[1];
int minColumnNum = ws.Dimension.Start.Column;//工作区开始列
int maxColumnNum = ws.Dimension.End.Column; //工作区结束列
int minRowNum = ws.Dimension.Start.Row; //工作区开始行号
int maxRowNum = ws.Dimension.End.Row; //工作区结束行号
if (vC == null)
{
for (int j = 1; j <= maxColumnNum; j++)
{
vC = new DataColumn("" + j, typeof(string));
dt.Columns.Add(vC);
}
}
var CountRows = 0;
for (int n = 1; n <= maxRowNum; n++)
{
Regex rex = new Regex(@"STYLE:\d{6}");
// DataRow vRow = dt.NewRow();
for (int m = 1; m <= maxColumnNum; m++)
{
if (ws.Cells[n, m].Value!=null)
{
if (rex.IsMatch(ws.Cells[n, m].Value.ToString()))
{
CountRows = n;
break;
}
}
}
}
for (int n = CountRows + 2; n <= maxRowNum; n++)
{
DataRow vRow = dt.NewRow();
for (int m = 1; m <= maxColumnNum; m++)
{
ws.Cells[n, 1].Value = n;
if (ws.Cells[n, m].Value != null)
{
vRow[m - 1] = ws.Cells[n, m].Value;
}
}dt.Rows.Add(vRow);
}
}
以上是关于epplus读取excel里的数据的主要内容,如果未能解决你的问题,请参考以下文章
EpPlus读取生成Excel帮助类+读取csv帮助类+Aspose.Cells生成Excel帮助类
.NET Core(C#) EPPlus读取Excel(.xlsx)文件的方法及示例代码