Hi friend,
I have a below "keywsh.js" javascript file
I want to access the above file "keywsh.js" from Java code. I am using the below java code to access "keywsh.js".whe n I tried to run this from below Java code. I am getting Error.
Error Description:-
javax.script.Sc riptException: sun.org.mozilla .javascript.int ernal.EcmaError : Ref
erenceError: "ActiveXObj ect" is not defined. (<Unknown source>#4) in <Unknown so
urce> at line number 4
at com.sun.script. javascript.Rhin oScriptEngine.e val(R hinoScriptEngin e.ja
va:110)
at javax.script.Ab stractScriptEng ine.eval(Abstra ctScr iptEngine.java: 232)
at script1.main(sc ript1.java:18)
Can you help me to run this javacode successfully? Is there is any other Java code? Pl help me.
I have a below "keywsh.js" javascript file
Code:
var myApp = new ActiveXObject("Excel.Application");
myApp.visible = false;
var shell = new ActiveXObject("WScript.shell");
shell.run('"C:\\ROME Literature Spreadsheet.xls"',1);
WScript.sleep(5000);
shell.SendKeys("y");
myApp.ActiveWorkbook.SaveCopyAs("C:\\goon\\today.xls");
shell.SendKeys("%{F4}");
Code:
import java.io.FileReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptException;
public class script1 {
public static void main(String[] args) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
try {
FileReader reader = new FileReader("C:\\keywsh.js");
engine.eval(reader);
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
javax.script.Sc riptException: sun.org.mozilla .javascript.int ernal.EcmaError : Ref
erenceError: "ActiveXObj ect" is not defined. (<Unknown source>#4) in <Unknown so
urce> at line number 4
at com.sun.script. javascript.Rhin oScriptEngine.e val(R hinoScriptEngin e.ja
va:110)
at javax.script.Ab stractScriptEng ine.eval(Abstra ctScr iptEngine.java: 232)
at script1.main(sc ript1.java:18)
Can you help me to run this javacode successfully? Is there is any other Java code? Pl help me.
Comment