目的:从数据源erp中使用sql语句提取数据然后直接导出到固定的目录,格式为excel格式。
原方法:
Dim q_a As new QueryBuilder
q_a.TableName = "cw"
q_a.C
q_a.SelectString = "select a.deptcode as '部门编码',d.name as '部门名称',round(sum(b.finishnum*c.inventoryprice/a.plannum*(a.plannum-a.finishnum)),2) as '车间物料' from aeg00000 a,agb00000 b,baa00000 c,zad00000 d where a.centercode='0100' and a.finishnum<a.plannum and a.planid=b.planid and b.finishnum>0 and c.warehousecode like '01%' and b.itemcode=c.itemcode and a.deptcode=d.code group by a.deptcode,d.name order by a.deptcode"
q_a.Build
Dim ex as New Exporter
ex.SourceTableName = "cw" '指定导出表为车间物料
ex.FilePath = "D:\Data\chejian\" & format(Date.now,"yyyy年MM月dd日HH时mm分") & "车间物料" & ".xls" '指定目标文件
ex.Format = "Excel" '导出格式为Excel
ex.Export() '开始导出
但是这种方法会生成一个table表cw,如果不希望生成cw表就从后台直接导出为EXCEL表,有没有其他更好的方法?