I was wondering if anyone had come across the following problem and had any ideas on how to resolve it: I\'m exporting data from a C# application (.NET 3.5) to Excel (2003)
The correct type is not General, because general will try to guess the correct type, which in this case is a numeric, but you have to specify it as text to not truncate the leading zeros.
Try the following code:
Range cell = ActiveWorksheet.Cells[1,1];
//The @ is the indicator for Excel, that the content should be text
const string textIndicator = "@";
//Change the NumberFormat from 'General' to 'Text'
cell.NumberFormat = textIndicator;
//Set the Value
cell.Value2 = "000123";