This project has moved. For the latest updates, please go here.

How to make a string value (which is stored as character value in SQL) remain as string when populating cells.

Apr 30, 2014 at 7:46 PM
I have a SQL table that has numeric values stored as chars (i.e. '0243', '0170'). When I insert the data into a workbook, it truncates the leading zero thinking it is an insignificant digit even though I declare the cell to have a datatype of text as shown below. I need the leading zero from the data:

indcell = "D" + i.ToString();
worksheet.Cell(indcell).DataType = XLCellValues.Text;
worksheet.Cell(indcell).Value = mySQLReader["CostCenter5"].ToString().ToUpper().Trim();

I have verified that the zero is still present when obtaining the data from the reader as a string as I have a log running that displays the data. All is good in the log. Can you help?
Coordinator
Apr 30, 2014 at 8:16 PM
cell.SetValue(string)