java - Error on opening ExcelFile in a scheduled task -
i've create jar file have throw vba excel macro. i've use jacob api code call :
final activexcomponent excel = new activexcomponent("excel.application"); try { final dispatch workbooks = excel.getproperty("workbooks").todispatch(); final dispatch workbook = dispatch.call(workbooks, "open", file.getabsolutepath()).todispatch(); final variant result = dispatch.call(excel, "run", new variant("\'" + file.getname() + "\'" + macro)); com.jacob.com.variant f = new com.jacob.com.variant(true); dispatch.call(workbook, "close", f); } catch (exception e) { readexcel.errorlog(e.getmessage()); } { excel.invoke("quit", new variant[0]); comthread.release(); }
this code work fine when launch jar manually, on scheduled task i've got error :
error - invoke of: open source: microsoft office excel description: microsoft office excel cannot access file « c:\users\me\desktop\project\excelwithmacro.xlsm ». there several possible reasons:
- the file name or path not exist.
- the file being used program.
- the workbook trying save has same name open workbook.
but file exist, not use other program , not open ...
the error throw on line:
final dispatch workbook = dispatch.call(workbooks, "open", file.getabsolutepath()).todispatch();
Comments
Post a Comment