Formating Excel cells?

S

Stefan

How would I programatically format cells in Excel.

I want to display a value as such "0001234", and Excel autoformats the
cells and strips out the leading zeros.

If I format the cells as Text format, then the zeros are preserved.

I tried doing something like this:
worksheet.Columns.AutoFormat(Microsoft.Office.Interop.Excel.XlRangeAutoFormat.xlRangeAutoFormatNone,
false,true,true,true,true,true);

but that did not make a difference (and makes the file size much much
bigger)...

Thanks,
Stefan
 
E

Eric White

You may have to preface any perceived numeric values with a single quote (" '
") in order to force Excel to see the value as a string and not numeric.

Excel tries to store data in the most efficient manner, so it doesn't see
why you would use a whopping multi-byte string when you could use a nice,
small, efficient integer. To its credit, and like many programming
languages, it will convert a sting value in a cell to a numeric value
(assuming it can be) in order to perform mathematical operations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top