Wednesday, June 15, 2011

Export to excel with preserve starting(Leading) zeros values in ASP Dot Net.

Export to excel with preserve starting(Leading) zeros values in ASP Dot Net.

In my office colleague was facing an interesting problem.
Sql sever data was listed below:
-------------------------------------------
ID EmpID EmpName Salary
1 000001 aa 1111111
2 000002 bb 2222222
3 000003 cc 3333333
4 000004 dd 4444444
5 000005 ee 5555555
-----------------------------------------
Column EmpID was varchar type, he was just trying export these data to MS-Excel,
so first show the data by GridView and then export it as a excel file.
But while opening excel file "000001" was showing as "1" and "000002" was showing as "2" and so on. the situation was "00000" were removed as below.
-------------------------------------------
ID EmpID EmpName Salary
1 1 aa 1111111
2 2 bb 2222222
3 3 cc 3333333
4 4 dd 4444444
5 5 ee 5555555
6 6 ff 6666666
----------------------------------------
He just requested me to help and I helped him.I've searched these problem in Microsoft site(MSDN) and found the solution
and implemented it. now he is getting right data in excel.


Download code here

No comments:

Post a Comment