使用EP Plus在工作表上允许前导零
您好我正在使用Ep Plus与Web应用程序。 我正在创build一个Excel文件,用户可以填写并上传回应用程序。 当我input一个前导零的数字时,它们被截断。
是否允许用户input前导零点?
玩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"
您可以使用打开Excel并使用数字格式对话框播放不同的格式。
我需要的格式是“@”,因此代码行是
codeSheet.Cells["A:D"].Style.Numberformat.Format = "@";
确保使用插入或单元格格式作为text
不是数字,而应该允许使用前导零
string text = "'0001"
这个问题接受的答案不适合我。 我发现这篇文章从微软解决了我的问题。 https://support.microsoft.com/en-gb/help/81518/using-a-custom-number-format-to-display-leading-zeros
我正在处理邮政编码,所以我能够做到这一点:
workSheet.Column(4).Style.Numberformat.Format = "00000";
这是可行的,因为我的邮编总是5位数。
Excel.Range formatRange; formatRange.NumberFormat = "@";