ranga nathan
ranga nathan

Reputation: 163

Export to Excel using C#

I'm exporting the values in the grid to excel through C# code. When i open the exported excel, the string column is displayed as integer and the leading '0' in that field gets deleted. how to handle this.

Upvotes: 0

Views: 445

Answers (4)

Basic
Basic

Reputation: 26766

A quick way to get around this is to prefix your cell value with an apostrophe.

Excel hides the apostrophe automatically and forces the text mode for the cell to Text

Try it directly in Excel and you'll see what I mean eg type '07799123477 into a cell with General text formatting (the default)

Upvotes: 0

Hupperware
Hupperware

Reputation: 979

Style the TDs with mso-number-format:\@

Upvotes: 0

Casperah
Casperah

Reputation: 4564

I have no experience in making Excel files but when entering text in Excel you can write '00123. The ' makes the whole difference.

Upvotes: 0

jrummell
jrummell

Reputation: 43097

This isn't a programming issue; it's Excel's default way of displaying what it thinks are numbers.

It assumes that 00001 is a number and should be displayed as 1. Change your cells to display "Text" instead of numbers in Excel.

Upvotes: 1

Related Questions