Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

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

$
0
0
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?

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>