Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi Expert,
 
I have a datagridview. When i Export it o Excel leading zero got truncated.
I have tried to add one single comma(') during writing to Excel but it show
the added comma(').
 
Below is my sample data: -
 
5001 13000001 '0003
5001 13000001 '0014
5002 13000002 '0014
5002 13000002 '0014
 
I want to produce the result in excel as below without comma('): -
 
5001 13000001 0003
5001 13000001 0014
5002 13000002 0014
5002 13000002 0014
 
Thanks,
 
Anil Kumar
Posted 28-Jan-13 23:47pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When you export this to excel, you need to set the format of the excel cells, if you have few data, you can try a free dataexport library Spire.FreeDataExport, this library enables you to set the format of excel cells after export datagridview data to Excel without any excel api. you can see below code:
   cellExport3.DataFormats.Currency = "¥#,###,##0.00";
   cellExport3.DataFormats.DateTime = "yyyy-M-d H:mm";
   cellExport3.DataFormats.Float = "#,###,##0.00";
   cellExport3.DataFormats.Integer = "#,###,##0";
   cellExport3.DataFormats.Time = "H:mm";
But if you have large data, you may have to use the commercial edition of this library:http://exportdata.codeplex.com/[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 751
1 George Jonsson 330
2 Garth J Lancaster 290
3 Sergey Alexandrovich Kryukov 274
4 BillWoodruff 252
0 Sergey Alexandrovich Kryukov 10,879
1 OriginalGriff 5,555
2 Maciej Los 5,534
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web01 | 2.8.141030.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100