Friday, January 9, 2009

JavaScript Open Excel

JavaScript Open Excel: "Using Javascript to Open Excel
There are many reasons a web developer might have to think of the Javascript Open Excel function. In any case we'll try and make it as easy as possible to opening excel using js. Here's the Javascript Open Excel Code:
view plaincopy to clipboardprint?

1. var newwindow=window.open('url to.xls','window2','');

var newwindow=window.open('url to.xls','window2','');

another option would be to use this Javascript OpenExcel Function in the header of your page:
view plaincopy to clipboardprint?

1. <script language='javascript'>
2. function openExcel(strFileName) {
3. var yourAddress = 'http://www.mySite.com';
4. openExcelDocPath(yourAddress + strFileName, false);
5. }
6. function openExcelDocPath(strLocation, boolReadOnly) {
7. var objExcel;
8. objExcel = new ActiveXObject('Excel.Application');
9. objExcel.Visible = true;
10. objExcel.Workbooks.Open(strLocation, false, boolReadOnly);
11. }
12. </script>


And place this in the body of your page.
view plaincopy to clipboardprint?

1. <p><a href='#' onclick='openExcel('test.xls');'>Open Excel</a></p>

Open Excel

Javascript Open Excel is not really that complicated. Keep in mind that viewers will not be able to save or write to your webserver unless it is local."

No comments: