Commit c7bd4929 by lcx

no message

parent 7b7e9c17
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
namespace Performance.Services.ExtractExcelService namespace Performance.Services.ExtractExcelService
{ {
...@@ -151,5 +152,36 @@ public static IWorkbook GetWorkbook(string filePath) ...@@ -151,5 +152,36 @@ public static IWorkbook GetWorkbook(string filePath)
return workbook; return workbook;
} }
public static List<string> GetCellValues(this IRow row)
{
List<string> list = new List<string>();
if (row == null || row.Cells == null || !row.Cells.Any()) return list;
list = row.Cells.Select(t => t.GetDecodeEscapes()).ToList();
return list;
}
public static Dictionary<string, int> GetCellIndex(this IRow row, params string[] list)
{
Dictionary<string, int> pairs = new Dictionary<string, int>();
if (row == null || row.Cells == null || !row.Cells.Any()) return pairs;
if (list == null || !list.Any()) return pairs;
var columns = row.Cells.Select(t => t.GetDecodeEscapes()).Distinct().ToList();
foreach (string key in list)
{
if (!pairs.ContainsKey(key) && columns.Contains(key))
{
pairs.Add(key, columns.IndexOf(key));
}
}
return pairs;
}
} }
} }
...@@ -12,15 +12,35 @@ public class EmployeeDataWrite : ISheetDataWrite ...@@ -12,15 +12,35 @@ public class EmployeeDataWrite : ISheetDataWrite
{ {
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, object data) public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, object data)
{ {
if (data == null || (data is IEnumerable<per_employee> employees && !employees.Any())) return; if (data is IEnumerable<per_employee> employees && employees.Any(t => accountingUnits.Contains(t.UnitType)))
{
int dataFirstRowNum = point.DataFirstRowNum.Value; int dataFirstRowNum = point.DataFirstRowNum.Value;
//foreach (var employee in employees) var columns = sheet.CreateRow(point.HeaderFirstRowNum.Value).GetCellValues();
//{
// var row = sheet.GetOrCreate(dataFirstRowNum); foreach (var employee in employees)
{
var row = sheet.GetOrCreate(dataFirstRowNum);
for (int cellIndex = 0; cellIndex < columns.Count(); cellIndex++)
{
var column = columns[cellIndex];
if (string.IsNullOrEmpty(column) || !employeeDict.ContainsKey(column)) continue;
var cell = row.GetOrCreate(cellIndex);
cell.SetCellOValue(employeeDict[column].Invoke(employee));
}
dataFirstRowNum++;
}
}
}
private void ClearHistoryData(ISheet sheet, PerSheetPoint point, List<per_employee> employees, List<string> columns, ref int dataFirstRowNum)
{
foreach (var employee in employees)
{
var row = sheet.GetRow(dataFirstRowNum);
//} }
} }
private readonly string[] accountingUnits = new string[] { AccountUnitType.行政高层.ToString(), AccountUnitType.行政中层.ToString(), AccountUnitType.行政工勤.ToString() }; private readonly string[] accountingUnits = new string[] { AccountUnitType.行政高层.ToString(), AccountUnitType.行政中层.ToString(), AccountUnitType.行政工勤.ToString() };
......
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