I have a string variable 'v_DateForLabelGeneration' wherein I store date. In datatable I have a column 'LblDate'. I am able to assign this variable to that 'LblDate' correctly. I then use this datatable for exporting to excel file alongwith other columns. In excel file I dont see the actual date but some junk like '########'. Hereunder is my code:
v_todaydate = (DateTime.Today);
string v_DateForLabelGeneration = v_todaydate.AddDays(1).Date.ToString("yyyy/MM/dd");
dtMainSQLData1.Rows[ii - 1]["LblDate"] = v_DateForLabelGeneration;
//export to excel
DataColumnCollection dcCollection1 = dtMainSQLData1.Columns;
Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp1 = new Microsoft.Office.Interop.Excel.ApplicationClass();
ExcelApp1.Application.Workbooks.Add(Type.Missing);
for (int iii = 1; iii < dtMainSQLData1.Rows.Count + 1; iii++)
{
for (int j = 1; j < dtMainSQLData1.Columns.Count + 1; j++)
{
if (iii == 1)
ExcelApp1.Cells[iii, j] = dcCollection1[j - 1].ToString();
ExcelApp1.Cells[iii + 1, j] = dtMainSQLData1.Rows[iii - 1][j - 1].ToString();
}
}
//ExcelApp.ActiveWorkbook.SaveCopyAs("C:\\Users\\RAJENDRAN\\Desktop\\guestaddress.xls");
string filename1 = "guestaddress" + DateTime.Now.ToString("ddMMyyyy") + ".xls";
ExcelApp1.ActiveWorkbook.SaveCopyAs("C:\\Users\\RAJENDRAN\\Desktop\\" + filename1);
ExcelApp1.ActiveWorkbook.Saved = true;