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
Author by
idanshmu
Updated on June 05, 2020Comments
-
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:
- 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
-
Tim Williams over 11 yearsOP's Excel files are on the local filesystem. This approach will only work for files accessed via HTTP.
-
Moeez over 6 yearsWhere you have defined the path ?
-
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