编写包含在特定工作表和行中打开 Excel 应用程序的链接的 html 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14487483/
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
write html file that contains a link that open excel application in a specific sheet & row
提问by idanshmu
I'm writing a very simple HTML file that contains some tables. I'm trying to have a cell value, which is basically a link. by clicking on the link I'd like to open a file in an excel application in a specific sheet and row.
我正在编写一个非常简单的 HTML 文件,其中包含一些表格。我正在尝试获得一个单元格值,它基本上是一个链接。通过单击链接,我想在特定工作表和行中的 Excel 应用程序中打开文件。
Notes:
笔记:
- windows environment
- HTML is opened by a standard browser
- the file exists locally (simple path: C:\test.xlsx)
- excel application path is unknown
- I'd like to keep the HTML file as simple as possible. good design is not a top priority. just need to make it happen.
- (low priority) if excel instance (for a specific file) is already open, I'd like to change the active sheet and highlight the row in the open instance
- 窗口环境
- HTML 由标准浏览器打开
- 该文件存在于本地(简单路径:C:\test.xlsx)
- excel应用路径未知
- 我想让 HTML 文件尽可能简单。好的设计不是重中之重。只需要让它发生。
- (低优先级)如果 excel 实例(对于特定文件)已经打开,我想更改活动工作表并突出显示打开实例中的行
采纳答案by idanshmu
I solved it using javascript:
我使用javascript解决了它:
<script type="text/javascript">
function open_excel_file(path,sheet,f_range)
{
if (!window.ActiveXObject)
{
alert ("Your browser does not support this feature.\n"
"Please re-open this file using IE browser.");
return;
}
fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FileExists(path))
alert("Cannot open file.\nFile '" + path + "' doesn't exist.");
else
{
var myApp = new ActiveXObject("Excel.Application");
if (myApp != null)
{
myApp.visible = true;
Book = myApp.workbooks.open(path);
var excel_sheet = Book.Worksheets(sheet).Activate;
myApp.range(f_range).Select;
}
else {
alert ("Cannot open Excel application");
}
}
}
</script>
usage example:
用法示例:
<button onclick="open_excel_file('f1.csv', 's1', 'A1:Z7');">Open</button>
回答by Eric Goncalves
<HTML>
<HEAD>
<Title>Excel Linking Example</Title>
</HEAD>
<body>
<p>
<a href="http://localhost/excel/asheet.xls#Sheet2!D4">
This link will open the Excel file to the second page with the focus on
cell D4</a>.
<a href="http://localhost/excel/asheet.xls#TableName">
This link will set the focus on a named area of the spreadsheet
</a>.
</p>
<form>
<input type=button
value="Via Jscript"
onclick='location.href = "asheet.xls#TableName"'>
</form>
</body>
</html>