此主题相关图片如下:1.png

老师,您看这个导出时间不对,
导出代码:
Dim nums1() As String={"cardID","name","sex","age","birth","tel","jiguan","rational", _
"edu","health","workdate","politicalStatus", _
"hobbies","retiredPost","title","address","leaOrRetire", _
"retireTime","proTecPost","proSpecialty","partyBranch","partyTime", _
"presonalClass","organName","partyStanding","retiredDep", _
"guanZhu"}
Dim nums2() As String={"身份证号", "姓名","性别","年龄","出生年月","联系方式","籍贯","民族", _
"学历","健康状况","参加工作日期","政治面貌", _
"兴趣爱好","离退休职务","享受待遇","地址","状态", _
"离退休时间","专业技术职务","专业特长","所在党支部","入党时间", _
"个人成分","单位","党龄","部门", _
"纪委关注"}
Dim List As WinForm.ListBox = e.Form.Controls("ListBox2")
'MessageBox.Show(List.Items.Count)
Dim nms As New List(of String)
For i As Integer = 0 To List.Items.count - 1 '获取已经勾选的列
Dim index As Integer=Array.Indexof(nums2,List.Items(i))
nms.Add(nums1(index))
Next
If nms.Count = 0 Then
MessageBox.Show("至少要选择一列","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
End If
'生成Excel表
Dim dt As Table = Tables("person")
Dim Book As New XLS.Book
Dim Style As XLS.Style = Book.NewStyle() '定义新样式
Style.AlignHorz = XLS.AlignHorzEnum.Center
Style.AlignVert = XLS.AlignVertEnum.Center
Dim Sheet As XLS.Sheet = Book.Sheets(0)
For i As Integer = 0 To nms.count -1
Sheet(0, i).Value = nums2(Array.Indexof(nums1,nms(i)))''获得该值在nums1中的位置,然后在nums2的同等位置找
Sheet(0, i).Style = Style
Next
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
For i As Integer = 0 To nms.count -1
Sheet(r + 1, i).Value = dt.rows(r)(nms(i))
Sheet(r + 1, i).Style = Style
Next
Next
'保存并打开excel文件
'Book.Save("c:\reports\test.xls")
'Dim Proc As New Process
'Proc.File = "c:\reports\test.xls"
'Proc.Start()
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Book.Save(dlg.FileName)
'Tables("person").SaveExcel(dlg.FileName,"person") '保存文件
End If
红色部分是把数据库表的值传给EXCEL表,但是,时间类型的值传出来的都不对?
[此贴子已经被作者于2018/8/20 9:31:03编辑过]