Using JavaScript to Open Excel and Word Files in HTML

by kalai 2010-02-01 12:19:45

<a href="bank/sheet.xls" >some excel file </a>

Another approach is via JavaScript.

<script type="text/javascript">
function openExcel(strFilePath) {
var yourSite = "http://www.yoursite.com";
openExcelDocPath(yourSite + strFilePath, false);
}
function openExcelDocPath(strLocation, boolReadOnly) {
var objExcel;
objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = true;
objExcel.Workbooks.Open(strLocation, false, boolReadOnly);
}
</script>

To open a word document with javascript, go with the following code:

<script type="text/javascript">
function openWord(strFilePath) {
var yourSite = "http://www.yoursite.com";
openWordDocPath(yourSite + strFilePath);
}
function openWordDocPath(strLocation) {
var objWord;
objWord = new ActiveXObject("Word.Application");
objWord.Visible = true;
objWord.Documents.Open(strLocation);
}
</script>

Tagged in:

1994
like
0
dislike
0
mail
flag

You must LOGIN to add comments