li_ret = ole_object.ConnectToObject("","word.application")
IF li_ret <> 0 THEN
//如果Word还没有打开,则新建。
li_ret = ole_object.ConnectToNewObject("word.application")
if li_ret <> 0 then
MessageBox('OLE错误','OLE无法连接!错误号:' + string(li_ret))
return 0
end if
ole_object.Visible = True
END IF
long ll_colnum,ll_rownum
constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0
constant long wdCell = 12
string ls_value
pointer oldpointer
oldpointer = SetPointer(HourGlass!)
string ls_objects,ls_obj,ls_objs[],ls_objtag[]
long ll_pos,ll_len,ll_num = 0
for i = 1 to ll_colnum
//得到标题头的名字
ls_value = ls_objtag[i]
ole_object.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_object.Selection.TypeBackspace()
next
ole_object.Selection.MoveRight(wdCell)
next
adw.setredraw(false)
ole_object.Selection.MoveLeft(wdCell)
string column_name
for i = 2 to ll_rownum
for j = 1 to ll_colnum
column_name = ls_objs[j]
if adw.Describe(column_name + '.type') = 'column' then
ls_value = adw.Describe("Evaluate('LookupDisplay("+column_name+")',"+string(i - 1)+")")
end if
if adw.Describe(column_name + '.type') = 'compute' then
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i - 1)+")")
end if
ole_object.Selection.MoveRight(wdCell)
ole_object.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_object.Selection.TypeBackspace()
next
next
next
adw.setredraw(true)
constant long wdFormatDocument = 0
SetPointer(oldpointer)
//保存新建的文档
if messagebox("保存","文档已经成功完成,是否保存?",Question!,YesNo!) = 1 then
string docname, named
integer value
value = GetFileSaveName("选择文件",docname, named, "DOC","Doc Files (*.DOC), *.DOC")
IF value = 1 THEN
ole_object.ActiveDocument.SaveAs(docname, 0,False,"",True,"",False,False,False, False,False)
end if
end if
//断开OLE连接
Ole_Object.DisConnectObject()
Destroy Ole_Object