Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All Experts ,
I Have An Column In Excel Sheet That Handle Leading Zero In It By Define Custom Format
But In Function Bar It Removes Leading Zero And Also
When I Select That Sheet From C# Code It Removes Leading Zero Too...
Is There Any Way To Handle This Challenge .......
Thank You All ...
Posted
Updated 10-Mar-20 22:25pm
Comments
Prasad Avunoori 2-Jun-14 0:33am    
Try like this. Put a single quote before number.
'01
daghune 2-Jun-14 0:51am    
Thank You Prasad It Works .....

Try like this. Put a single quote before number.
'01
 
Share this answer
 
If you want to store number with leading zeros, you need to treat it as a text.

Please, read about cell formats: Range.NumberFormat Property (Excel)[^]
 
Share this answer
 
Use PadLeft or PadRight. Below query worked for me.

Plz = Sheet.GetCellValue(rowIndex, colIndex++)?.ToString().PadLeft(5, '0');
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900