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 a number with leading zeros, they are truncated.
Is there access so that the user can enter leading zeros?
The format I needed was "@", so the line of code was
codeSheet.Cells["A:D"].Style.Numberformat.Format = "@";
When playing with style ExcelRange, you can achieve what you want:
ExcelRange
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 various formats that open in Excel and play with the format dialog.
. Microsoft, . https://support.microsoft.com/en-gb/help/81518/using-a-custom-number-format-to-display-leading-zeros
, :
workSheet.Column(4).Style.Numberformat.Format = "00000";
This works since my zipcodes will always have 5 digits.
Make sure you use insert or cell formatting as textnot a number, which should allow you to use a leading zero
text
string text = "'0001"
Excel.Range formatRange; formatRange.NumberFormat = "@";