//创建 连接
OleObject ole_excel
ole_excel = create OleObject
If ole_excel.ConnectToNewObject("Excel.Application") <> 0 Then
MessageBox('连接到Excel错误','请确认是否已经安装了Excel!',Exclamation!)
Destroy ole_excel
Return
End If
//打开文件
ole_excel.Application.Workbooks.Open("E:\pbStudy\synthesize\candidate.xls")
ole_excel.Application.Visible = TRUE
这么做以后为什么在窗口上不能得到想要表的数据,而是打开了那个xls文件。
想在那个控件窗口上显示数据的话怎么做?
------解决方案--------------------
//从excel文件获得数据
//建立从EXCEL表获取数据的通道
OLEObject ole1
int result ,ll_rtn,i,j
string ls_pathname,ls_filename
long ll_rowno,ll_colno
string ls_cell,ls_desc
ole1= CREATE OLEObject
result=ole1.ConnectTonewObject("Excel.application")
if result<>0 then
messagebox("提示!","连接Excel表出错,请重新选择")
return
end if
//操作员选择要导入数据的EXCEL文件
ll_rtn = getfileopenname('打开文件',ls_pathname,ls_filename,'XLS','EXCEL文件(*.xls),*.xls')
if ll_rtn<>1 then
messagebox("提示!","连接Excel表出错,请重新选择")
return
end if
ole1.workbooks.open(ls_pathname,0,0)
ole1.visible = true
ll_rowno=1
ll_colno=1
for ll_rowno = 1 to 30
for ll_colno = 1 to 3
ls_cell = string(ole1.workbooks[1].worksheets[1].cells(ll_rowno,ll_colno).value)
i = dw_1.insertrow(0)
dw_1.setitem(i,'irow',ll_rowno)
dw_1.setitem(i,'icol',ll_colno)
dw_1.setitem(i,'svalue',ls_cell)
// ls_desc += string(ll_rowno) +';'+ string(ll_colno) +';'+ string(ls_cell) + '~r~n'
next
next
//mle_1.text = ls_desc
ole1.visible = false
ole1.workbooks.close()
destroy ole1
------解决方案--------------------
OLEObject ObjExcel
ObjExcel = CREATE OLEObject
result = ObjExcel.ConnectToNewObject( "excel.application")
if result <> 0 then
messagebox("信息提示","连接EXCEL失败,请检查计算机中是否安装了EXCEL!")
Return
else
ObjExcel.Workbooks.Open(path) //ls_rj是文件的路径
string ls_copy
int i
ObjExcel.ActiveSheet.Cells.Copy
ObjExcel.Application.Visible = false
idw_dw.SetTransObject(SQLCA)
i = idw_dw.ImportClipboard(4) //将系统剪切版上的内容粘贴到数据窗口中,其中2为起始行参数
Clipboard("") //清空剪切版上的内容
ObjExcel.Quit()
ObjExcel.DisconnectObject() //断开与OLE的连接
Destroy ObjExcel
------解决方案--------------------
顶贴!!!