I'm pretty new to JavaScript (and coding for that matter). The problem is the following.
I'm looking for a way to call an Excel file and set some filters in the document when executed. So the requested file would pop up as specified. This is supposed to work on Windows 8.1.
ActiveX apparently does not work. Does anybody have an idea how to makes this work? Is there a substitute for using ActiveX Objects?
Any help is much appreciated.
Below the code I have so far:
var sId = "1989";
var app = "Excel.Application";
var path = "C:\\Temp\\UmsatzGL.xls";
var sheet = "Output";
var range = "FilterWE";
var filterdefault = "(Alle)";
return_wbook = "T";
return_sheet = "T";
return_range = "T";
var UsrLanguage = "de";
switch (UsrLanguage) {
case "de":
alert_wbook = 'Excelmappe ' +path+' kann nicht gefunden werden!';
alert_sheet = 'Arbeitsblatt ' +sheet+' ist nicht vorhanden!';
alert_range = 'Bereich ' +range+' ist nicht vorhanden!';
alert_content = 'Kunde ' +sId+' ist nicht vorhanden!';
break;
case "en":
alert_wbook = 'Excel-File ' +path+' does not exist!';
alert_sheet = 'Worksheet ' +sheet+' does not exist!';
alert_range = 'Range ' +range+' does not exist!';
alert_content = 'Customer ' +sId+' does not exist!';
break;
default:
alert_wbook = 'Excel-File ' +path+' does not exist!';
alert_sheet = 'Worksheet ' +sheet+' does not exist!';
alert_range = 'Range ' +range+' does not exist!';
alert_content = 'Customer ' +sId+' does not exist!';
break;
}
function my_get_app(app){
try{return GetObject('',app)}
catch(e){return my_start_app(app)}
}
function my_start_app(app){
return new ActiveXObject(app)
}
function my_get_wbook(path){
try{return excel.Workbooks.Open(path)}
catch(e){return_wbook = "F";}
}
function my_get_sheet(sheet){
try{return excel.Worksheets(sheet)}
catch(e){return_sheet = "F";}
}
function my_get_range(range){
try{return excel_sheet.range(range)}
catch(e){return_range = "F";}
}
var excel = my_get_app(app);
var excel_file = my_get_wbook(path);
var excel_sheet = my_get_sheet(sheet);
var excel_range = my_get_range(range);
excel.displayalerts = false;
if (return_wbook == "F") {
alert(alert_wbook);
excel.quit();
} else if (return_sheet == "F") {
alert(alert_sheet);
excel.quit();
} else if (return_range == "F") {
alert(alert_range);
excel.quit();
}
if (return_wbook != "F" && return_sheet != "F" && return_range != "F") {
excel_range.value = filterdefault;
try{
excel_range.value = sId;
excel.Visible=true;
excel_sheet.Activate;
}
catch(e){
alert(alert_content);
excel.quit();
}
}
close();
}