Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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# 如何导出日期? 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

您可能无法获取日期值,它返回null并给出错误。仅对于日期列,您尝试转换

 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";