cancel
Showing results for 
Search instead for 
Did you mean: 

Create document based on word template through alfresco javascript

mitpatoliya
Star Collaborator
Star Collaborator
I am trying to create word document from word template which I have uploaded in to repository through alfresco javascript.
Issue is that arguments which I am passing during processTemplate is not replaced with place holders.
Script which I am using is as follow.


var fileNode=companyhome.childByNamePath("/Data Dictionary/Node Templates/template1.doc");
var doc1=space.createFile("testtemplate.doc");
var props = new Array(1);
props["docname"] = "tesstttt";
var content=document.processTemplate(fileNode,props);
doc1.properties.content.content= content;
doc1.mimetype = "application/msword";
doc1.save();


My word template is simple with following content.


Hello how are you ${docname}
5 REPLIES 5

kaynezhang
World-Class Innovator
World-Class Innovator
Please remember two things:
First make sure your "template1.doc" is just text format, you can create a template1.txt and rename it to template1.doc
Second ,argument you passed to model should be refered like  this  ${args["docname"]}

jpotts
World-Class Innovator
World-Class Innovator
I am fairly certain that the processDocument call does not work the way you would like it to work. It is intended to process a freemarker template in the context of a node. It doesn't have anything to do with Microsoft Word document templates.

There are ways to do what you are trying to do (inject metadata values into a Word document), but I don't think any of them are out-of-the-box unless there are some very new features I haven't played with.

Jeff

Yes, Jeff that what exactly I am trying to do "inject meta-data value to word document while creating new copy from template". I was bit lost in other task and now I am back to this task. Trying to figure out how I could do this.Let me know if you have suggestion for this.

You might look at

http://addons.alfresco.com/addons/metadata-writer

I have never used this, but I came across it when I was looking to do something similar to you (I ended up using OpenOffice + Freemarker which works well using JODConverter).

It says it will write properties, but you can embed properties in your word document by reference so far as I recall. Also, if you can write properties you can probably write variables with a modest change to the code.

If you do try it, please report back. I would be really interested to know if it works as I suspect others would.

kaynezhang
World-Class Innovator
World-Class Innovator
We can create a  text format (for example template1.txt) and rename it do template1.doc.
Although it is a fake doc,freemarker can deal with it,it will work..