I’ve had EPPlus (Office Open XML) working on a Azure Web Role for some time now, but I’ve been experimenting with Azure Web Sites lately and there I’m getting a very weird error;
[DivideByZeroException: Attempted to divide by zero.]
System.Decimal.FCallDivide(Decimal& d1, Decimal& d2) +0
OfficeOpenXml.Drawing.ExcelDrawing.SetPixelWidth(Int32 pixels, Single dpi) +465
Compliance.Net.CommonCode.PivotGenerator.GeneratePivotTable(ExcelWorksheet dataWorksheet, ExcelWorksheet pivotWorksheet, Int32 endRow)
I am getting this on the same data and code as is running on Azure Web Role.
Edit:
The offending lines look like this:
var chart = pivotWorksheet.Drawings.AddChart("PivotChart", eChartType.ColumnClustered, pivotTable);
chart.SetPosition(endRow + 2, 20, 1, 10);
chart.SetSize(600, 400);
Please note that I have made sure that ‘endRow’ is > 1.
Any ideas?
Having had the same issue myself I’ve pulled the EPPlus source and done some sleuthing.
The issue is in ExcelWorkbook.cs line 283 which calls
System.Windows.Forms.TextRenderer.MeasureText(string,Font).Width
which appears to return Zero in an Azure website.
I’ve just added a line
if (_standardFontWidth == 0) _standardFontWidth = 7;
(7 was the value I was getting locally so it will do as my default – your mileage may vary) meaning I ended up with
Of course this means building EPPlus from source, and you may have a different value for 7, but its a useful workaround for me!