如何导入EXCEL,WORD

yang528119 2003-03-20 08:41:09
如何将数据导入EXCEL,WORD要全部导入
...全文
332 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
linmana 2003-03-21
  • 打赏
  • 举报
回复
是在数据窗口导入吗?

//--------------------//
定义外部函数:f_saveas
参数类型:datawindow
返回值:空

//--------------------//

string file_name,file_path
integer value
integer r_i
string file_path_name_type//存放文件的总称
boolean lb_exist//返回指定的文件是否存在:存在返回TRUE,不存在返回FALSE;
int re_me

value=GetfileSaveName("保存文件",file_path,file_name,"xls","(*.xls),*.xls,"+"(*.txt),*.txt,"+"(*.html),*.html,"+"(*.*),*.*")

if value=1 then
lb_exist=FileExists(file_path)
if lb_exist=true then
re_me=messagebox('保存','此文件已存在,是否覆盖它?',question!,yesno!,2)
if re_me=1 then
r_i=dw_x.SaveAsAscii(file_path)
else
return
end if
else
r_i=dw_x.SaveAsAscii(file_path)
end if
end if
if r_i=1 then
messagebox('提示','保存成功!')
else
messagebox('提示','保存失败!')
return
end if
songccs 2003-03-21
  • 打赏
  • 举报
回复
SetPointer(HourGlass!)

OLEObject ole_word
ole_word = CREATE OLEObject

//创建新的Word对象并连接到该对象上
long result
result=ole_word.ConnectToNewObject("Word.Application")
IF result<> 0 THEN
Destroy ole_word
MessageBox('错误','无法创建word对象!')
return 1
END IF

ole_word.Visible =true

long l_colnum,l_rownum
constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0

//得到数据窗口数据的列数与行数(行数应该是数据行数 + 1)
l_colnum = long(dw_print.object.datawindow.column.count)
l_rownum = dw_print.rowcount() + 1

ole_word.Documents.Add("C:\Normal.dot",False,0)
//设定表格
ole_word.ActiveDocument.Tables.Add(ole_word.Selection.Range, l_rownum, l_colnum,1,0)

string str_colname
string str_value
integer i,j
//插入标题头的名字到Word文档
for i = 1 to l_colnum
str_colname = dw_print.describe('#' + string(i) + ".name") + "_t"
str_value = dw_print.describe(str_colname + ".text")
ole_word.Selection.TypeText(trim(str_value))
ole_word.Selection.MoveRight(12)
next

dw_print.setredraw(false)
ole_word.Selection.MoveLeft(12)
//插入数据窗口中的数据到Word文档
for i = 2 to l_rownum
for j = 1 to l_colnum
dw_print.scrolltorow(i - 1)
dw_print.setcolumn(j)
str_value =dw_print.gettext()
ole_word.Selection.MoveRight(12)
ole_word.Selection.TypeText(str_value)
next
next
dw_print.setredraw(true)

//保存由数据窗口数据生成的Word文档
ole_word.ActiveDocument.SaveAs(filepath, 0,False,"",True,"",False,False,False, False,False)

//断开OLE连接
ole_word.DisConnectObject()
Destroy ole_word
return 1
songccs 2003-03-21
  • 打赏
  • 举报
回复
constant integer ppLayoutBlank = 12
OLEObject ole_object
ole_object = CREATE OLEObject

integer li_ret
li_ret = ole_object.ConnectToObject("","Excel.Application")
IF li_ret <> 0 THEN
li_ret = ole_object.ConnectToNewObject("Excel.Application")
IF li_ret <> 0 THEN
messagebox("OLE错误","OLE无法连接!~r~n错误号:" + string(li_ret))
Return 0
END IF
ole_object.visible = False
END IF

pointer oldpointer
oldpointer = SetPointer(HourGlass!)

ole_object.Workbooks.open(xlsname)
ole_object.WorkSheets[1].Activate

long ll_column, ll_rowumn
ll_column = long(dw_print.object.datawindow.column.count)
ll_rowumn = dw_print.rowcount() + 1

string ls_colname[],ls_value
integer i,j

long handle

handle = OpenChannel("Excel", xlsname)

//转换标题头为中文,标题头命名应该为列名+"_t"形式
for j = 1 to ll_column
ls_colname[j] = dw_print.describe("#"+string(j)+".name")
ls_value = dw_print.describe(ls_colname[j]+"_t"+".text")
//ole_object.activesheet.cells[1,j].value = ls_value 开始的方法
SetRemote("R1C"+STRING(J), ls_value, handle)
next

//将下拉数据窗口数据值转化为显示值,数据量大时比现用方法速度慢
//If ll_column > 0 Then
// For j = 1 To ll_column
// If dw_print.Describe("#" + String(j) + ".edit.style") = 'dddw' Then
// for i=1 to ll_rowumn - 1
// SetRemote("R"+STRING(i+1)+"C"+STRING(J),dw_print.Describe("Evaluate('LookUpDisplay(#"+string(j)+")',"+string(i)+")"), handle)
// next
// end if
// next
//end if

CloseChannel(handle)
SetPointer(oldpointer)

ole_object.ActiveWorkBook.Save()
ole_object.application.quit()
ole_object.Disconnectobject()
Destroy ole_object
user_mess("文件另存成功!")
Return 1
zzz1975 2003-03-20
  • 打赏
  • 举报
回复
利用ole

1,109

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧