ファイルが Excel インスタンスで既に開かれているかどうかを確認するにはどうすればよいですか?
私は DXL (DOORS) 言語を使用していますが、この言語から独立している必要があります。
どのファイルが開かれているかを確認し、それをパス/ファイル名と比較するために呼び出すことができる OLE メソッドはありますか?
可能であれば、その Excel アプリケーションでそのワークシート/ファイルだけを閉じることはできますか?
編集:これは私が今まで得たものです。これは機能しますが、一度だけです。DXL は Excel.exe プロセスを開いたままにし、次のチェックで、ワークブックが開いていない、またはウィンドウがまったくないインスタンスが使用されていることを確認します。
if (confirm "File \"" fPath "\" already exists. Do you want to overwrite it?") {
// check if file is opened in any Excel instance
OleAutoObj oleWorkbooks = null;
OleAutoObj oleExcel = null;
OleAutoObj oleWorkbook = null;
OleAutoArgs autoArgs = create;
oleExcel = oleGetAutoObject("Excel.Application");
bool opened = false;
// if excel is opened
if(oleExcel != null){
d("Excel is opened");
// Get workbooks and open file
oleGet(oleExcel,"Workbooks", oleWorkbooks);
// compare each open workbook
int count = 0;
oleGet(oleWorkbooks,"Count", count);
string workbookname = "";
string sPath = replace(fPath, "\\", "/");
sPath = stripPath(sPath, true);
while (count > 0) {
d("checking opened document");
clear(autoArgs);
put(autoArgs, count);
oleGet(oleWorkbooks,"Item", autoArgs, oleWorkbook);
oleGet(oleWorkbook, "Name", workbookname);
opened = sPath == workbookname;
if(opened) {
if(confirm "The file is currently opened in Excel. It must be closed. Do you want to close the document?") {
clear(autoArgs);
oleMethod(oleWorkbook,"Close",autoArgs);
}
break;
}
count--;
}
}
oleCloseAutoObject(oleExcel);
oleCloseAutoObject(oleWorkbooks);
oleCloseAutoObject(oleWorkbook);
// todo leaves excel process open
if(!opened) {
streamOutputData = write fPath;
streamOutputData << sOutput;
close streamOutputData;
return true;
}
}