Export to PDF in specific culture


Is it possible to export to PDF in a specific culture, apart form setting the own threads culture and resetting it after export?



Not in FlexCel.NET. We have a FlexCelFormatSettings in FlexCel for delphi, but that is because in Delphi it is really difficult to change the threads culture. In .NET, changing the thread culture is easy, so we felt it doesn't justify to add a lot of repeated functionality and code to do the same as changing the culture thread with a different but similar class. It opens the door to new bugs, it is more code to maintain, more code for you to learn how to use, and I don't think it adds much.

Is there any reason why you don't want to change the thread culture?


Thank you for your response.

No, there is not a strong reason, why I don't want to change the culture. It's just a matter of taste. You could also change the current threads culture, call .ToString(), and change the culture back. Or you could just use .ToStrong(culture).

Apart from that: I was hoping to solve following problem: When I concatenate Cells containing (double) numbers and cells containing text in the Excel report template, this results in a string which was generated with the current culture.

E.g. Cell A1: Text , cell A2: 2.5, cell A3: =A1&A2. This results in "Text 2,5" for the cell A3 in the final report with the region settings de-DE.

But I'd like to generate the report with InvariantCulture and the workaround with setting the current thread culture to InvariantCulture does not work in this specific situation.

My workaround is now not to concatenate the cells A1 and A2 in cell A3 but to set A3 to A1 and set A4 to A2 and size them that it finally looks like they are concatenated (in the PDF report). May you know a better solution?



The things with ToString() is that it is a simple method, so it makes sense so offer it both ways. We have something similar with the ActiveSheet: Instead of making every call to have a parameter "sheet", we have a state variable ActiveSheet, which sets the sheet we are working on, and the sheet parameter is implicit. But we do have a xls.SetCellValue(sheet, row, col) in case you want to change a cell value without changing the sheet.

When designing the API, it is a hard desicion what should be stateful and what should be stateless: We prefer stateless whenever possible (so you pass the parameters explicitly and there is less room for error). But when a parameter like the culture information is needed in every api call, it makes no sense to make it stateless: You will just be passing the cultureinfo all the time, and gaining nothing as most cases require just to work with a single culture.

Now, being decided that culture should be a state variable and not a parameter to every call, we could duplicate the functionality of .NET cultureinfo by having our own classes that are similar, but only apply to FlexCel objects. As said, we had to do exactly that in Delphi because changing the thread locale is complex. But in .NET, I think duplicating the functionality brings more problems than it solves. There is already a well-known method to change the locale for all the objects, introducing an specific method to change the locale just for FlexCel will lead to problems: When someone changes the thread locale he will expect FlexCel to change, not to remain the same because FlexCel is not using the therad locale but a different locale set somewhere else that the user might not even be aware of. You can then make a system that changes the FlexCel thread locale when the user changes the locale, but I think you can see that complexity begins to skyrocket: What if I didn't want the FlexCel locale to change when I change the thread locale?

About your specific problem, if I understood right the solution is simple:

The "magic" here is in the recalc line: The you save the Excel file, it will be recalculated with the "de" settings. So A3 will have the formula result "Text 2,5". When FlexCelPdfExport picks up the file, it will see that it is already calculated and not try to recalculate it again. It will see that the formula result in A3 is the string "Text 2,5" and use that. 
But if you force a recalculation of the file using Invariant locale, then the value stored in the xls file as formula result will be "Text 2.5" and FlexCelPdfExport will use that. You need to recalc with the settings you want in order to export correctly.

Note that this issue wouldn't be fixed either by having a local setting for the FlexCel objects. This is more of an issue with recalculation, and you will need to recalculate the formulas so they are calculated in the correct locale.

Hello Adrian Gallero

Thank you for your explanation.

Your suggested solution works perfect for me.