Clarity

Expand all | Collapse all

Write form data into docx file

  • 1.  Write form data into docx file

    Posted May 01, 2016 03:21 AM

    I have a requirement where I need to write the contents of my customobject form data upon some action into a word document which is stored in collaboration folder.

    So can anyone help me in achieving this functionality?



  • 2.  Re: Write form data into docx file

    Posted May 02, 2016 10:33 AM

    A clarification please , you wish to write in a Word document or any delimited document would solve your purpose?



  • 3.  Re: Write form data into docx file

    Posted May 02, 2016 11:30 AM

    Hi Nirbhay thanks for looking into it.I need to write in a worddocument not in any delimited format.The doc format will be in collaboration folder and processes should write data from custom page fields to respective section in that template word file.



  • 4.  Re: Write form data into docx file

    Posted May 03, 2016 08:09 AM

    To the level my understanding is, you can only operate on a delimited File.



  • 5.  Re: Write form data into docx file

    Posted May 03, 2016 08:37 AM

    You can build word documents that pull data out of Clarity (via web-services or direct SQL), then upload that document to Clarity (via XOG) - very little of this is "Clarity" though (only the XOG bit).



  • 6.  Re: Write form data into docx file

    Posted May 03, 2016 08:51 AM

    Good approach David, but as you said this actually has less of Clarity and much of Web services, SOAP or Restful services..

         But the number of stages this approach comprises is what makes the solution implementation a bit tricky.



  • 7.  Re: Write form data into docx file

    Posted May 03, 2016 08:56 AM

    Hi Danish,

     

    If you can drop the plan to write to a DOCX file and live with an XLS spreadsheet then I believe this post might be helpful :

     

    GEL to output a txt file



  • 8.  Re: Write form data into docx file

    Posted May 03, 2016 09:29 AM

    Thanks David and Nirbhay but I haven't work with any such webservice or direct SQL code which can write data to Docx.I guess it would involve writing some code in some programming language .So if you have any such code logic with you it would be helpful.



  • 9.  Re: Write form data into docx file

    Posted May 03, 2016 09:38 AM

    VBA would be the programming language for running a macro within word to call sql/webservices and populate a word document.

     

    But you can call SQL/webservices from *any* programming language really, so work with what you know if you can - I have no idea what you know and whether that can write into Word documents of course.

     

    You could build a REPORT though in Clarity (jaspersoft), that could provide you a document format, then use whatever you have available to upload to Clarity.

     

    (Unfortunately you are not going to get an "easy" answer to all this since it is not something that comes out-of-the-box with Clarity - the closest out-of-the-box thing is a REPORT though)



  • 10.  Re: Write form data into docx file

    Posted May 03, 2016 01:15 PM

    So if you save you word template as a Word 2003 XML document, you can use a simple Gel script to populate the template.

     

    So given this word document template

    Word Template
    Body XML

     

     

    With this Gel script:

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
        xmlns:core="jelly:core"
        xmlns:log="jelly:log"
        xmlns:util="jelly:util"
        xmlns:x="jelly:xml"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
        <!-- test values -->
        <core:set var="Plan_code" value="PlanCode1234" />
        <core:set var="Project_code" value="ProjectCode987" />
        
        <!-- find our word xml template -->
        <util:file name="wordtemplate.xml" var="template"/>
        <util:available file="${template}">
            <gel:log>Found wordtemplate.xml</gel:log>
        </util:available>
        <x:parse var="xmlWordtemplate" xml="${template}" />
    
        <!-- locate our tokens via xpath  and update the node text values-->
        <core:set var="token1" value='${xmlWordtemplate.selectSingleNode("/w:wordDocument[1]/w:body[1]/wx:sect[1]/w:p[2]/w:r[1]/w:t[1]")}' />
        <core:expr value="${token1.setText(Plan_code)}" />
        <core:set var="token2" value='${xmlWordtemplate.selectSingleNode("/w:wordDocument[1]/w:body[1]/wx:sect[1]/w:p[3]/w:r[1]/w:t[1]")}' />
        <core:expr value="${token2.setText(Project_code)}" />
    
        <!-- write our xml file out -->
        <core:file name="wordFilledOut.xml" escapeText="false" omitXmlDeclaration="true">
            ${xmlWordtemplate.asXML()}
        </core:file>
    </gel:script>
    

     

    Which produces our filled out word document.

     

    V/r,

    Gene



  • 11.  Re: Write form data into docx file

    Posted May 04, 2016 01:17 AM

    Hi Gene Thanks for this and I will try at my end.



  • 12.  Re: Write form data into docx file

    Posted May 03, 2016 02:20 PM

    Putting on my BA hat, is this a want or a need? Does it have to occur based on a condition? If not, why not just schedule a report in JasperSoft.

     

    I just have to ask.



  • 13.  Re: Write form data into docx file

    Posted May 04, 2016 01:18 AM

    Michael the requirement is based on condition it should populate the word doc with the inputs given in page.



  • 14.  Re: Write form data into docx file

    Posted May 04, 2016 08:47 AM

    ^ Still sounds like a report to me.

     

    Some interesting debate about integration with MS products here too ; MS Products as 'Reports' - Word/Excel being called from Clarity