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.
Unfortunately, activation email could not send to your email. Please try again.

Keep leading Zero''s in Excel Export,

Thread ID:

Created:

Updated:

Platform:

Replies:

102154 Jan 4,2012 09:17 AM Aug 25,2014 05:12 PM ASP.NET Web Forms (Classic) 4
loading
Tags: XlsIO
Tony Kelly
Asked On January 4, 2012 09:17 AM

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


Sridhar [Syncfusion]
Replied On January 5, 2012 02:35 AM

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



Tony Kelly
Replied On January 5, 2012 05:42 AM

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.




Sridhar [Syncfusion]
Replied On January 9, 2012 07:54 AM

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



solymars
Replied On August 25, 2014 05:12 PM

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.







CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;