Donate

Export ASP.NET GridView To Excel And Preserve Leading Zeros

Hi,

There was a question raised on how to export data from ASP.NET Gridview to Microsoft Excel and preserve leading zeros of numeric values. A workaround that we have is to insert an   character before the cell value if that value starts with zero (0). So if the value starts with zero such as 0001, the result would be " 0001". Thus when exported to Excel, the leading zero is kept.
cell.Text = string.Format(" {0}", cell.Text);
A suggested solution is to insert a Tab character ( ) but this fails on some occasions. After doing some research, replacing the tab character with   or   would also fix the issue.
cell.Text = string.Format(" {0}", cell.Text);
//or
cell.Text = string.Format(" {0}", cell.Text);

ASP.NET GridView Export
Export ASP.NET GridView To Excel And Preserve Leading Zeros
Excel Report
Export ASP.NET GridView To Excel And Preserve Leading Zeros
Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.