-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use @Raw tags in XLSX and PPTX files #622
Comments
For docx, I would recommend you to do the transformation with an angular filter, to make things easier to read. Like this :
And in your template, simply write : For pptx, you have to change the tags, because For pptx, the equivalent would be :
|
For xlsx, this is currently not possible. So what you would want is the same, to be able to style an xlsx cell ? The equivalent in XLSX would be to use the following :
|
Good news, I've just released version 3.7.0 of the xlsx module :) You now can use the raw xml tag. |
Thank, I will try the XLSX module tomorrow. I tested raw tags in pptx, but there is problem with paragraphs : I added the template in a table, or in a text zone, but I still get this result. The only way to avoid the error is to put the tag in a text zone, without any loop on the slide, and without any other text: this does not cause the error, but the text is not rendered ... |
Most likely if you have this error, it means that you have some text before or after the tag (maybe it can just be whitespace), no characters are allowed near the {@raw} tag. I know that the file in the tests works well : https://github.com/open-xml-templating/docxtemplater/blob/master/examples/raw-xml-example.pptx?raw=true If your file doesn't have any whitespace or other characters around, maybe there is a bug, in that case it would be helpful for me to see what your file is. |
Here are 2 templates to illustrate what I tried :
|
I see, the issue is actually in docxtemplater's code. Since the beginning, the expansion of the {@rawXML} tag for pptx is expanding to the full shape : This is where it is configured : https://github.com/open-xml-templating/docxtemplater/blob/master/es6/file-type-config.js#L57 |
With the current behavior of expanding up to the full shape, it makes it possible to insert tables, shapes, which would no more be possible if using "a:p" for the expansion. I don't know whether it would be best to keep the two possibilities, and how the syntax would be. Maybe double @ : "{@@raw}" for "a:p" expansion, and single "@" for "p:sp" expansion : "{@raw}" |
In the meantime, you can change this manually by using following code : const doc = new Docxtemplater(inputZip, {
modules: [
{
optionsTransformer(options, docxtemplater) {
docxtemplater.fileTypeConfig.tagRawXml = 'a:p';
return options;
}
}
],
}); |
Thanks, I will use this workaround |
@vdechef for the workaround to work well without breaking things for docx /xlsx, you have to write a condition like this : const doc = new Docxtemplater(inputZip, {
modules: [
{
optionsTransformer(options, docxtemplater) {
if (docxtemplater.fileType === 'pptx') {
docxtemplater.fileTypeConfig.tagRawXml = 'a:p';
}
return options;
}
}
],
}); |
I'm closing this since I won't be changing this in docxtemplater 3, there's a way to change it with the optionsTransformer option. Maybe this is something that will change in docxtemplater 4, I'm not sure about that yet. |
I was wondering if it would be possible to use raw tag in xlsx and ppts templates ?
I need to change a text color, based on an hexadecimal color value defined in my data : I can create a template that works for docx files, but I cannot figure a way to do this in pptx and xlsx files.
What I do for docx is using data like this:
and template like this (I added carriage return to ease comprehension):
The text was updated successfully, but these errors were encountered: