【求助】从DataGrid导出数据到excel问题,请大虾帮帮忙啊
【求助】从DataGrid导出数据到excel问题,请大虾帮帮忙啊本人做了一个从DataGrid导出数据到excel的程序,导出到excel后,在excel中的日期跟在DataGrid中的数据不一样了
如在DataGrid中是2014-1-6,可是在excel中却是41645,而不是2014-1-6
请大虾帮忙看看,要怎么解决啊!
程序代码:
If rs.RecordCount <= 0 Then MsgBox "没有可输出的数据,请选择数据" Exit Sub Else Set xlapp = CreateObject("excel.application") Set xlBook = xlapp.Workbooks.Add Set xlSHEET = xlBook.Worksheets(1) xlapp.Visible = True '设置EXCEL对象不可见 'xlapp.DisplayAlerts = False On Error Resume Next If Err.Number <> 0 Then Set xlapp = CreateObject("Excel.Application") Set xlBook = xlapp.Workbooks.Add Set xlSHEET = xlBook.ActiveSheet For k = 1 To DataGrid1.Columns.Count xlSHEET.Cells(1, k) = DataGrid1.Columns(k - 1).Caption Next k For i = 1 To rs.RecordCount + 1 For j = 0 To DataGrid1.Columns.Count xlSHEET.Cells(i + 1, j + 1) = rst(j) Next j rst.MoveNext Next i CommonDialog2.DialogTitle = "导出数据" CommonDialog2.Filter = "Excel文件|*.xls" CommonDialog2.ShowOpen 'xlapp.Save xlapp.Close xlapp.ActiveWindow.Close xlapp.Workbooks.Close Set xlapp = Nothing End If