我正在使用vb.net將我的日期時間值格式化爲從access to excel導出時的日期。Excel導出日期格式出錯,但僅限於某些日期值
我有下面的代碼
Dim formatRange As Excel.Range
formatRange = xlWorksheet.Range("C1", "C9999")
formatRange.NumberFormat = "dd/MM/yyyy"
formatRange = xlWorksheet.Range("D1", "D9999")
formatRange.NumberFormat = "dd/MM/yyyy"
這在我的數據庫適用於大多數日期,然而,一些人仍與00:00:00時間部分顯示,我認爲當日期高於20 ..
這是爲什麼,我該如何解決?
編輯
我完整的代碼:
Dim sPath As String = sDt.Rows(0).Item("excelPath")
Dim i, j As Integer
Dim xlapp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Dim misvalue As Object = Reflection.Missing.Value
xlapp = New Excel.Application
xlWorkbook = xlapp.Workbooks.Add(misvalue)
xlWorksheet = xlWorkbook.Sheets.Add
xlWorksheet.Name = "CommissionInformation"
Dim formatRange As Excel.Range
formatRange = xlWorksheet.Range("C1", "C9999")
formatRange.NumberFormat = "dd/MM/yyyy"
formatRange = xlWorksheet.Range("D1", "D9999")
formatRange.NumberFormat = "dd/MM/yyyy"
For k As Integer = 1 To dgvExport.Columns.Count
xlWorksheet.Cells(1, k) = dgvExport.Columns(k - 1).HeaderText
Next
For i = 0 To dgvExport.RowCount - 1
For j = 0 To dgvExport.ColumnCount - 1
xlWorksheet.Cells(i + 2, j + 1) = dgvExport(j, i).Value.ToString
Next
Next
xlWorksheet.Columns.AutoFit()
日期應該幾乎總是格式化爲年/月/日,所以yyyy/MM/dd – Fionnuala
@Fionnuala即使英國的日期? – Harambe
聽起來好像你不會導出日期值_as is_,而是表示值的字符串。 – Gustav