Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:


C#
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;
Posted

1 solution

When you see '########' in Excel, it is normally because the column is too narrow to show the value, and there is a column with data to the right, so it can't just "flow" it out of the cell into the next column. Try using the resize handled on teh column header to make it bigger and you may well see your date!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900