AutoFit with formatted cells

Dec 1, 2014 at 7:23 PM
I have a problem where AutoFit() won't work correctly on cells which have formatting applied.

In my case I apply following to Style
.Style.Numberformat.Format = "#,##0.00;\-\ #,##0.00;\ 0"

So using styling I make sure I have 2 decimals and I have a thousand-separator.

This means my numbers are wider then the original (e.g. 1000 becomes 1,000.00)

How can I overcome this issue?
Dec 1, 2014 at 7:54 PM
I don't know whether is your case, but if you are using formulas you need to call calculation engine method before.
Dec 2, 2014 at 7:21 AM
Nope that's not my case. There is no formula involved.

I found a possible work-around: in stead of adding the value as decimal, I do a .ToString("#,##0.00"), but then the cell gives a warning that there is a number stored as text (which makes sense of course)
Dec 22, 2014 at 7:21 PM
I use
and it works well.