编写包含链接的HTML文件,该链接在特定的表格和行中打开Excel应用程序

我正在写一个非常简单的HTML文件,其中包含一些表。 我试图有一个单元格的价值,这基本上是一个链接。 通过点击链接,我想在一个特定的表格和行中的Excel应用程序中打开一个文件。

笔记:

  1. windows环境
  2. HTML由标准浏览器打开
  3. 该文件在本地存在(简单path:C:\ test.xlsx)
  4. excel应用程序的path是未知的
  5. 我想保持HTML文件尽可能简单。 好的devise不是重中之重。 只需要做到这一点。
  6. (低优先级),如果Excel实例(对于特定的文件)已经打开,我想改变活动工作表,并突出显示在打开的实例

<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> 

来源: http : //support.microsoft.com/kb/197922

我解决了它使用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> 

用法示例:

 <button onclick="open_excel_file('f1.csv', 's1', 'A1:Z7');">Open</button>