EPPlus公式未运行

我正在使用EPPlus将一些信息导出到excel中,并且我已经在公式总排上遇到了一个绊脚石。 当我打开文件时,只计算第一个公式,而其他公式只在我进入并离开公式单元格时计算。 下面是构build表的代码和结果。 希望有人可以提供一些关于如何解决这个问题的见解。

private void BuildSalesTable(string label, ISalesTable table) { var sheet = ExcelPackage.Workbook.Worksheets.Add(string.Format("Sales{0}", label)); //table header //BuildHeader(startRow, 2, startRow, 9, string.Format("Sales Tons - {0}", label)); //table lables sheet.Cells[1, 2].Value = "Joist Qtd"; sheet.Cells[1, 3].Value = "PP/Ton"; sheet.Cells[1, 4].Value = "Deck Qtd"; sheet.Cells[1, 5].Value = "PP/Ton"; sheet.Cells[1, 6].Value = "Joist Sold"; sheet.Cells[1, 7].Value = "PP/Ton"; sheet.Cells[1, 8].Value = "Deck Sold"; sheet.Cells[1, 9].Value = "PP/Ton"; for (int i = 0; i < table.Rows.Count; i++) { var row = 2 + i; //every other row coloring if (i == 0 || i%2 == 0) { sheet.Cells[row, 1, row, 9].Style.Fill.PatternType = ExcelFillStyle.Solid; sheet.Cells[row, 1, row, 9].Style.Fill.BackgroundColor.SetColor(Color.Khaki); } //data sheet.Cells[row, 1].Value = table.Rows[i].Location; sheet.Cells[row, 2].Value = table.Rows[i].JoistQuoted; sheet.Cells[row, 3].Value = table.Rows[i].JoistQuotedPP; sheet.Cells[row, 4].Value = table.Rows[i].DeckQuoted; sheet.Cells[row, 5].Value = table.Rows[i].DeckQuotedPP; sheet.Cells[row, 6].Value = table.Rows[i].JoistSold; sheet.Cells[row, 7].Value = table.Rows[i].JoistSoldPP; sheet.Cells[row, 8].Value = table.Rows[i].DeckSold; sheet.Cells[row, 2].Value = table.Rows[i].JoistQuoted; sheet.Cells[row, 9].Value = table.Rows[i].DeckSoldPP; } //totals row sheet.Cells[table.Rows.Count + 2, 1].Value = "Total"; sheet.Cells[table.Rows.Count + 2, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; sheet.Cells[table.Rows.Count + 2, 1].Style.Font.Color.SetColor(Color.Gray); sheet.Cells[table.Rows.Count + 2, 2].Formula = string.Format("=SUM(B2:B{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 3].Value = string.Format("=SUMPRODUCT(B2:B{0},C2:C{0})/SUM(B2:B{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 4].Value = string.Format("=SUM(D2:D{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 5].Value = string.Format("=SUMPRODUCT(D2:D{0},E2:E{0})/SUM(D2:D{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 6].Value = string.Format("=SUM(F2:F{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 7].Value = string.Format("=SUMPRODUCT(F2:F{0},G2:G{0})/SUM(F2:F{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 8].Value = string.Format("=SUM(H2:H{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 9].Value = string.Format("=SUMPRODUCT(H2:H{0},I2:I{0})/SUM(H2:H{0})", table.Rows.Count + 1); sheet.Cells[table.Rows.Count + 2, 2, table.Rows.Count + 2, 9].Style.Font.Color.SetColor(Color.DarkBlue); //format data sheet.Cells[2, 1, 2 + table.Rows.Count, 10].Style.Numberformat.Format = "#,##0"; sheet.Workbook.CalcMode = ExcelCalcMode.Automatic; } 

Excel看起来像这样:

excel文档的临时图像

我是一个白痴。 我正在设置没有运行公式的单元格的值,而不是设置公式。 我不敢相信我花了多长时间看到这一点。