Question

I set a value in string type to Excell cell, but in result it shows like numeric format.

workSheet.Cells[i + 1, 7] = list[i].Code;

Code is a string type, but in result it shown like double. For example, Code is "409318000597" in string type, but in excell value is 4,09318E+11. When I double clicked to cell, it expands and shown like 409318000597 and get back on mouse over.

I also tried this, but nothing changed.

workSheet.Cells[i + 1, 7] = String.Format("{0}", list[i].Code);

It is interesting that, there is Name property in string type also, it shown like normal.

Is there any way to manage excel types?

Was it helpful?

Solution

Try changing NumberFormat to text:

workSheet.Cells[i + 1, 7].NumberFormat = "@";
workSheet.Cells[i + 1, 7] = list[i].Code;

Actually I suggest you to do it for entire range:

workSheet.Range["G1","G100"].NumberFormat = "@";

and then in loop:

workSheet.Cells[i + 1, 7] = list[i].Code;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top