NPOI Format Number As Text

2.4k Views Asked by At

I'm trying to generate a excel file using VB in visual studio 2010, using the NPOI library. I ran into the issue where the data inserted are format incorrectly.

For example, I have a user id "0001", and I'm trying to inserted into excel. In the output excel file, the cell says "1" which is incorrect. I looked at the format and it already says "Text" and not "General".

How can I go about inserting "0001" correctly instead of "1"?

I tried this and it's no making any changes

myStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("text")

I tried "@" as well and also doesn't make any changes.

Any help is appreciated.

1

There are 1 best solutions below

1
On

Make sure you set the CellType to String if you don't already.

cellType = NPOI.SS.UserModel.CellType.String;
var cell=currentRow.CreateCell(i, cellType);

Or in C# try:

cell.SetCellType(NPOI.SS.UserModel.CellType.String);