Subscribe to Subscribers

Resources » .NET programming » ASP.NET/Web Applications

Open Word and Excel files using Javascript


Posted Date:     Category: ASP.NET/Web Applications    
Author: Member Level: Diamond    Points: 15


Many times, we need to open files on Client side. Scripting languages played a strong role in such activities. here we used word and excel automation to open file using javascript. This is called client side automation technique.



Open Word and Excel files using Javascript



Background


Background behind this article is bit interesting, we have a project in ASP.NET, which open word and excel files on client machine.
and then user can make changes in it. Team members thought, can't we open file using Javascript ? and the answer was "yes, we can but we need some code to try"
and after some trial and error we got small piece of code in javascript, that will open word and excel file in javascript with automation object.
Javascript is one of the most powerful scripting language that allows you to create word and excel object.

why not window.open() ?


window.open() in javascript will let you open word and excel file, but it's open in browser not it in's own editor.
to avoid this we have to use automation with javascript

Let's cook


Write a function in javascript and call it on button click in asp.net.
for e.g. in following code i have take "open file" button and call function javascript function openFile() on it.

code



Here we used ActiveX to create word and excel object

Write a javascript function to open file : WINWORD


Check following javascript function. to create word object

word object



Write a javascript function to open file : EXCEL


Check following javascript function.

excel object



Possible exception


when we deal with ActiveX, most of the time security issue are lift.
and if you run above code may be your browser gives you following error

error


To over come this we have to chnage the browser settings.
we have to tell browser to initialiaze and run activex controls.
change the browser setting. InternetExplorer --> Tools --> InternetOntions --> Security --> Custom Level

Browser setting



Limitations


This article opens Word/Excel using ActiveX object and unfortunately, these AciveX Plugins are only supported by Internet Explorer (tested on IE6/7/8).
These objects are used to create instances of OLE Automation. Several applications (Microsoft Office Word, Microsoft Office Excel, Windows Media Player, ...)
provide OLE Automation objects to allow communication with them.
You can use the methods and properties supported by Automation objects in JavaScript.

Client side automation is a good alternative to server side automation. Server side automation is not recommended by Microsoft itself, check article

Thanking you


Suggestions and Queries are always welcome.





Did you like this resource? Share it with your friends and show your love!


Responses to "Open Word and Excel files using Javascript"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: ASP.NET Control Extenders
    Previous Resource: Calling server side method by using Java Script.
    Return to Resources
    Post New Resource
    Category: ASP.NET/Web Applications


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Open Word and Excel files using Javascript  .  

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.