Search code examples
c#type-conversioncurrencyculturelinq-to-excel

LinqToExcel and currency format (Culture)


I use LinqToExcel in my application for a while now and has been working like a charm.

But I'm facing a problem reading currency strings from Excel.

I can't post images yet, but the value in excel is 9999 formated like 9.999,00 (pt-BR)

Local in my machine LinqToExcel reads this value just fine(9999) and I can convert it to decimal.

But on the IIS server that has a en-US culture it reads this same value as 9,999.00, so when I try to convert is to decimal I get an exception.

Is there a way to set the default culture for LinqToExcel or something like that? Because I don't want to replace the , and . it's just too ugly.

I'm using C# VS2013.


Solution

  • Actually the problem was that the excel's first line were all empty strings, so if the user left these fields empty LinqToExcel would assume string as the type for these columns, returning the masked input(9.999,00) instead of the interger value(9999).

    The workaround was to use a VBA macro in the excel file to replace the empty strings for 0(zero) when the file is beeing saved/closed.