C# 如何导出日期? Microsoft.Office.Interop.Excel.Application Excel=new Microsoft.Office.Interop.Excel.Application(); 工作簿wb=Excel.Workbooks.Add(XlSheetType.xlWorksheet); 工作表ws=(工作表)Excel.ActiveSheet; Excel.Visible=true; ws.Cells[1,1]=“Tarih”; ws.Cells[1,2]=“Kasiyer”; ws.Cells[1,3]=“Ucret”; ws.Cells[1,4]=“Bilet No”; ws.Cells[1,5]=“Firma Adı”; 对于(int j=2;j
您可能无法获取日期值,它返回null并给出错误。仅对于日期列,您尝试转换C# 如何导出日期? Microsoft.Office.Interop.Excel.Application Excel=new Microsoft.Office.Interop.Excel.Application(); 工作簿wb=Excel.Workbooks.Add(XlSheetType.xlWorksheet); 工作表ws=(工作表)Excel.ActiveSheet; Excel.Visible=true; ws.Cells[1,1]=“Tarih”; ws.Cells[1,2]=“Kasiyer”; ws.Cells[1,3]=“Ucret”; ws.Cells[1,4]=“Bilet No”; ws.Cells[1,5]=“Firma Adı”; 对于(int j=2;j,c#,excel,winforms,datagrid,C#,Excel,Winforms,Datagrid,您可能无法获取日期值,它返回null并给出错误。仅对于日期列,您尝试转换 Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application(); Workbook wb = Excel.Workbooks.Add(XlSheetType.xlWorksheet); Worksheet ws = (Worksheet)Excel.Act
Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = Excel.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)Excel.ActiveSheet;
Excel.Visible = true;
ws.Cells[1, 1] = "Tarih";
ws.Cells[1, 2] = "Kasiyer";
ws.Cells[1, 3] = "Ucret";
ws.Cells[1, 4] = "Bilet No";
ws.Cells[1, 5] = "Firma Adı";
for (int j = 2; j < dataGridView1.Rows.Count; j++)
{
for (int i = 2; i <= 5; i++)
{
ws.Cells[j,i]=dataGridView1.Rows[j-2].Cells[i-1].Value;
}
}
你调试过吗?dataGridView1.行[j-2]。单元格[i-1]的值是什么?值是日期、出纳、费用、票号和公司名称。日期不导出到Excel程序告诉我“HRESULTözel durum döndürdü:0x800A03EC”看。@SercanDeveci
for (int i = 1; i < dataGridView1.Rows.Count; i++)
{
ws.Cells[i,0] = (Convert.ToDateTime(ws.Cells[i,0]).ToOADate();
}
Microsoft.Office.Interop.Excel.Range range = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1];
range = range.get_Resize(rowCount, columnCount);
range.EntireColumn.NumberFormat = "DD/MM/YYYY";