Click here to Skip to main content
Rate this: bad
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
Anil Kumar
Posted 29-Jan-13 0:47am

1 solution

Rate this: bad
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:[^]

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

Advertise | Privacy | Mobile
Web02 | 2.8.150327.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2015
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