We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Keep leading Zero''s in Excel Export,

I have a ASP.NET application which builds/creates various excell reports by dumping the datasets to excel however for specific columns I need the column to represent the data without stripping any leading zero's . Currently these are being stripped off when I view the excel export. Is there any simply way to keep the zero's ... we are trying to keep this dynamic as possible so any dataset structure can be exported out. I don;t want to start formatting individiual cells as some of the reports are really big with over 200000 rows


4 Replies

SR Sridhar Syncfusion Team January 5, 2012 07:35 AM UTC

Hi Tony,

Thank you for using Syncfusion products.

Please use the following number format to apply the number with leading zero’s for a particular range with XlsIO. Please add the number of zeros with the number format to add the number of zeros to the cell.

Code Snippet [C#]:

sheet.Range["C5"].NumberFormat = "0#,##0";will result as 0370
sheet.Range["C5"].NumberFormat = "00#,##0"; will result as 00370

As per your above reported requirement instead of applying the number format every time to the cell range or the group of ranges, create a style with the number format and you can set the style to the cell range and cell Ranges. Please go through the following code snippet for the same.

IStyle style = workbook.Styles.Add("Style");
style.BeginUpdate();
style.NumberFormat ="0#,##0";
style.EndUpdate();

//Aplying styles

sheet.Range["C5"].CellStyleName = "Style";
sheet.Range["A1:C5"].CellStyleName = "Style";


Please try the above code snippet at your side and let us know if this helps you. Please revert back to us if you have any concerns.

Please let us know if you require any further assistance on this.

Thanks,
Sridhar.S




TK Tony Kelly January 5, 2012 10:42 AM UTC

Many Thanks guys for u're suggestions. The issue I have is that depending on the client the number of prefixed leading Zero's can be different as can be the position of these colums in the Dataset/datable to be printed and therefore I have to change the apx code to reflect this, the dataset/datatable has the data formatted correctly so I just wish to print this out exactly as it comes. If I was using excel I could just set the column format for all cells to text and paste the values in and they would all show correctly ,essentially I want to do this programmically with as little effort as possible otherwise I have to code for formatting into the aspx page which is what I want to avoid.





SR Sridhar Syncfusion Team January 9, 2012 12:54 PM UTC

Hi Tony,

Thank you for the update.

Currently, we do not have support to preserve the leading zero with the numbers while importing the data table in XlsIO. So we request you to open a new direct-trac incident with a simple issue reproducing sample for further follow up on this forum.

Direct-Trac Link:
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Workaround:

Please set the number format to display the values with leading zero as given in our previous post.

Please let me know if you require any further clarifications.

Thanks,
Sridhar.S




SO solymars August 25, 2014 09:12 PM UTC

I have a need to preserve leading zeroes also, isn't there a TEXT cell Format in XLSIO that will allow me to do:

sheet.Range["C5"].Text


Thanks in advance.







Loader.
Live Chat Icon For mobile
Up arrow icon