提取空行问题处理

parent 5e46577f
...@@ -131,8 +131,8 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -131,8 +131,8 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
{ {
dataFirstRowNum = point.DataFirstRowNum.Value; dataFirstRowNum = point.DataFirstRowNum.Value;
RemoveIncomeRow(sheet, point); RemoveIncomeRow(sheet, point);
WriteSheetIncomeData(sheet, columnHeader, point, style, headers, data, rows, dataFirstRowNum); var endRowNum = WriteSheetIncomeData(sheet, columnHeader, point, style, headers, data, rows, dataFirstRowNum);
dataFirstRowNum = point.DataFirstRowNum.Value + rows.Count; dataFirstRowNum = endRowNum;
} }
if (data == null || !data.Any()) return; if (data == null || !data.Any()) return;
...@@ -186,11 +186,9 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -186,11 +186,9 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
//数据为空,且单元格值不为空,不写入数据(保留原始值) //数据为空,且单元格值不为空,不写入数据(保留原始值)
// 22.3.29 ry 只要是提取的列头全部覆盖数据 // 22.3.29 ry 只要是提取的列头全部覆盖数据
//if (value.HasValue && value != 0) if (headers != null && headers.Contains(column) && value.HasValue && value != 0)
if (headers != null && headers.Contains(column))
{ {
cell.SetCellValue<decimal>(value ?? 0); cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
} }
} }
...@@ -231,7 +229,8 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -231,7 +229,8 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
foreach (string department in departments) foreach (string department in departments)
{ {
var deptData = data.Where(t => (t.Department ?? "") == department); var deptData = data.Where(t => (t.Department ?? "") == department);
if (deptData != null && deptData.Any())
{
var row = sheet.GetOrCreate(dataFirstRowNum); var row = sheet.GetOrCreate(dataFirstRowNum);
for (int cellIndex = point.HeaderFirstCellNum.Value; cellIndex < columnHeader.LastCellNum; cellIndex++) for (int cellIndex = point.HeaderFirstCellNum.Value; cellIndex < columnHeader.LastCellNum; cellIndex++)
{ {
...@@ -240,15 +239,13 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -240,15 +239,13 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
if (filed.ContainsKey(column)) if (filed.ContainsKey(column))
{ {
var value = (deptData != null && deptData.Any()) ? filed[column]?.Invoke(deptData.First()) : ""; var value = filed[column]?.Invoke(deptData.First());
cell.SetCellOValue(value); cell.SetCellOValue(value);
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
} }
else if (sheetType == SheetType.Income || (headers != null && headers.Contains(column))) else if (sheetType == SheetType.Income || (headers != null && headers.Contains(column)))
{ {
var value = (deptData != null && deptData.Any()) var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
? deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value
: 0;
cell.SetCellValue<decimal>(value); cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
} }
...@@ -256,8 +253,9 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -256,8 +253,9 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
dataFirstRowNum++; dataFirstRowNum++;
} }
} }
}
private static void WriteSheetIncomeData(ISheet sheet, IRow columnHeader, PerSheetPoint point, ExcelStyle style, List<string> headers, private static int WriteSheetIncomeData(ISheet sheet, IRow columnHeader, PerSheetPoint point, ExcelStyle style, List<string> headers,
List<ExtractTransDto> data, List<IncomeRow> incomes, int dataFirstRowNum) List<ExtractTransDto> data, List<IncomeRow> incomes, int dataFirstRowNum)
{ {
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据); var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
...@@ -294,7 +292,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -294,7 +292,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
cell.SetCellValue(content.Value); cell.SetCellValue(content.Value);
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
} }
}
for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++) for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
...@@ -313,11 +311,12 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -313,11 +311,12 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
cell.SetCellValue<decimal>(value); cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
} }
dataFirstRowNum++; dataFirstRowNum++;
data.RemoveAll(t => t.Department == item.Department); data.RemoveAll(t => t.Department == item.Department);
} }
} }
return dataFirstRowNum;
}
public static string HasValue(params string[] list) public static string HasValue(params string[] list)
{ {
......
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