以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]关于导出EXCEL的方法问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=32947)

--  作者:xietan417
--  发布时间:2013/5/10 21:07:00
--  [求助]关于导出EXCEL的方法问题

我用以下代码,将ACCESS改成EXCEL

Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter=
"Access文件|*.mdb" \'设置筛选器
If
dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim
ex As New Exporter
   
ex.SourceTableName = "订单" \'指定导出表
   
ex.filepath = dlg.FileName  \'指定目标文件
   
ex.Export() \'开始导出
End If

 

为什么导出来的EXCEL无法打开呢?是不是这个方法只能导出ACCESS啊?

[此贴子已经被作者于2013-5-10 21:19:31编辑过]

--  作者:xietan417
--  发布时间:2013/5/10 21:18:00
--  
狐爸请教!
--  作者:狐狸爸爸
--  发布时间:2013/5/10 21:22:00
--  
默认是Access格式,如果要导出为Excel,必须明确指定格式:
 
ex.Format = "Excel" \'导出格式为Excel
 
 
例如:
 
Dim ex as New Exporter
ex.SourceTableName = "订单" \'指定导出表
ex.FilePath = "c:\\Data\\订单.xls" \'指定目标文件
ex.Format = "Excel" \'导出格式为Excel
ex.Fields = "日期,客户,数量,单价" \'指定导出字段
ex.Filter = "[产品] = \'PD01\'" \'指定导出条件
ex.Export() \'开始导出

--  作者:xietan417
--  发布时间:2013/5/10 21:23:00
--  
你别动!我试一下我的项目先!
--  作者:xietan417
--  发布时间:2013/5/10 21:26:00
--  

这个FORMAT我也有试过啊!比如这个代码!

Dim sd As Date = e.Form.Controls("sd").value
Dim ed As Date = e.Form.Controls("ed").value
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
Dim ex As New Exporter
If sd = #01/01/0001#  OrElse ed = #01/01/0001#  Then
MessageBox.Show("请输入起始日期和结束日期","注意",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
End If
If dlg.ShowDialog = DialogResult.OK Then
ex.SourceTableName = "a" \'指定导出表
ex.Format = "dlg" \'指定目标文件
ex.Fields = "ID,卡号,姓名,时间,dn,MachNo" \'指定导出字段
ex.Filter = "[dn] like \'" & _Userdept & "\' And  [时间] >=  #" & sd & "# And [时间] <=  #" & ed & "#"
 \'指定导出条件
ex.Export() \'开始导出
End If

 

这个dlg我就不知道怎么去定义它了!乱搞!

[此贴子已经被作者于2013-5-10 21:26:33编辑过]

--  作者:狐狸爸爸
--  发布时间:2013/5/10 21:30:00
--  

Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim ex As New Exporter

    ex.Format = "Excel" \'导出格式为Excel
    ex.SourceTableName = "订单" \'指定导出表
    ex.filepath = dlg.FileName  \'指定目标文件
    ex.Export() \'开始导出
End If


--  作者:xietan417
--  发布时间:2013/5/10 21:35:00
--  

哦!我懂了!谢谢!狐爸指点!