Javascript 如何使用javascript在excel应用程序中打开excel html文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6784681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use javascript to open excel html file in excel application
提问by RetroCoder
How to use javascript or jQuery to open an excel html file in excel from the browser?
如何使用 javascript 或 jQuery 从浏览器中打开 excel 中的 excel html 文件?
I've been trying to just use the window.open(href) to open an html excel file. It location on server is: /server/excelfiles/myexcel.xls, and I'm trying to open it in an excel app and not in an active x control in IE browser. Its this even possible to open up a file in the application instead of the browser?
我一直在尝试使用 window.open(href) 打开一个 html excel 文件。它在服务器上的位置是:/server/excelfiles/myexcel.xls,我试图在 excel 应用程序中打开它,而不是在 IE 浏览器的活动 x 控件中打开它。它甚至可以在应用程序中而不是浏览器中打开文件吗?
采纳答案by Mrchief
Two methods:
两种方法:
<a href="/server/excelfiles/myexcel.xls" target="_blank">open myexcel.xls</a>
or via JS:
或通过JS:
function openExcelFile(strFilePath) {
if (window.ActiveXObject) {
try {
var objExcel;
objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = true;
objExcel.Workbooks.Open(strLocation, false, [readonly: true|false]);
}
catch (e) {
alert (e.message);
}
}
else {
alert ("Your browser does not support this.");
}
}
回答by roberkules
if you link to the xls file, the user will be asked if he wants to download it (or will download it automatically)... then, depending on his settings, it will open automatically in excel or, what's more likely, it just ended up in his downloads folder and he has to open it manually.
如果您链接到 xls 文件,则会询问用户是否要下载它(或会自动下载)...然后,根据他的设置,它将在 excel 中自动打开,或者更有可能的是,它只是最终出现在他的下载文件夹中,他必须手动打开它。
回答by roberkules
In javascript you cannot access to the client softwares or hardisk (for security reason). You only can trigger the download of the xls file and open it manually
在 javascript 中,您无法访问客户端软件或硬盘(出于安全原因)。只能触发下载xls文件并手动打开
回答by RetroCoder
This link is informational and work in opening it up in a browser: http://www.dynamicdrive.com/forums/showthread.php?t=6138.
此链接提供信息,可用于在浏览器中打开它:http: //www.dynamicdrive.com/forums/showthread.php? t= 6138。
This link is key for opening the file based on file type: http://www.codingforums.com/showthread.php?t=99465
此链接是根据文件类型打开文件的关键:http: //www.codingforums.com/showthread.php?t=99465
Notice the rel attributeis set to nofollow , and the target is set to '_blank'.
请注意rel 属性设置为 nofollow ,目标设置为 '_blank'。
document.location.rel="nofollow" target='_blank';
document.location.href="index.php?hitCount=1&linkID=" + linkID;