2

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

笔记:

  1. 窗户环境
  2. HTML 由标准浏览器打开
  3. 该文件在本地存在(简单路径:C:\test.xlsx)
  4. excel应用路径未知
  5. 我想让 HTML 文件尽可能简单。好的设计不是重中之重。只需要让它发生。
  6. (低优先级)如果 excel 实例(对于特定文件)已经打开,我想更改活动工作表并突出显示打开实例中的行
4

2 回答 2

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

于 2013-01-23T19:12:32.403 回答
1

我使用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>
于 2013-07-01T09:52:11.397 回答