snowindy / scriptlet4docx Goto Github PK
View Code? Open in Web Editor NEWFully functional groovy template scriptlets inside a docx document. No need to edit docx xml source code. All scripting can be written in MS Word.
Fully functional groovy template scriptlets inside a docx document. No need to edit docx xml source code. All scripting can be written in MS Word.
if i have ${agencyName} in my template and haven't key "agencyName" in params map, i ll get next exception:
: [http-thread-pool-7067(2)] | ERROR | Cannot process template: [3f8a977f-69e8-4947-8558-9859a35e977c${__docxTemplaterInstance.replaceIfNull(agencyName)}4cdce23e-9c89-4e70-894d-fb2d099a2695${__docxTemplaterInstance.replaceIfNull(applicant)}9a93a81f-817d-4542-9ab6-feeb6f6c00e5${__docxTemplaterInstance.replaceIfNull(dulSeries)}98917caf-49ae-4a91-9124-efc2921fc894${__docxTemplaterInstance.replaceIfNull(dulNumber)}05a5f06b-6fb5-4b30-b840-4250dbc5af8a${__docxTemplaterInstance.replaceIfNull(dulIssuedBy)}b3189a1a-3463-473d-a1e4-44e2b9588a16${__docxTemplaterInstance.replaceIfNull("serviceName")}626a17ed-1912-44fb-ac12-b86c50e5efc0].
groovy.lang.MissingPropertyException: No such property: agencyName for class: groovy.tmp.templates.GStringTemplateScript1
[12:38:45] Куксо Илья: 17.11.2015 12:34:14.276 | [http-thread-pool-7067(2)] | ERROR | java.lang.RuntimeException: java.lang.RuntimeException: groovy.lang.MissingPropertyException: No such property: agencyName for class: groovy.tmp.templates.GStringTemplateScript1
groovy.lang.MissingPropertyException: No such property: agencyName for class: groovy.tmp.templates.GStringTemplateScript1
I tested using scriptlets in the header and footer of a docx file, but it didn´t work. This is a missing feature or a bug? I´m using verision 0.7.6
Ricardo Fraga Camelo
Hi snowindy !
Congratulation for your great template engine. I have however some problems when i want to format fields in italic or exponant. See my template sample above and the docx result.
Thanks for your help.
I'm trying to do a String comparison operation and show/hide text in a template. The code is as below:
<% if(P_KEY == "ARF") { %>
Display ARF Text
<% } else { %>
Display non-ARF text
<% } %>
This throws an exception as below:
groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
GStringTemplateScript16.groovy: 2: Invalid variable name. Must start with a letter but was: ?ARF?
. At [2:395] @ line 2, column 395.
cd6c79a8e03"""; if(P_KEY == ?ARF?) {
^
1 error
at groovy.text.GStringTemplateEngine$GStringTemplate.<init>(GStringTemplateEngine.java:190)
at groovy.text.GStringTemplateEngine.createTemplate(GStringTemplateEngine.java:105)
at groovy.text.TemplateEngine.createTemplate(TemplateEngine.java:38)
at org.scriptlet4docx.docx.DocxTemplater.processCleanedTemplate(DocxTemplater.java:158)
at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:255)
at org.scriptlet4docx.docx.DocxTemplater.processAndReturnInputStream(DocxTemplater.java:213)
at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:230)
I tried to use def key="ARF"
and then use the variable to compare, but that also didnt work.
I'm using v0.7.6
Can you please take a look?
Если в строке, которая вставляется с документ, содержится символ "&", то созданный документ не открывается Microsoft Word'ом.
Microsoft Word 2007
Oracle Java 1.6.0_16
ps
Отличная библиотека!
image???
There is a way to hava a byte[] or InputStream, that contains an image (jpeg or png) and put it in the template?
Code example:
Java Code:
byte[] image = loadImage();
map.put("image1", image);
InputStream docInputStream = docxTemplater.processAndReturnInputStream(map);
Template doc4x:
<%=image1%>
Hi,
can we have the option to set the tags as empty if the param is not present in the parammap.
Template has ${EmployeeName} but param doesn't contain EmployeeName
So the final generated document should have empty value instead of ${EmptyName}.
Ex: My name is ${PERSON_NAME}.
After generation, if PERSON_NAME is not provided in the map it should be
My name is .
I have a very large document (more than 200 forms). The first forms worked without problems. Currently I started to give the following error
Method code too large!
Stack:
groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: General error during class generation: Method code too large!
For what you can see is a limitation of the size of Java methods
https://stackoverflow.com/questions/24256316/method-code-too-large-in-groovy-grails
Any known workarround?
Now exists only File api. Streams api will be very usefull.
Hi,
Thank you for your excellent scriptlet4docx library. One missing feature seems to be ability to support parameters that contains '\n'. These need to be replaced with <w:br/> for appropriate rendering in most cases.
General suggestion, too much of the logic is private or package private. I looked into extending the DocxTemplater class but it is closed to extension because of private methods. I would suggest use of protected helper methods (similar to the Spring framework philosophy) for any significant logic that other might want to customize.
Thanks and Regards,
Farhan
Now i have possibility to cleanup whole cache, but i can't cleanup cache for specific key.
Example of usage:
Perhaps I'm doing something incorrectly, but looking at DocxTemplater.java and this line:
sv = sv.replace("\n", "<w:br/>");
It appears that new line characters (\r\n or \n) should result in <w:br/> elements being replaced within the XML. What I'm seeing instead is the <w:br/> text within the document post processing.
Expected:
Tyler Carver
Steven White
Amanda Bryant
Brenda Wout
Actual:
Tyler Carver<w:br/>Steven White<w:br/>Amanda Bryant<w:br/>Brenda Wout
My template has only one section now. So I'll just copy-paste the content here
<% if(L_TERM < 20) { %>
Show L_TERM less than 20 data
<% } else { %>
Show L_TERM greater than 20 data
<% } %>
and I'm getting the below error:
groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
GStringTemplateScript4.groovy: 5: expecting ')', found ';' @ line 5, column 69.
c92364810"""; if(L_TERM < 20) {;
^
1 error
at groovy.text.GStringTemplateEngine$GStringTemplate.<init>(GStringTemplateEngine.java:190)
at groovy.text.GStringTemplateEngine.createTemplate(GStringTemplateEngine.java:105)
at groovy.text.TemplateEngine.createTemplate(TemplateEngine.java:38)
at org.scriptlet4docx.docx.DocxTemplater.processCleanedTemplate(DocxTemplater.java:156)
at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:253)
at org.scriptlet4docx.docx.DocxTemplater.processAndReturnInputStream(DocxTemplater.java:211)
at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:228)
I can use equal sign perfectly fine, but < and > will get escaped.
If it is possible, to add custom replacement for null values?
Multiple conditions cannot be used in if clauses.
<% if(VAL_1=="ABC" && VAL_2>5) { %>
Display text
<% } %>
Gives an error message that
GStringTemplateScript69.groovy: 2: expecting ')', found ';' @ line 2, column 412.
f(VAL_1=="ABC" && VA
^
1 error
at groovy.text.GStringTemplateEngine$GStringTemplate.<init>(GStringTemplateEngine.java:190)
at groovy.text.GStringTemplateEngine.createTemplate(GStringTemplateEngine.java:105)
at groovy.text.TemplateEngine.createTemplate(TemplateEngine.java:38)
at org.scriptlet4docx.docx.DocxTemplater.processCleanedTemplate(DocxTemplater.java:178)
at org.scriptlet4docx.docx.DocxTemplater.processCleanedTemplate(DocxTemplater.java:96)
at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:275)
at org.scriptlet4docx.docx.DocxTemplater.processAndReturnInputStream(DocxTemplater.java:233)
at org.scriptlet4docx.docx.DocxTemplater.process(DocxTemplater.java:250)
However, a condition like
<% if(VAL_1=="ABC" || VAL_2>5) { %>
Display text
<% } %>
works fine.
For TableScriptingRowProcessor.java
private static Pattern groovyFormPattern = Pattern
.compile("\$\[((.?)(@\w+).?)\]", Pattern.DOTALL | Pattern.MULTILINE);
we need to change this to
private static Pattern groovyFormPattern = Pattern
.compile("\\$\\[((.*?)(@[\\w+\\W+][^.]*).*?)\\]", Pattern.DOTALL | Pattern.MULTILINE);
This will help in supporting the unicode names for the list.
Sample : $[@dgtag_test标签List.blahblah1]
Currently list comes as dgtag_testList
A simple example:
template
Testing report
<% def a = “some text” %>
Some text.
document
Testing report
Some text.
But I expected
Testing report
Some text.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.