How to convert a standard .NET format string to an Excel format string

I have an application that allows a user to create custom representations of numeric data and specify the format strings used to display the data. Typically, users use standard .NET format strings such as N2, P1.

Now I have a requirement to generate Excel export and you want to format the exported data according to user preferences.

Is there anything "built-in" to convert a standard .NET format string to a custom format string that can be used in Excel. For instance. "N2" => "#, ## 0.00"; "P1" => "#, ## 0.0%", or do I need to roll my own?

+5
source share
1 answer

I went through something similar, and I'm sorry to say that basically you have to do it yourself.

Just friendly advice, let me tell you that there is a trick if you plan to export to a text file or similar (TXT / CSV / HTML) before importing to excel.

Excel will read numbers correctly if it can "understand" the formatting (otherwise, Excel will import as text or read the number incorrectly).

For example, let's say .net uses "," as a decimal point and uses excel. "When exporting, you are probably reading the data incorrectly.

, , excel. .net, ( ).

-1

All Articles