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
close icon

Numerical string keeps dropping zeros

I have a column of postal codes that I'm setting up as a string since many postal codes will contain leading zeros(i.e. "04438", "00110") however when my xls sheet opens, it eliminates the leading zeros (i.e. "4438", "110").

I'm trying to set this by first populating the spreadsheet with the data and then formatting the column:
-------------------------------------------
sheet.ImportArray(data,1,1);
sheet.Columns[0].HorizontalAlignment = ExcelHAlign.HAlignCenter;
sheet.Columns[0].ColumnWidth = 11;
sheet.Columns[0].NumberFormat = "@";
---------------------------------------------

I would think that by using "@" as the numberFormat, that would prevent the leading zeros from dropping however that doesn't seem to be the case.

Any idea on what I should do?

Thanks.

-Ryan

1 Reply

MW Melba Winshia Syncfusion Team January 12, 2007 01:12 PM UTC

Hi Ryan,

Could you please try using the following code snippets to set the postal codes with the leading zeros?

[C#]

//Number format to preserve the leading zeros
sheet.Range["A1:A2"].NumberFormat="00000";

//Import array of objects
sheet.ImportArray( arrInt, 1, 1, true );

Here is the sample for your reference:

ImportArrayBoder.zip

Please take a look at the sample above and let me know if you have any other questions.

Best Regards,
Melba

Loader.
Live Chat Icon For mobile
Up arrow icon