I have a program that takes data out of an excel sheet and puts it in a text doc. My problem is that some cells are dates but not all. Atm the output format is dd/MM/yyyy 00:00:00 in my textdoc. Is there a way to check if its a date and if yes chop off the time part?
I tried something with TryParse as you can see but I honestly don't know if it even makes sense
DateTime dDate;
var allRowTexts = new List<string>();
for (int row = 5; worksheet.Cells[row, 5].Value != null; row++)
{
// loop all configured Columns
var rowText = new StringBuilder();
foreach (var col in configuredColumns)
{
var cell = worksheet.Cells[row, col];
if (cell.Value == null)
{
rowText.Append("leer" + "\t\t\t\t");
}
else
{
if (DateTime.TryParse(cell.Value.ToString(), out dDate))
{
String.Format("{0:dd/MM/yyyy}", dDate);
rowText.Append(dDate+"\t\t");
}
else
{
rowText.Append(cell.Value.ToString()+"\t");
}
}
}
}
allRowTexts.Add(rowText.ToString()+"\n");