下列代码导出excle时,时间time列,导出不能显示正确的 几点几分钟,显示为 1900-1-0 9:39:00
求助,怎样显示为9:39,谢谢
Dim dt As Table = Tables("工作日志")
Dim nms() As String = {"省份","城市","项目名称","其他名称","项目位置","户型","项目类别","日期","创建时间","创建者","工作内容","完成情况","未完成原因","加班时间","次日工作计划","图片","附件a"} '要导出的列名
Dim caps() As String = {"省份","城市","项目名称","其他名称","项目位置","户型","项目类别","日期","创建时间","创建者","工作内容","完成情况","未完成原因","加班时间","次日工作计划","图片","附件a"} '对应的列标题
Dim szs() As Integer = {50,70,90,100,90,90,90,90,90,80,190,190,190,190,190,40,40} '对应的列宽
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim st As XLS.Style = Book.NewStyle '日期列的显示格式
st.Format = "yyyy-MM-dd"
For c As Integer = 0 To nms.length -1
Sheet(0, c).Value = caps(c) '指定列标题
Sheet.Cols(c).Width = szs(c) '指定列宽
If dt.Cols(nms(c)).IsDate Then '如果是日期列
Sheet.Cols(c).Style = st '设置显示格式
End If
Next
'For r As Integer = 0 To dt.Rows.Count - 1 '填入数据 '导出的excle表的单元格 日期是1900-01-00,下面代码怎么修改呢?谢谢
'For c As Integer = 0 To nms.length -1
'Sheet(r +1, c).Value = dt.rows(r)(nms(c))
'Next
'Next
'[求助]导出数据
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
Dim dr As Row = dt.rows(r)
For c As Integer = 0 To nms.length -1
If dr.IsNull(nms(c)) = False
Sheet(r +1, c).Value = dr(nms(c))
End If
Next
Next
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Book.Save(dlg.FileName)
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If
[此贴子已经被作者于2018/11/16 11:30:43编辑过]