Allow leading zeros on sheet with EP Plus

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?

+4
source share
5 answers

The format I needed was "@", so the line of code was

codeSheet.Cells["A:D"].Style.Numberformat.Format = "@";
+2
source

When playing with style 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 various formats that open in Excel and play with the format dialog.

Format cells

+2
source

. 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.

+1
source

Make sure you use insert or cell formatting as textnot a number, which should allow you to use a leading zero

string text  = "'0001"
0
source
 Excel.Range formatRange;
    formatRange.NumberFormat = "@";
-one
source

All Articles