Format Exception in HtmlConverter

Nov 11, 2014 at 10:35 AM
Edited Nov 11, 2014 at 3:50 PM
Hi,

I am new to Open XML and PowerTools. I just recently downloaded PowerTools Core 2.7.04, ran the HtmlConverter01 project and got a format exception for test-01.docx on line 468 in HtmlConverter.cs:
var tabWidth = (decimal)tabWidthAtt;
tabWidthAtt is {pt14:TabWidth="0,11"}. Note that the decimal separator is a comma (probably because of Norwegian locale is used somewhere). Can I fix this by changing some settings?

(note that this is easily fixed by changing the code to
var tabWidth =decimal.Parse(tabWidthAtt.Value);
But that should not be necessary.)
Nov 11, 2014 at 3:50 PM
Things like
string.Format("{0:0.00}", (decimal)delta2 / 1440m)
are all over the place in HtmlConverter.cs, also for css. That does not work well if the current thread culture has comma as decimal separator (like most of Europe). The format exception thrown from System.Xml.Linq.XAttribute explicit conversion to decimal is just one of the problems, the css will also get full of nonsense like "padding-right:5,4pt;".

Shouldn't the code in HtmlConverter be like this or similar?
string.Format(CultureInfo.InvariantCulture, "{0:0.00}", (decimal)delta2 / 1440m)
(The CSS or HTML specifications are not culture dependent)

A quick fix is to change the CurrentCulture for the thread:
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;