docx/pptx - very different to (eg) xlsx and chrome-pdf



  • Is there any reason that the docx/pptx recipes are quite different to the xlsx and others in the way it works? Not in a rush to use them, but was trying to understand if we'll end up with a similar model where we can edit the script within Studio and use that to update a bare bones template (more so for docx than powerpoint)?

    I spent some time today trying to build a template for a table in Word which will have a variable number of columns as well as rows and while this has been fairly easy to achieve in chrome-pdf (including switching from portrait to landscape if the number of columns exceeds a certain threshold) and loading the data into an xlsx sheet ... I've got nowhere productive with the docx setup (and having to edit the template in Word and upload has made it more time consuming!)


  • administrators

    Is there any reason that the docx/pptx recipes are quite different to the xlsx and others in the way it works?

    as you already know, trying to make dynamic these kind of documents (xlsx, docx, pptx, etc) is tricky, they are static by nature so if you want to generate these files based on some dynamic data you need to go low level in the internals of these files and start to find, update, add things manually.

    this is basically the approach that uses the jsreport-xlsx recipe, it lets you modify the internal structure (xml files) of the xlsx using template engine and raw xml modifications, this approach is really powerful because you can do everything you want with the files, but it requires that the developer have to become an expert about the OpenXML spec, which makes simple things harder, complex things even more harder, and in most cases a bit impossible to do it manually. knowing how to correctly modify these xml files is hard, it requires some level of expertise in the OpenXML spec, as you may guess using this approach is not the best for the developer, not everyone will become an expert in the OpenXML spec and we identified that as a major flag in this strategy, and we always thought that using the xlsx recipe is not the best experience with jsreport.

    the way that docx, pptx works is our new attempt to fix the developer experience when generating dynamic office documents, instead of let you modify the xml files on your own, we instead handle these manual operations (updates to the xml files) ourselves, you as the developer only need to define the dynamic parts of the office document using handlebars syntax {{}} (which is easy to do when you do it using the visual editors like Word, etc) and we will do the rest of the job in order to modify the xml files. this approach is not powerful from the start, because it is always limited to what we expose and support, but we think is a great experience for the developer to define dynamic content in this way intead of going to low level in xml internals. it will eventually become more powerful, we will continue adding support for more complex things the developer try to do, we just need bug reports and use cases to continue improving the extensions.

    Not in a rush to use them, but was trying to understand if we'll end up with a similar model where we can edit the script within Studio and use that to update a bare bones template (more so for docx than powerpoint)?

    it is still too early stage for docx, pptx. so far we don't let you modify the xml files on your own, so you can not use an script to modify the template content in this way. however this can be possible in the future, we can expose some kind of api for scripts which can let you modify the template the way you want, but as i said we are in early stage and we are still looking for more feedback to discuss what good solutions can look like for each use case.

    I spent some time today trying to build a template for a table in Word which will have a variable number of columns as well as rows and while this has been fairly easy to achieve in chrome-pdf (including switching from portrait to landscape if the number of columns exceeds a certain threshold) and loading the data into an xlsx sheet ... I've got nowhere productive with the docx setup (and having to edit the template in Word and upload has made it more time consuming!)

    i see, have you tried to create the docx template as a linked asset? i mean, when you create an asset, you have a "link to existing file" checkbox, if you select it you can pass there a path to your docx file and the asset will always read that file directly from the filesystem and treat it as the source of truth. using that approach you won't need to uplodad the docx file every time you make a change to the docx template.



  • thanks for the detailed feedback - as I'd worked with OpenXML back in the day I like the way the xlsx recipe lets me get hands-on for some things, but also lets me re-use template items, but ... I also like the idea of moving more to a 'designer' view of things using handlebars within the Word doc (or PowerPoint or Spreadsheet) to achieve the same results without having to know as much about the internals. Will this new model also allow more than just handlebars (so if we want to do some logic within the document based in the data - ie use javascript or VBA to handle something more complex than just what handlebars will let us do) - if not, that's where the current xlsx model would be good to let us extend further.

    I'd not tried using the docx as a linked asset, that would certainly save me a few steps as I experiment!

    If my current use-case of a table with variable rows supportable, or should I drop in a feature request to github for that?


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.