以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]导出到表,时间格式不对,怎么设置导出的时间格式  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=67759)

--  作者:vvfree
--  发布时间:2015/4/30 23:38:00
--  [求助]导出到表,时间格式不对,怎么设置导出的时间格式

导出到表,时间格式不对,怎么设置导出的时间格式

 

Dim dt As Table = Tables("窗口1_表格_Table出入库主表")
Dim nms() As String = {"第一列","第二列","时间"} \'要导出的列名
Dim caps() As String = {"标题一","标题二","时间"} \'对应的标题

For c As Integer = 0 To nms.length -1 \'添加列标题
Sheet(0, c).Value = caps(i)
Next

For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
For c As Integer = 0 To nms.length -1
Sheet(r +1, c).Value = dt.rows(r)(nms(c))
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


--  作者:sloyy
--  发布时间:2015/5/1 17:25:00
--  

Dim dt As Table = Tables("窗口1_表格_Table出入库主表")
Dim nms() As String = {"第一列","第二列","时间"} \'要导出的列名
Dim caps() As String = {"标题一","标题二","时间"} \'对应的标题

For c As Integer = 0 To nms.length -1 \'添加列标题
Sheet(0, c).Value = caps(i)
Next

For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
For c As Integer = 0 To nms.length -1
Sheet(r +1, c).Value = dt.rows(r)(nms(c))
Next
Next
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Book.Save(dlg.FileName)

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("dlg.FileName")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.Columns("C")  \'引用C列
Rg.NumberFormat = "h:mm:ss"  \'时间
App.Visible = False
App.Quit
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If

--  作者:vvfree
--  发布时间:2015/5/1 18:17:00
--  回复:(sloyy)Dim dt As Table = Tables("窗口1_表格...
导出出错 无法找到 dlg.FileName
--  作者:vvfree
--  发布时间:2015/5/1 18:40:00
--  回复:(sloyy)Dim dt As Table = Tables("窗口1_表格...

可以了 谢谢

 

我定义一个

Style3.Format = "yyyy-MM-dd"
Sheet.Cols(dt.Cols(3).Index).Style = Style3

就好了


--  作者:sloyy
--  发布时间:2015/5/2 4:17:00
--  
不好意思  这句错了,应该是,没有双引号的
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)