|
|
- import winex;
- import win.ui;
- import fsys.dlg;
- import com.excel;
- /*DSG{{*/
- var winform = win.form(text="aardio form";right=396;bottom=146;parent=...)
- winform.add(
- button={cls="button";text="打开Excel文件";left=87;top=38;right=311;bottom=95;z=1}
- )
- /*}}*/
- var excel, book, sheet = null, null, null;
- winform.button.oncommand = function(id,event){
- if ("关闭Excel文件" == winform.button.text) {
- winform.button.text = "打开Excel文件";
- book.save(); book.close();
- excel.Quit();
-
- sheet = null; book = null; excel = null;//释放所有对excel对象的引用
- collectgarbage("collect");//内存回收,确保excel完全退出
- return;
- }
-
- var file_path = fsys.dlg.open("Excel文件|*.xls;*xlsx|",,,winform.hwnd);
- if (null == file_path) {
- return;
- }
-
- excel = com.excel(true);
- if (!excel) error ("Excel未正确安装!");
-
- excel.Visible = false; // Excel窗口不可见
- book = excel.WorkBooks.open(file_path);
-
- sheet = book.Worksheets(1);
- sheet.Cells(1,1).Value2 = tostring(time(, "%Y%m%d%H%M%S"));
- sheet.Range("A1").HorizontalAlignment = -4108/*_xlCenter*/; sheet.Columns(1).ColumnWidth = 48;
-
- winform.button.text = "关闭Excel文件";
- }
- winform.enableDpiScaling();
- winform.show();
- win.loopMessage();
复制代码 测试环境:32位 WIN7 SP1,WPS软件
在该代码中,先打开一个A.xls文件,并隐藏后进行操作。A.xls未关闭的情况下,在系统中打开B.xls文件,B.xls文件被显示出来的同时,连带A.xls也被显示出来了;若此时点击"关闭Excel文件"按钮,会导致A.xls和B.xls两个文件同时被关闭。
查看任务管理器,在打开了一个A.xls文件时,任务管理器中生成了一个et.exe的进程,然后在系统中打开B.xls文件,任务管理中会立即生成另外一个et.exe的进程,然后这个新et.exe关闭,紧接着系统界面同时显示出A.xls和B.xls文件。
问题1:代码中A.xls文件是被隐藏起来后进行操作,此时系统打开B.xls文件使得A.xls文件被显示出来,如何避免或解决?
问题2:如果问题1不能避免,是否有办法使打开A.xls文件时生成的et.exe进程被独占或被隐藏?
|
|