Hi I am using Ep Plus with a web application. I am creating an Excel file that the user can fill out and upload back to the application. When I enter in a number with leading zeros, they are truncated.
Is there away to allow leading Zeroes to be entered by the user?
The accepted answer for this question did not work for me. I found this article from Microsoft which solved my problem. https://support.microsoft.com/en-gb/help/81518/using-a-custom-number-format-to-display-leading-zeros
I was dealing with zip codes so I was able to do this:
workSheet.Column(4).Style.Numberformat.Format = "00000";
This works since my zipcodes will always be 5 digits.
Playing around with the style of the ExcelRange
you can achieve what you want:
var range = // get the range you want
// Force the numbers to have 2 digits to the left and 1 digit to the right
// of the decimal place.
range.Style.NumberFormat.Format = "00.0"
You can play with the different formats available by opening Excel and playing with the number format dialog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With