1.
OLEObject ole_object , ole_workbooks
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)
lls(1,1).value="id" //数据窗口的标题 就是表头
lls(1,2).value="用户名"
lls(1,3).value="密码"
// lls(1,4).value="机器号"
/
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)
lls(1,1).value="id" //数据窗口的标题 就是表头
lls(1,2).value="用户名"
lls(1,3).value="密码"
// lls(1,4).value="机器号"
/
/ lls(1,5).value="开始时间"
// lls(1,6).value="结束时间"
long l_row
for l_row = 1 to wcount()
lls(l_row+1,1).value=itemnumber(l_row ,1)
lls(l_row+1,2).value=itemstring(l_row ,2)
lls(l_row+1,3).value=itemstring(l_row ,3)
// lls(l_row,4).value=itemnumber(l_row,4)
// lls(l_row,5).value=itemtime(l_row,5)
// lls(l_row,6).value=itemtime(l_row,6)
next
ole_workbooks.SaveAs ("d:\data.xlsx")
ole_object.quit()
Ole_Object.DisConnectObject()
Destroy Ole_Object
destroy ole_workbooks
// lls(1,6).value="结束时间"
long l_row
for l_row = 1 to wcount()
lls(l_row+1,1).value=itemnumber(l_row ,1)
lls(l_row+1,2).value=itemstring(l_row ,2)
lls(l_row+1,3).value=itemstring(l_row ,3)
// lls(l_row,4).value=itemnumber(l_row,4)
// lls(l_row,5).value=itemtime(l_row,5)
// lls(l_row,6).value=itemtime(l_row,6)
next
ole_workbooks.SaveAs ("d:\data.xlsx")
ole_object.quit()
Ole_Object.DisConnectObject()
Destroy Ole_Object
destroy ole_workbooks
2
PB数据窗口导出到EXCEL函数
function f_oletoexcel(adw datawindow,title string,as_file string)
Oleobject ole_object
String s_english="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
String ls_obj,ls_objs[],ls_objtag[],ls_width[],ls_value,column_name,ls_coltype,ls_range
Integer li_ret,i,li_grouprow,li_newgrouprow,j,row,groupflag,detailflag,sumflag
Long ll_row,ll_num,ll_column,ll_groupnum,ll_sumrow
Int li_rtn=-9
dec ld_width
Pointer oldpointer
String s_english="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
String ls_obj,ls_objs[],ls_objtag[],ls_width[],ls_value,column_name,ls_coltype,ls_range
Integer li_ret,i,li_grouprow,li_newgrouprow,j,row,groupflag,detailflag,sumflag
Long ll_row,ll_num,ll_column,ll_groupnum,ll_sumrow
Int li_rtn=-9
dec ld_width
Pointer oldpointer
groupflag=0
detailflag=1
sumflag=1
/*-------打开EXCELL文档-------*/
detailflag=1
sumflag=1
/*-------打开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))
li_rtn = -1
goto totheend
end if
ole_object.Visible = False //一般自动保存时设为不可视
END IF
/*-------打开文档完毕-------*/
oldpointer = SetPointer(HourGlass!)
ole_object.Workbooks.Add
ll_row = 1
ll_column =long(adw.Object.DataWindow.Column.Count)
ll_num = 1
//"#1"可以指向第一列,#2则指向datawindow的第二列
FOR i = 1 TO ll_column
IF adw.Describe("#"+String(i)+".Visible")="1" and adw.Describe("#"+String(i)+".Band")="detail" THEN
yield()
ls_obj = adw.Describe("#"+String(i)+".name")
ls_objs[ll_num] = ls_obj
ls_objtag[ll_num]=adw.Describe(ls_obj+"_t.text") //字段名称的显示值
// messagebox(ls_obj,adw.Describe(ls_obj+"_t.text"))
ls_width[ll_num]= adw.Describe(ls_obj + '.width') //每列的宽度
ll_num++
END IF
NEXT
//messagebox("",ll_column)
ll_column = upperbound(ls_objs)
ls_objs[ll_num] = ls_obj
ls_objtag[ll_num]=adw.Describe(ls_obj+"_t.text") //字段名称的显示值
// messagebox(ls_obj,adw.Describe(ls_obj+"_t.text"))
ls_width[ll_num]= adw.Describe(ls_obj + '.width') //每列的宽度
ll_num++
END IF
NEXT
//messagebox("",ll_column)
ll_column = upperbound(ls_objs)
if ll_column <= 26 then
ls_range = Char(64+ll_column)
else
ls_range = char(64+integer((ll_column - 1)/26))+char(64+integer(mod((ll_column - 1),26)+1))
ls_range = Char(64+ll_column)
else
ls_range = char(64+integer((ll_column - 1)/26))+char(64+integer(mod((ll_column - 1),26)+1))
end if
IF trim(title)<>"" THEN
ll_row = 2
/*-------生成标题-------*/
ll_row = 2
/*-------生成标题-------*/
ole_object.Cells(1,1).Value =title
ole_object.Range('A1').Select
ole_object.Selection.Font.Size =24
ole_object.selection.HorizontalAlignment =3
ole_object.Range('A1:'+ls_range+'1').Select
ole_object.Range('A1:'+ls_range+'1').Merge
ole_object.Range('A1').Select
ole_object.Selection.Font.Size =24
ole_object.selection.HorizontalAlignment =3
ole_object.Range('A1:'+ls_range+'1').Select
ole_object.Range('A1:'+ls_range+'1').Merge
END IF
字符串长度在线测试/*-------设置标题栏-------*/
for i = 1 to ll_column
yield()
字符串长度在线测试/*-------设置标题栏-------*/
for i = 1 to ll_column
yield()
ls_value = ls_objtag[i]
lls(ll_row,i).value = ls_value //1
if isnull(ls_width[i]) then
ld_width=12
else
ld_width=dec(ls_width[i])/35
end if
ole_object.Columns(i).ColumnWidth=ld_width
ole_object.Columns(i).HorizontalAlignment =3
ole_object.Columns(i).Borders.LineStyle= 1
ole_object.Columns(i).Font.Bold =True
next
IF groupflag = 1 and detailflag = 0 THEN
ll_row ++
END IF
lls(ll_row,i).value = ls_value //1
if isnull(ls_width[i]) then
ld_width=12
else
ld_width=dec(ls_width[i])/35
end if
ole_object.Columns(i).ColumnWidth=ld_width
ole_object.Columns(i).HorizontalAlignment =3
ole_object.Columns(i).Borders.LineStyle= 1
ole_object.Columns(i).Font.Bold =True
next
IF groupflag = 1 and detailflag = 0 THEN
ll_row ++
END IF
li_grouprow = 0
ll_groupnum = 0
IF groupflag = 1 THEN
ll_groupnum = 0
IF groupflag = 1 THEN
FOR i = 1 wcount()
li_newgrouprow = adw.findgroupchange(i,1)
IF li_newgrouprow = i THEN
IF li_grouprow > 0 THEN
row = i*detailflag + ll_row + ll_groupnum
for j = 1 to ll_column
yield()
li_newgrouprow = adw.findgroupchange(i,1)
IF li_newgrouprow = i THEN
IF li_grouprow > 0 THEN
row = i*detailflag + ll_row + ll_groupnum
for j = 1 to ll_column
yield()
column_name = ls_objs[j]+"_c"
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(li_grouprow)+")")
ls_coltype=adw.Describe(column_name+'.coltype')
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(li_grouprow)+")")
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 //对字符型数据处理
lls(row,j).NumberFormat ="@"
end if
lls(row,j).Font.Bold =true
lls(row,j).value = ls_value
next
ll_groupnum++
li_grouprow = li_newgrouprow
ELSE
li_grouprow = li_newgrouprow
END IF
IF detailflag = 1 THEN
ls_value = ""
END IF
if pos(upper(ls_coltype),"CHAR")>0 then //对字符型数据处理
lls(row,j).NumberFormat ="@"
end if
lls(row,j).Font.Bold =true
lls(row,j).value = ls_value
next
ll_groupnum++
li_grouprow = li_newgrouprow
ELSE
li_grouprow = li_newgrouprow
END IF
IF detailflag = 1 THEN
row = i + ll_row + ll_groupnum
for j = 1 to ll_column
yield()
for j = 1 to ll_column
yield()
column_name = ls_objs[j]
if adw.Describe(column_name + '.type') = 'column' then
ls_value = adw.Describe("Evaluate('LookupDisplay("+column_name+")',"+string(i)+")")
end if
if adw.Describe(column_name + '.type') = 'compute' then
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i)+")")
end if
IF isnull(ls_value) or ls_value="!" or ls_value = "?" THEN
ls_value = ""
END IF
if adw.Describe(column_name + '.type') = 'column' then
ls_value = adw.Describe("Evaluate('LookupDisplay("+column_name+")',"+string(i)+")")
end if
if adw.Describe(column_name + '.type') = 'compute' then
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i)+")")
end if
IF isnull(ls_value) or ls_value="!" or ls_value = "?" THEN
ls_value = ""
END IF
ls_coltype=adw.Describe(column_name+'.coltype')
if pos(upper(ls_coltype),"CHAR")>0 then //对字符型数据处理
lls(row,j).NumberFormat ="@"
end if
lls(row,j).Font.Bold =false
lls(row,j).value = ls_value
next
END IF
ELSE
IF detailflag = 1 THEN
row = i + ll_row + ll_groupnum
for j = 1 to ll_column
yield()
if pos(upper(ls_coltype),"CHAR")>0 then //对字符型数据处理
lls(row,j).NumberFormat ="@"
end if
lls(row,j).Font.Bold =false
lls(row,j).value = ls_value
next
END IF
ELSE
IF detailflag = 1 THEN
row = i + ll_row + ll_groupnum
for j = 1 to ll_column
yield()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论