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

Commented Unassigned: Date value as text in excel file [9444]

$
0
0
I am trying to set a text value to one of my columns.
Text value is 2015/06/03 15:15

Below is the code, that I use to set this column

excelWorkSheet.Cell(j + 1, k).SetDataType(XLCellValues.Text);
excelWorkSheet.Cell(j + 1, k)
.Style.NumberFormat.SetNumberFormatId(0);
excelWorkSheet.Cell(j + 1, k).Value = cellValue;

This is converting my string as a number.

How could I show this value as a text(Not as date time or a number)
Comments: If you prefix cellValue with apostrophe the Excel will treat cell content as a text. ``` cellValue = "'2015/06/03 15:15"; // notice apostrophe before 2015 ws.Cell(1, 1).Value = cellValue; OR string timeString = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); string stringForExcel = "'" + timeString; ws.Cell(1, 2).Value = stringForExcel; ``` Not sure if it is the "correct" way, but works for me. Cheers Olaf

Viewing all articles
Browse latest Browse all 1877

Trending Articles



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