我是JavaScript的新手(并为此编码)。 问题如下。
我正在寻找一种方法来调用Excel文件,并在执行时在文档中设置一些过滤器。因此,请求的文件将按指定弹出。这应该适用于Windows 8.1。
ActiveX显然不起作用。 有没有人知道如何使这项工作?是否可以替代使用ActiveX对象?
非常感谢任何帮助。
到目前为止我的代码下面:
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();
}
答案 0 :(得分:1)
我不太清楚你的问题是什么。 但我可以推荐一个可以推动你的插件。
https://github.com/SheetJS/js-xlsx
上找到了示例代码<html>
<body>
<form name="form1">
<input type=button onClick="test()" value="Open File">
<br><br>
</form>
<script type="text/javascript">
function test() {
var Excel = new ActiveXObject("Excel.Application");
Excel.Visible = true;
Excel.Workbooks.Open("teste.xlsx");
}
</script>
</body>
</html>