示例四
将产品PD01的订单导出为Excel格式保存,并只导出指定的列:
Dim ex as New Exporter
ex.SourceTableName = "订单" '指定导出表
ex.FilePath = "c:\Data\订单.xls" '指定目标文件
ex.Format = "Excel" '导出格式为Excel
ex.Fields = "日期,客户,数量,单价" '指定导出字段
ex.Filter = "[产品] = 'PD01'" '指定导出条件
ex.Export() '开始导出
帮助里面这个是按列导出的,但是,会把整个表里面的内容都导出来了。
我想要的是把筛选后的结果的内容,再按照选择的列导出来。
----------------------------------------------------------------------
Dim dt As Table = Tables("订单")
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim Style As Xls.Style = Book.NewStyle '新建一个样式
Style.BackColor = Color.Red '样式的背景颜色设为红色
For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
Sheet(0, c).Value = dt.Cols(c).Name
Next
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
For c As Integer = 0 To dt.Cols.Count -1
Sheet(r +1, c).Value = dt.rows(r)(c)
Next
If dt.rows(r)("折扣") >= 0.15 Then '如果折扣大于等于0.15
Sheet(r + 1,dt.Cols("折扣").Index).Style = Style '设置折扣单元格的样式
End If
Next
'打开工作簿
Book.Save("c:\reports\test.xls")
Dim Proc As New Process
Proc.File = "c:\reports\test.xls"
Proc.Start()
-----------------------------------------------------------
帮助里面的这个代码可以把筛选后的内容导出来,
但是却不可以选择列。
请求帮助!