Forum


Replies: 2   Views: 3819
Approach to create contracts from word file templates?
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by alerts@dalescott.com  · 25-06-2014 - 09:20

Hi Folks, I just finished my first project and wonder how I might approach things more efficiently next time. In addition to using simple variable replacements from a template doc, I need to handle more complex substations based on logic. For example, based on the value of a particular data field, I might need to insert 1 paragraph or 2 paragraphs or 1 table or another table. Using the function ReplaceVariableByText is limited to basic substitution. What is the general approach to insert formatted content into a template document? Here is what I considered... 1) Have completely separate templates, one for each variation. This isn't very elegant, but it is straightforward. Gets ugly if the template has multiple subsitutions. 2) Cut the document into template sections. Keep variations in different sections. Perform ReplaceVariableByText as needed and merge the docx together. 3) Cut the document into template sections but create variable content using docxCreate features. I ended up using method #1 above to get the job done, but want to know how to improve the process next time. One option that I wouldn't consider is to create the document from scratch using createdocx. This particular project had 10 4-page contracts for each client and only 3 days to create them. Future turnaround will be similar. The contract body could change substantially. Plus, they only execute once per year. So, how do you approach this challenge? Thanks Jonathan

Posted by admin  · 25-06-2014 - 10:16

Hi, The best approach is to use the replaceVariableByWordFragment method. It allows to replace an array of variables by Word Fragments, so there's no limit on you can do. You get the Word fragments of each element you create and replace the placeholders using replaceVariableByWordFragment. Regards.

Posted by alerts@dalescott.com  · 25-06-2014 - 17:19

Thanks! I'll give that a try.