的确是很复杂啊~~~~~~~~我觉得一下代码已经够用了:
global type gf_2excel from function_object
end type
forward prototypes
global subroutine gf_2excel (datawindow fdw)
end prototypes
global subroutine gf_2excel (datawindow fdw);if fdw.dataobject='' or isnull(fdw.dataobject) then return
long l_rc
long l_col,l_colcount,l_row
string s_temp,ls_colname
ole_object = CREATE OLEObject
IF ole_object.ConnectToNewObject("Excel.Application") <> 0 THEN
MessageBox('OLE错误','OLE无法连接!')
return
END IF
ole_object.workbooks.add
ole_object.Visible = True
ole_workbooks = ole_object.Worksheets(1)
for l_col=1 to l_colcount
ls_colname = fdw.describe('#'+string(l_col)+'.name')
if left(right(ls_colname,2),1)='_' then ls_colname=left(ls_colname,len(ls_colname)-2)//if is duplicate,cut'_#'
s_temp=ls_colname+'.ColType'//get coltype string
s_temp=fdw.Describe(s_temp)//get coltype
for l_row=0 to fdw.rowcount()
if l_row=0 then//set title
ole_workbooks.cells(l_row+1,l_col).value=fdw.describe(ls_colname+'_t.text')
else//set value
// choose case left(lower(s_temp),5)
// case 'datet'//datetime
// ole_workbooks.cells(l_row+1,l_col).value=fdw.getitemdatetime(l_row,ls_colname)
// case 'decim','int','long','numbe','real','ulong'//decimal,int long,number,real,ulong
// ole_workbooks.cells(l_row+1,l_col).value=fdw.getitemdecimal(l_row,ls_colname)
// case else//char(n)
ole_workbooks.cells(l_row+1,l_col).value=fdw.Describe("Evaluate('LookUpDisplay("+ls_colname+")',"+string(l_row)+")")//fdw.getitemstring(l_row,ls_colname)
// end choose
end if
next
next
Ole_Object.DisConnectObject()
Destroy Ole_Object
destroy ole_workbooks
end subroutine
/*---将数据窗口中的值导入Excell---*/
li_count = li_starrow - 3
for i = 3 to ll_rownum
w_progress_message_tmp.event ue_percent(i/ll_rownum*100) /* 进度条*/
li_flag = 1
FOR li_pos = 1 to upperbound(ls_group)
/*---取分组合计值,判断是否输出分组合计---*/
ls_data[li_pos] = adw.Describe("Evaluate('" + adw.Describe(ls_group[li_pos]+'_c.expression') + "',"+string(i - 2)+")")
IF isnull(ls_data[li_pos]) or ls_data[li_pos] = "!" or ls_data[li_pos]="?" THEN
ls_data[li_pos] = ""
END IF
IF ls_data[li_pos] = ls_olddata[li_pos] THEN
li_flag = li_flag*1
ELSE
li_flag = 0
END IF
/*---取分组合计值,判断是否输出分组合计完毕---*/
NEXT
IF li_flag <> 1 THEN
/*---[一组数据输出完毕]输出分组合计---*/
int k
for j = 2 to ll_colnum - 2
if j = 2 then
k = 1
else
k = j
end if
column_name = ls_objs[k]+"_c"
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i - 3)+")")
ls_coltype=adw.Describe(column_name+'.coltype')
IF isnull(ls_value) or ls_value="!" or ls_value = "?" THEN
ls_value = ""
END IF
if pos(upper(ls_coltype),"CHAR")>0 then //对字符型数据处理
ole_object.cells(i+li_count,k).NumberFormat ="@"
end if
IF detailflag = 1 THEN
// ole_object.cells(i+li_count,k).Font.Bold =true
ole_object.cells(i+li_count,k).value = ls_value
//ole_object.cells(i+li_count,k).columnwidth=900
ELSE
// ole_object.cells(3+li_count,k).Font.Bold =true
ole_object.cells(3+li_count,k).value = ls_value
//ole_object.cells(i+li_count,k).columnwidth=900
END IF
next
IF detailflag = 1 THEN
//ole_object.cells(i+li_count,1).Font.Bold =true
ole_object.cells(i+li_count,1).value = i+li_count - 2
ELSE
//ole_object.cells(3+li_count,1).Font.Bold =true
ole_object.cells(3+li_count,1).value = 3+li_count - 2
END IF
FOR li_pos = 1 to upperbound(ls_group)
ls_olddata[li_pos] = ls_data[li_pos]
NEXT
li_count ++
/*-----输出分组合计完毕----*/
END IF
/*------输出组内数据------*/
IF detailflag = 1 THEN
for j = 2 to ll_colnum - 2
if j = 2 then
k = 1
else
k = j
end if
column_name = ls_objs[j]
if adw.Describe(column_name + '.type') = 'column' then
ls_value = adw.Describe("Evaluate('LookupDisplay("+column_name+")',"+string(i - 2)+")")
end if
if adw.Describe(column_name + '.type') = 'compute' then
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i - 2)+")")
end if
IF isnull(ls_value) or ls_value="!" or ls_value = "?" THEN
ls_value = ""
END IF
if k = 1 then picpath = ls_value//add by wzf 20030726 for draw pic by pb
ls_coltype=adw.Describe(column_name+'.coltype')
if pos(upper(ls_coltype),"CHAR")>0 then //对字符型数据处理
ole_object.cells(i+li_count,k).NumberFormat ="@"
end if
// ole_object.cells(i+li_count,k).Font.Bold =false
ole_object.cells(i+li_count,k).value = ls_value
next
// ole_object.cells(i+li_count,1).Font.Bold =false
// ole_object.cells(i+li_count,1).value = i+li_count - 2
END IF
// add by wzf 20030725 for pic
if not isNUll(picpath) and picpath <> '' and FileExists(picpath) and FileLength(picpath)> 0 then
ole_object.Worksheets(1).Shapes.AddPicture(picpath, True, True, 0, (i - 3)*75 + 80, 70, 70)
end if
// add by wzf 20030725
$PBExportHeader$f_tran_excell_eachprice.srf
$PBExportComments$单价位报价单有图.----design by wolf 2003.07.24
global type f_tran_excell_eachprice from function_object
end type
forward prototypes
global function integer f_tran_excell_eachprice (datawindow adw, string reptitle, integer detailflag, string as_tempfile)
end prototypes
/*-----定义程序用到的变量-----*/
Oleobject ole_object
String s_english="ABCDEFGHIJKLMNOPQRSTUVWXYZ",column_name,ls_coltype
String ls_objects,ls_obj,ls_objs[],ls_objtag[],ls_width[],ls_value
string ls_colname,ls_syntax,ls_temp,ls_group[],ls_olddata[],ls_data[]
Integer li_ret,i,j,li_pos,li_count,li_flag,flag=0
long ll_colnum,ll_rownum,ll_pos,ll_len,ll_num = 0
dec ld_width
pointer oldpointer
int li_starrow,li_starcol
li_starrow = 5
li_starcol = 1
string picpath //add by wzf 20030726 for draw pic by pb
/*---------定 义 完 毕--------*/
if fileexists(gs_syspath+as_tempfile)=false then
messagebox(gs_sysname,gs_syspath+as_tempfile+'模板不存在!请确认')
return 0
end if
/*-------打开EXCELL文档-------*/
ole_object = CREATE OLEObject
li_ret = ole_object.ConnectToObject("Excel.Application")
IF li_ret <> 0 THEN
/*--如果Excel还没有打开则新建--*/
li_ret = ole_object.ConnectToNewObject("Excel.Application")
if li_ret <> 0 then
MessageBox('OLE错误','OLE无法连接!错误号:' + string(li_ret))
return 0
end if
END IF
/*-------打开文档完毕-------*/