One of the main reasons that you might need this is that Microsoft Excel and Word documents pervade. They are perfect media to store, display and distribute information and ideas.
A rather straightforward approach is to simply link that document up.
<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>
You should also read:
- PHP: setcookie() with HttpOnly Option to Reduce XSS (Cross Site Scripting) Attacks by Preventing JavaScript from Reading Cookies
- How to include a JavaScript file inside a JavaScript file?
- JavaScript: Open or Redirect to Another Page / Site / Location
- JavaScript: Confirmation / Warning before Leaving or Navigating Away from a Page
- PHP and JavaScript Variable / Value Transfer / Exchange: How to pass variable values from PHP to JavaScript or JavaScript to PHP?


Facebook
Twitter
Google Plus
{ 10 comments… read them below or add one }
Hi there, very helpful post!
I have a question – what does the 2nd argument in excelApp.Workbooks.Open(Location, FALSE, false) stand for? I understand the 1st and the 3rd one but the second one is not very clear – and I do not seem to find any useful details on msdn….
Hi Friend,
Very much thanks to you.
Thanks.
Raja.
I want to open the .doc file and I have used your above code, but when I run the application its show the following error
Microsoft jscript runtime error : Automatic server can’t create object
any suggestion
I want to open the .doc file and I have used your above code, but when I run the application its show the following error
Microsoft jscript runtime error : Automatic server can’t create object
any suggestion
to resolve your problem, enable the ActiveXObject by going to internetOpt-> Security-> custom level
i used the same code it is working fine in IE7 but it is not working in Mozilla can you give a solution to it. i try to get this using Open office plugin still i am unable to open
@Sekhar ActiveX plugins only work in IE. This code won’t work in Mozilla.
hi all.. can you please tell me the alternative to activexobject used in above code.. if i have to use it in other browsers..?
Can you send me how to fetch data from excel sheet into drop down using JavaScript. Its really very very very very urgent
thanks in advance
You need to use XMLHTTP instead of ActiveXobject.