急~高分,程序中如何判断一个excel文件是否已经打开?

ranliang 2003-05-08 10:14:13
用下面的代码可以打开一个xls文件
OLEObject xlapp , xlsub
xlApp.Application.Workbooks.Open("C:\表1.XLS")
xlApp.Application.Visible = true
xlsub = xlapp.Application.ActiveWorkbook.Worksheets[1]
.........
xlApp.DisConnectObject()
Destroy xlapp

请教一下,如何在打开之前,判断一下,此文件是否已经打开,如未打开就open
如已经打开,系统提示

...全文
130 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
juwuyi 2003-05-09
  • 打赏
  • 举报
回复
Declare FindWindowA as a global external function:

FUNCTION uint FindWindowA (long classname, &

string windowname) LIBRARY "user32.dll"

Then add code like the following to your application's open event:

uint val

val = FindWindowA(0, "MyApp Main Window")

IF val > 0 THEN
MessageBox("Application already running", &
"MyApp is already running. You cannot &
start it again")
HALT CLOSE
ELSE
open(w_main)
END IF
jucia 2003-05-09
  • 打赏
  • 举报
回复
ii_message = GetFilesaveName("ÇëÑ¡Ôñµ¼³öÎļþ", &
+ ls_path, ls_fname, "XLS", &
+ "ExcelÎļþ (*.xls), *.xls")
IF ii_message <> 1 THEN
return //ii_message
end if

setpointer(hourglass!)

if fileexists(ls_path) then
li_file = fileopen(ls_path)
if li_file = -1 then
ii_param_1 = messagebox('提示', '该文件已打开')
return //ii_param
end if
FileClose(li_file)

ii_param_2 = messagebox('提示', ‘该文件未打开打开', Question!, YesNo!)
if ii_param_2 = 2 then
return //ii_param
end if

end if
zhouweiwansui 2003-05-08
  • 打赏
  • 举报
回复
这个问题可以这么解决:写一函数:
of_file_can_open(string filename) return boolean

integer li_FileNum
try
if not fileexists(filename) then return false
//好像必须要用独占方式打开才可以
li_FileNum = FileOpen(FileName,StreamMode!, Write!, LockWrite!, Append!)
return (li_filenum>0)
finally
if li_filenum>0 then fileclose(li_filenum)
end try

1,108

社区成员

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

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