Commit 2c1dda0b by lcx

自定义提取,删除历史数据

parent 027b1210
...@@ -63,7 +63,7 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st ...@@ -63,7 +63,7 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st
sheet = workbook.CreateSheet(module.ModuleName); sheet = workbook.CreateSheet(module.ModuleName);
workbook.SetSheetOrder(sheet.SheetName, workbook.NumberOfSheets - 1); workbook.SetSheetOrder(sheet.SheetName, workbook.NumberOfSheets - 1);
} }
ClearSheetData(sheet);
var exscript = exscripts.FirstOrDefault(t => t.TypeId == module.TypeId); var exscript = exscripts.FirstOrDefault(t => t.TypeId == module.TypeId);
if (exscript == null) continue; if (exscript == null) continue;
...@@ -76,9 +76,10 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st ...@@ -76,9 +76,10 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st
try try
{ {
// 没数据跳过 // 没数据跳过
if (dynamics == null || dynamics.Count() == 0) if (dynamics == null || !dynamics.Any())
continue; continue;
logger.LogInformation($"{module.ModuleName}开始写入数据,{dynamics.Count()}");
var first = (IDictionary<string, object>)dynamics.ElementAt(0); var first = (IDictionary<string, object>)dynamics.ElementAt(0);
var header = sheet.GetOrCreate(Point.HeaderFirstRowNum.Value); var header = sheet.GetOrCreate(Point.HeaderFirstRowNum.Value);
if (header != null) if (header != null)
...@@ -116,5 +117,35 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st ...@@ -116,5 +117,35 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st
} }
} }
} }
private void ClearSheetData(ISheet sheet)
{
try
{
for (int i = Point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row != null)
{
row.ZeroHeight = false; //取消隐藏行
int dataFirstCellRowNum = Point.DataFirstCellNum.Value;
//跳过核算单元和科室
for (int j = dataFirstCellRowNum; j < row.LastCellNum; j++)
{
var cell = row.GetCell(j);
if (cell != null && cell.CellType != CellType.Formula)
{
cell.RemoveCellComment();
row.RemoveCell(cell);
}
}
}
}
}
catch (Exception ex)
{
logger.LogError(ex.Message);
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment