I am working on a C# Console application which export data from a DataTable to an excel file. My DataTable has few columns of type Text and I also have a column which just has a month of type Text in the form of "May-15" but in the excel file it is automatically converting this to a date. How do I just export plain text to my excel.
I am using the Excel Interop assembly in C# as follows
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook workbook = excelApp.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel._Worksheet WhiteBoardData = null;
WhiteBoardData = workbook.Sheets[1];
// changing the name of active sheet
WhiteBoardData.Name = "WhiteBoard-Data";
int z = 1;
foreach (DataColumn dc in dtWhiteBoardData.Columns)
{
WhiteBoardData.Cells[1, z] = dc.ColumnName.ToString();
z++;
}
for (int k = 0; k < dtWhiteBoardData.Rows.Count; k++)
{
for (int x = 0; x < dtWhiteBoardData.Columns.Count; x++)
{
WhiteBoardData.Cells[k + 2, x + 1] = dtWhiteBoardData.Rows[k][x].ToString();
}
}
How do I fix this?