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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -