How to programmatically format Excel Numbers in C#

Asked

Viewed 361 times

3

I’m putting together a C#Orders report, I’m using the library Microsoft.Interop.Excel and I face a problem:

It is necessary to include in this report the Request number and when presented in Excel, it comes in Exponential Format: 7,80005E+12, and the original would be: 78000496698755.

I read on the Web that putting an Apostrophe before the text it would come correct, the problem is that this number is necessary for other conversions in and out of the program file and this apostrophe is barring some of these conversions.

My question is: Is there any type of formatting that I can put for the content to come correctly, I tried the code below, but without success:

NumberFormat = "@";
  • 1

    take a look: http://stackoverflow.com/questions/3879463/parse-number-from-exponential-notation

  • Almost that Thiago, the number is there, but Excel, by default converts it to Exponential (God knows why), I tried to use it here but it’s still the same

1 answer

4


I didn’t understand the question completely but try:

NumberFormat = "0";

Using this code is formatted cell as numbers, in my example I was formatting as general text (where I fall into the problem of Exponentiation).

  • Lucas, following the analogy, if I needed to omit a few decimal places, would use Numberformat = "0.0"?

  • 1

    @Guilhermegolfetto, in this case use: Numberformat = "0,0" To check other formats, I suggest you take a look directly at excel. Pressing Ctrl+1 will open the cell formatting menu. Choose the "custom" or "custom" option depending on the language. There you will see several number formats and the code that represents them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.