Commit d80ba249 by wyc

(提取时)excel如果没有筛选 保存报错问题处理

parent b51941de
...@@ -211,18 +211,24 @@ public static void CloseAutoFilter(string path) ...@@ -211,18 +211,24 @@ public static void CloseAutoFilter(string path)
ExcelWorkbook workbook = package.Workbook; ExcelWorkbook workbook = package.Workbook;
if (workbook == null) return; if (workbook == null) return;
bool shouldSave = false; // 标志是否需要保存文件
foreach (var sheet in workbook.Worksheets) foreach (var sheet in workbook.Worksheets)
{ {
if (sheet.AutoFilterAddress != null) if (sheet.AutoFilterAddress != null)
{ {
sheet.Cells[sheet.AutoFilterAddress.Address].AutoFilter = false; sheet.Cells[sheet.AutoFilterAddress.Address].AutoFilter = false;
shouldSave = true; // 设置标志为需要保存文件
} }
} }
package.Save(); if (shouldSave)
{
package.Save();
}
} }
} }
catch (Exception) catch (Exception)
{ {
} }
} }
......
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