write html file that contains a link that open excel application in a specific sheet & row

38,745

Solution 1

I solved it using 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>

Solution 2

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

source: http://support.microsoft.com/kb/197922

Share:
38,745
idanshmu
Author by

idanshmu

Updated on June 05, 2020

Comments

  • idanshmu
    idanshmu almost 4 years

    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.

    Notes:

    1. windows environment
    2. HTML is opened by a standard browser
    3. the file exists locally (simple path: C:\test.xlsx)
    4. excel application path is unknown
    5. 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.
    6. (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
  • Tim Williams
    Tim Williams over 11 years
    OP's Excel files are on the local filesystem. This approach will only work for files accessed via HTTP.
  • Moeez
    Moeez over 6 years
    Where you have defined the path ?
  • Moeez
    Moeez over 6 years
    <input type="button" id="dl" onclick="open_excel_file('/inventory-web/Files/Example.xlsx'‌​,'Sheet1','A1:Z7')" name="Download" class="btn btn-info" ></input> I have done this but still it's not working