I am having trouble getting EP Plus to format as text so I can keep the leading zeros of a number.
This Post has a code snippet I tried but could not get to work. Here is the snippet:
workSheet.Cells[row, col].Style.Numberformat.Format = "@";
The only way I could get it work is with the code below, but I do not want a set number of place holders.
workSheet.Cells[row, col].Style.Numberformat.Format = "0000000";
Here is my full code, I've tried it in reverse order with the same result.
workSheet.Cells[row, col].Style.Numberformat.Format = "@";
workSheet.Cells[row, col].LoadFromText("000001");
Any idea what I am doing wrong?
LoadFromText
is mostly used to import CSV into range(not a single cell).
The only way to actually keep stored a number with leading 0
s while keep it at an arbitrary length is to store it as TEXT
.
For TEXT
value, simply set the Value
and don't touch the NumberFormat
:
sheet.Cells[1, 1].Value = "000001";