部分代码如下:
handle=OpenChannel("Excel","test.xls")
n=dw_1.rowcount( )
for i= 1 to n
SetRemote("r"+string(i+1)+"c2",dw_1.getitemstring(i+1,"empno"),handle)
messagebox('',string(i))
next
CloseChannel(handle)
执行上述代码时,只能成功的执行一次 SetRemote("r"+string(i+1)+"c2",dw_1.getitemstring(i+1,"empno"),handle)
连Messagebox()都不执行,程序也不知怎么了.
请问这是怎么回事啊
------解决方案--------------------
测试了一下:
你的 SetRemote() 函数的写法是用于暖连接的,
但是你的OpenChannel() 方法返回的 handle 是-1,有错误.因而可以改用冷连接方法,
试一下这么写代码:
- C/C++ code
int i,handle,nstring excelstring excel_pathregistryGet("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe",&"Path",excel_path)if right (excel_path,1)='\' then excel_path += 'excel.exe'else excel_path += '\excel.exe'end ifif not fileexists(excel_path) then messagebox("提示","~n找不到 Excel 程序文件,请确认是否已经安装该软件。 ~n") close(parent) returnend ifrun(excel_path+' book1.xls')//handle=OpenChannel("Excel","book1.xls") n=dw_a.rowcount( ) //messagebox(string(n),handle) for i= 1 to n SetRemote("r"+string(i+1)+"c2",dw_a.getitemstring(i,1),'excel','book1.xls') //messagebox('',string(i)) next //CloseChannel(handle)