Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the format of a decimal number in EpPlus?

My office Excel is confirate in French Format (separator decimal = Point and separator thousand = space ) i load a sheet with csv file with french format decimal number :

My code:

var range = sheet.Cells["A3"].LoadFromText(new FileInfo(fileCSVFull), format, TableStyles.Medium27, true);
var numStyle = package.Workbook.Styles.CreateNamedStyle("TableNumber");
numStyle.Style.Numberformat.Format = "# ##0,00";

var tbl = sheet.Tables[0];
tbl.ShowTotal = true;
tbl.Columns[0].TotalsRowLabel = "Total";

tbl.Columns[1].TotalsRowFunction = RowFunctions.Sum;
tbl.Columns[1].DataCellStyleName = "TableNumber";
tbl.Columns[2].TotalsRowFunction = RowFunctions.Sum;
tbl.Columns[2].DataCellStyleName = "TableNumber";
tbl.Columns[3].TotalsRowFunction = RowFunctions.Sum;
tbl.Columns[3].DataCellStyleName = "TableNumber";

string numcell = "E4:E"+(3 + nbline); 
sheet.Cells[numcell].Formula = "B4*C4";
sheet.Cells[numcell].StyleName = "TableNumber";

sheet.View.ShowGridLines = false;
sheet.Calculate();
sheet.Cells[sheet.Dimension.Address].AutoFitColumns();

But i have an exception on "sheet.Calculate();" What if I change the format of my decimal number that's good my XLSX file is generated but I have an error when I open Excel as my decimal format is not recognized by my French version of Excel.

like image 940
FredG Avatar asked May 20 '15 12:05

FredG


Video Answer


1 Answers

I faced the similar issue. Setting format string to "#,##0.00" did the trick in my case.

like image 91
Evgeny Safonov Avatar answered Sep 21 '22 23:09

Evgeny Safonov