在网上下了个changexcel(dw_1,'') 的函数
但是在使用过程中 出现 以下错误
谁给个解释?
------解决方案--------------------
楼主是想将dw导出带标题excel吧,建议使用dw2xls,不仅带标题,数据窗口的格式,计算列等信息也均可导出。如果实在不想用,楼主可以试一下,下面函数可正常导出带标题的excel
///////////////////////////////////////////////////////////////////////////
//
// parameters : ad_dw : datawindow
// as_file : file name
// returns : true/false : boolean
// description : save the datawindow as a excel file.
//
///////////////////////////////////////////////////////////////////////////
// author : purplekite
// date : 2003-01-23
///////////////////////////////////////////////////////////////////////////
setpointer(hourglass!)
//declare the local variables
long i, j, li_pos
string ls_objects, ls_obj, ls_text, ls_err, ls_sql
datastore lds_saveas //导出数据窗
datastore lds_sort //获得根据 object.x 排序的 (band = detail and visible = 1) 的 column/compute
boolean lb_return //返回值
string ls_pbver //pb 版本信息
environment env //环境变量
getenvironment(env)
ls_pbver = string(env.pbmajorrevision)
//创建排序列 datastore
lds_sort = create datastore
ls_sql = 'column=(type=char(1) name = ztext dbname="ztext" )' + '~r~n' + &
'column=(type=char(1) name = zcol dbname="zcol" )' + '~r~n' + &
'column=(type=long name = zx dbname="zx" )' + '~r~n'
ls_sql = 'release ' + ls_pbver + ';~r~ntable(' + ls_sql + ')'
lds_sort.create(ls_sql, ls_err)
if len(ls_err) > 0 then
lb_return = false
goto lab1
end if
//准备数据====================================================
//all controls
ls_objects = ad_dw.describe("datawindow.objects")
//按~t位置作判断开始循环
do while (pos(ls_objects,"~t") > 0)
li_pos = pos(ls_objects,"~t")
ls_obj = left(ls_objects,li_pos - 1)
ls_objects = right(ls_objects,len(ls_objects) - li_pos)
//(column or compute ) at detail and visible
if (ad_dw.describe(ls_obj+".type") = "column" or &
ad_dw.describe(ls_obj+".type") = "compute" ) and &
(ad_dw.describe(ls_obj+".band") = "detail" ) and &
(ad_dw.describe(ls_obj+".visible") = "1" ) then
ls_text = ad_dw.describe(ls_obj + '_t.text')
if ls_text <> '!' and ls_text <> '?' then
lds_sort.insertrow(0)
lds_sort.setitem(lds_sort.rowcount(), 'ztext', ls_text)
lds_sort.setitem(lds_sort.rowcount(), 'zcol', ls_obj)
lds_sort.setitem(lds_sort.rowcount(), 'zx', long(ad_dw.describe(ls_obj + '.x')))
end if
end if
loop
//the last control
ls_obj = ls_objects
if (ad_dw.describe(ls_obj+".type") = "column" or &
ad_dw.describe(ls_obj+".type") = "compute" ) and &
(ad_dw.describe(ls_obj+".band") = "detail" ) and &
(ad_dw.describe(ls_obj+".visible") = "1" ) then
ls_text = ad_dw.describe(ls_obj + '_t.text')
if ls_text <> '!' and ls_text <> '?' then
lds_sort.insertrow(0)
lds_sort.setitem(lds_sort.rowcount(), 'ztext', ls_text)
lds_sort.setitem(lds_sort.rowcount(), 'zcol', ls_obj)
lds_sort.setitem(lds_sort.rowcount(), 'zx', long(ad_dw.describe(ls_obj + '.x')))
end if
end if
//如果没有列则跳出
if lds_sort.rowcount() < 1 then goto lab1
//根据 object.x 排序
lds_sort.setsort('zx a')
lds_sort.sort()
//创建导出 datastore
lds_saveas = create datastore
ls_sql = ''
for i = 1 to lds_sort.rowcount()
ls_obj = lds_sort.getitemstring(i, 'zcol')
ls_sql += 'column=(type=char(1) dbname="' + ls_obj + '" )' + '~r~n'
next
ls_sql = 'release ' + ls_pbver + ';~r~ntable(' + ls_sql + ')'
lds_saveas.create(ls_sql, ls_err)
if len(ls_err) > 0 then
lb_return = false
goto lab1
end if
//向 lds_saveas 中写数据
for i = 1 to ad_dw.rowcount()