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);
}
}