2012-09-07 32 views
1

我已經有一段時間從事Azure Web角色的EPPlus(Office Open XML)工作,但最近我一直在嘗試使用Azure Web站點,並且出現了一個非常奇怪的錯誤;爲什麼我在Azure網站上獲得Divide By Zero Exception?

[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) 

我在相同的數據和代碼是在Azure Web角色運行得到這個。

編輯: 違規的線條看起來像這樣:

var chart = pivotWorksheet.Drawings.AddChart("PivotChart", eChartType.ColumnClustered, pivotTable); 
chart.SetPosition(endRow + 2, 20, 1, 10); 
chart.SetSize(600, 400); 

請注意,我確信, 'endRow' 是> 1

任何想法?

+0

我不確定這可能是特定於Windows Azure網站的,通過您提供的代碼示例的外觀,沒有任何內容訪問底層環境的信息。 –

+0

不會這麼認爲......但是,當我刪除'SetPosition'和'SetSize'調用它的作品!所以我就是這樣「修復」它的。 – noocyte

+0

是的,這將工作,因爲這是有問題的代碼。我想了解可能導致問題的原因。你能告訴我在哪裏下載EPPlus,以便我可以看到'SetPosition'在做什麼? –

回答

2

自己有同樣的問題,我已經拉EPPlus來源,並做了一些偵查。

的問題是ExcelWorkbook.cs線283電話

System.Windows.Forms.TextRenderer.MeasureText(字符串,字體).WIDTH

這似乎在Azure中的網站返回零。

我剛添加了一行

如果(_standardFontWidth == 0)_standardFontWidth = 7;

(7是我在本地獲得,因此要照我的默認值 - 您的里程可能會有所不同),這意味着我結束了

public decimal MaxFontWidth 
    { 
     get 
     { 
      if (_standardFontWidth == decimal.MinValue) 
      { 
       var font = Styles.Fonts[0]; 
       System.Drawing.Font f = new System.Drawing.Font(font.Name, font.Size); 
       _standardFontWidth=(decimal)(System.Windows.Forms.TextRenderer.MeasureText("00", f).Width - System.Windows.Forms.TextRenderer.MeasureText("0", f).Width); 
      } 
      if (_standardFontWidth == 0) _standardFontWidth = 7; 
      return _standardFontWidth; 
     } 
    } 

當然,這是指從源代碼構建EPPlus,你可能對於7有一個不同的值,但它對我來說是一個有用的解決方法!

+1

與Web或工作者角色(您可以在遠程桌面中)不同,Azure網站中沒有GDI或Desktop,因此如果沒有桌面,則無法使用像素來衡量事物。 (Scott Hanselman在推特上指出) – Andiih

+0

好東西,可以看到這個問題在Codeplex上註冊(http://epplus.codeplex.com/workitem/14742)。我已經添加了一個鏈接到這個問題和問題(跟蹤)。 – noocyte

+0

+1 - 因爲這爲我節省了一大堆工作! – Stuart

相關問題