-1

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?

Jeyhun Rahimov
  • 3,769
  • 6
  • 47
  • 90
  • possible duplicate of [C# Excel Interop: How to format cells to store values as text](http://stackoverflow.com/questions/7583704/c-sharp-excel-interop-how-to-format-cells-to-store-values-as-text) and also http://stackoverflow.com/questions/2067926/format-an-excel-column-or-cell-as-text-in-c –  Apr 22 '14 at 15:53

1 Answers1

2

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;
Dmitry Pavliv
  • 35,333
  • 13
  • 79
  • 80