使用SetCellFormula(),注意公式不需要加=,參考下面範例:
public static void CreateFile()
{
    var wb = new XSSFWorkbook();
    var ws = wb.CreateSheet("Test");
    ws.CreateRow(0);
    ws.GetRow(0).CreateCell(0).SetCellValue("欄位1");
    ws.GetRow(0).CreateCell(1).SetCellValue("欄位2");
    ws.GetRow(0).CreateCell(2).SetCellValue("欄位3");
    ws.GetRow(0).CreateCell(3).SetCellValue("欄位4");
    ws.GetRow(0).CreateCell(4).SetCellValue("欄位5");
    ws.GetRow(0).CreateCell(5).SetCellValue("合計");
    ws.CreateRow(1);
    ws.GetRow(1).CreateCell(0).SetCellValue("編號");
    ws.GetRow(1).CreateCell(1).SetCellValue(1);
    ws.GetRow(1).CreateCell(2).SetCellValue(2);
    ws.GetRow(1).CreateCell(3).SetCellValue(1);
    ws.GetRow(1).CreateCell(4).SetCellValue(2);
    ws.GetRow(1).CreateCell(5).SetCellFormula($"SUM(B2:E2)");
    var file = new FileStream(@"D:\test.xlsx", FileMode.Create);
    wb.Write(file);
    file.Close();
}