Ich versuche eine einfache Formel von SUM(E1:E6)
zu erstellen, aber behalte immer eine Value cannot be null. Parameter name: stream
. Ich habe ein =
vor und habe es sogar Kleinbuchstaben ohne Erfolg gemacht. Eine Formel, die ich zur Arbeit bekommen konnte, war 1 + 3 + 8
. Ich versuchte dann E1 + E2 + E3 + E4 + E5 + E6
und das gab den gleichen Fehler.NPOI Core - Formula Issue
Hier ist mein Code:
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet1 = workbook.CreateSheet("Project Time");
... Other numeric and textual cells fill in and work great
row = sheet1.CreateRow(RowIndex++);
var test = row.CreateCell(ColIndex++);
test.SetCellType(CellType.Formula);
test.SetCellFormula($"1 + 2 + 3 + 4 + 5 + 6"); // WORKS
test.SetCellFormula($"SUM(1 + 2 + 3 + 4 + 5 + 6)"); // FAILS
test.SetCellFormula($"SUM(E1:E6)"); // FAILS
test.SetCellFormula($"E1 + E2 + E3"); // FAILS
XSSFFormulaEvaluator.EvaluateAllFormulaCells(workbook);
workbook.Write(TheStream);
Die GitHub Lage is here.
siehe diesen Link https://stackoverflow.com/questions/25077009/npo-i-setcellformula-custom-formula-in-vba. Entferne $ von SetCellFormula ($ "SUM (E1: E6)"); –
@kumarchandraketu Das '$' ist ein Präfix für die Formatierung von C# -Strings und beeinflusst dies in keiner Weise. Ich nahm es heraus und bekam das gleiche Ergebnis. Die Dokumentationsverknüpfung von dem SO-Link, den du erwähnst, zeigt auch nicht, was ich tue und gab wirklich keine Einsichten darüber, was ich vermisse oder was ich falsch mache. – Grandizer
Ich schlage vor, Sie SetCellFormula ("= SUMME (E1: E6)"); oder SetCellFormula ($ "= SUMME (E1: E6)"); Manchmal funktioniert die Syntax aus der Dokumentation nicht in NPOI, daher müssen Sie vielleicht Ihre Problemumgehung mit hit or miss ausprobieren :) –