syneffort 1 year ago
parent 39effecfe9
commit 6663282452
  1. 7
      ExcelHelper/ExcelHelperFW/ExcelHelper.cs

@ -25,7 +25,7 @@ namespace ExcelHelperFW
/// <param name="tempPath">copy path</param> /// <param name="tempPath">copy path</param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception>
public List<Dictionary<string, string>> GetData(string sourcePath, string sheetName, bool removeHeader, int rowStartPosition = 1, string tempPath = "./temp_file.xlsx") public List<Dictionary<string, string>> GetData(string sourcePath, string sheetName, bool removeHeader, int rowStartPosition = 1, Func<Dictionary<string, string>, bool> continueFunc = null, string tempPath = "./temp_file.xlsx")
{ {
File.Copy(sourcePath, tempPath, true); File.Copy(sourcePath, tempPath, true);
@ -38,7 +38,7 @@ namespace ExcelHelperFW
Sheet sheet = workbookPart.Workbook.Descendants<Sheet>().FirstOrDefault(s => s.Name == sheetName); Sheet sheet = workbookPart.Workbook.Descendants<Sheet>().FirstOrDefault(s => s.Name == sheetName);
if (sheet == null) if (sheet == null)
throw new Exception("Cannot find sheet."); throw new Exception($"Cannot find sheet. (Sheet name: {sheetName})");
WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id); WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id);
Worksheet worksheet = worksheetPart.Worksheet; Worksheet worksheet = worksheetPart.Worksheet;
@ -53,6 +53,9 @@ namespace ExcelHelperFW
if (rowPairs == null || rowPairs.Count < 1) if (rowPairs == null || rowPairs.Count < 1)
continue; continue;
if (continueFunc != null && continueFunc(rowPairs))
continue;
data.Add(rowPairs); data.Add(rowPairs);
} }
} }

Loading…
Cancel
Save