Commit 846e58a9 by Licx

设置打开Excel时将更新公式

parent 79095838
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Performance.DtoModels;
......@@ -305,5 +306,30 @@ public static void EvaluateAll(this IWorkbook workbook)
return;
}
}
/// <summary>
/// 设置打开Excel时将更新公式
/// </summary>
/// <param name="workbook"></param>
public static void ForceFormulaRecalculation(this IWorkbook workbook)
{
try
{
if (workbook == null) return;
int index = 0;
while (index < workbook.NumberOfSheets)
{
var sheet = workbook.GetSheetAt(index);
index++;
sheet.ForceFormulaRecalculation = true;
}
}
catch
{
return;
}
}
}
}
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using OfficeOpenXml;
using Performance.DtoModels;
using Performance.EntityModels;
......@@ -10,7 +7,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService
{
......@@ -152,22 +148,8 @@ public static void ClearSheetPartialData(ISheet sheet, PerSheetPoint point, Shee
{
var cell = row.GetCell(j);
if (cell == null) continue;
if (cell.CellType == CellType.Formula)
{
try
{
BaseFormulaEvaluator e = row.Sheet.Workbook is XSSFWorkbook
? new XSSFFormulaEvaluator(row.Sheet.Workbook)
: new HSSFFormulaEvaluator(row.Sheet.Workbook);
cell = e.EvaluateInCell(cell);
}
catch
{
continue;
}
}
else if (cell.CellType != CellType.Formula || sheetType == SheetType.Income)
if (cell.CellType != CellType.Formula || sheetType == SheetType.Income)
{
cell.RemoveCellComment();
row.RemoveCell(cell);
......
......@@ -11,7 +11,6 @@
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
namespace Performance.Services.ExtractExcelService
{
......
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