I would like to transfer a Datatable
to excel and calculate a sum. For this I'm using epplus. Here is my code:
Sheet.Cells["A1"].LoadFromDataTable(dsExcel.Tables[0], true, TableStyles.Medium9);
Sheet.Cells[Sheet.Dimension.Address].AutoFitColumns();
Sheet.View.FreezePanes(3, 3);
int totalCols = Sheet.Dimension.End.Column;
int letztezeile = Sheet.Dimension.End.Row;
var range = Sheet.Cells[1, 1, 1, totalCols];
for (int i = 3; i < totalCols; i++)
{
if (range[1, i].Value.ToString().Contains("Durchfluss")) Sheet.Column(i).Style.Numberformat.Format = "#,##0.00";
}
Sheet.InsertRow(2, 1);
Sheet.Cells["A2"].Value = "Summe";
for (int i = 4; i <= totalCols; i++)
{
Sheet.Cells[2, i, 2, i].Formula = "SUMME(" + range[3, i].Address + ":" + range[letztezeile + 1, i].Address + ")";
}
This is my output:
I have to enter the cell D2 and press Enter, then the formula is working:
So what must I change that the formula is working from the beginning? Thanks
You should change "SUMME" to "SUM", localized formula names is handled by the Excel GUI. The underlying xml (same as Excel produces) assumes that the formula names are in english.
From EPPlus Formula calc documentation: