0
class Program
{
    static void Main(string[] args)
    {
        EditExcel();
    }

    static void EditExcel()
    {
        string path = @"test.xlsx";
        XSSFWorkbook workbook = new XSSFWorkbook(path);
        var sheet = workbook.GetSheetAt(0);

        var row = sheet.GetRow(4);
        var cell = row.GetCell(3);
        cell.SetCellType(CellType.Formula);
        cell.SetCellFormula("SUM(E4:F4)");
        FileStream fs = new FileStream(@"newTest.xlsx", FileMode.Create, FileAccess.Write);
        workbook.Write(fs);
    }
}

Above is the test code that I write. I tested it in windows10, .net core3.1 Visual Studio 2019. NPOI version is 2.5.2 But I got the fllowing error: enter image description here So How can I slove this problem? Thanks

david.gao
  • 41
  • 8
  • Shouldn't it be "=SUM(E4:F4)" Is it simply that you are missing the equals? – Ryan Thomas Apr 02 '21 at 08:27
  • No, it shouldn't. If you add equals sign, it will throw the following exception: Unhandled exception. NPOI.SS.Formula.FormulaParseException: The specified formula '=SUM(E4:F4)' starts with an equals sign which is not allowed. – david.gao Apr 06 '21 at 00:37

1 Answers1

1

It's a bug in NPOI 2.5.2. I was facing the same issue in my app and only workaround for now is to downgrade to 2.5.1. It should be fixed in the next release 2.5.3.

user2250152
  • 14,658
  • 4
  • 33
  • 57