jquery - Using JavaScript to "Create" a Microsoft Word Document -
i dynamically create document using javascript , open document in microsoft word. possible? here current code:
<html> <head> <title></title> <script src="js/jquery-1.4.4.js" type="text/javascript"></script> </head> <body> <div id="mydiv">the quick brown fox jumped lazly on dead log.</div> <script type="text/jscript"> var printwindow = window.open("", "print", "width=800,height=400,scrollbar=0"); var printareahtml = $("#mydiv").attr("outerhtml"); printwindow.document.open("text/html", "replace"); printwindow.document.writeln("<html><head>") printwindow.document.writeln("<meta http-equiv='content-type' content='application/vnd.ms-word'>"); printwindow.document.writeln("<meta http-equiv='content-disposition' content='attachment;filename=print.doc'>"); printwindow.document.writeln("</head>"); printwindow.document.writeln("<body>"); printwindow.document.write(printareahtml); printwindow.document.writeln("</body>"); printwindow.document.writeln("</html>"); printwindow.document.close(); // printwindow.print(); </script> </body> </html>
i'm not sure trying in code there here information found accessing word document , table within doc:
microsoft word object model
this object model part of microsoft word (not javascript) , lets "automate" word remotely other programs (not web pages, computer program).
it designed visual basic, can accessed javascript web page - see para 2 below.
however bit more tricky use through javascript, particularly because cannot use visual basic constants - need refer them value. if research further, know mean this.
so can find out object model?
it there in word files if it.
if in word help, under programming information, find microsoft word visual basic programming reference.
the word object model, lets things need solve problem like:
- open word
- open document in word
- access collection of tables in activedocument.
- access rows , cells of given table.
how access javascript?
this might done think through internet explorer (and perhaps opera).
here need learn activexobjects.
activexobjects (if not know) separate computer programs enable additional functionality. there lots of activex objects on internet.
when install word, installs activex object automating word, giving access word object model.
so in javascript, lets open new instance of word:
var oapplication=new activexobject("word.application"); oapplication.visible=true; // "visible" in word object model`
there have it.
then if want open file , table:
oapplication.documents.open("myfilename"); var odocument=oapplication.activedocument; var otable=odocument.tables(1);`
and leave keep going rest.
Comments
Post a Comment