-
Notifications
You must be signed in to change notification settings - Fork 392
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
Corrupted Docx Result (Template: Ms Word 2010-365) #558
Comments
Could you send me the same .docx saved from both MSWord and your libreoffice so I can see differencies |
These are the input file saved from Libreoffice - saved as Ms Word 2010-365 (input-libre.docx), and Ms Word - Windows (input-word.docx) Just in case, here's the output.docx (which contains duplicated core.xml, corrupted - executed with version 0.18.0): Output using input-word.docx: |
I am using libreoffice 7.3.7 on Ubuntu 22.04 : no problem to open both output files |
The main difference between 0.16.4 and 0.16.5 is a code managing core properties : def render_properties(self, context: Dict[str, Any], jinja_env: Optional[Environment] = None) -> None:
# List of string attributes of docx.opc.coreprops.CoreProperties which are strings.
# It seems that some attributes cannot be written as strings. Those are commented out.
properties = [
'author',
# 'category',
'comments',
# 'content_status',
'identifier',
# 'keywords',
'language',
# 'last_modified_by',
'subject',
'title',
# 'version',
]
if jinja_env is None:
jinja_env = Environment()
for prop in properties:
initial = getattr(self.docx.core_properties, prop)
template = jinja_env.from_string(initial)
rendered = template.render(context)
setattr(self.docx.core_properties, prop, rendered) The problem may come from that... |
Simple fact of getting actual docx template properties :
Makes a duplicate for This looks like a python-docx bug, not a docxtpl bug... |
This simple script using python-docx directly does the problem too : from docx import Document
# Load or create a new document
doc = Document("input-libre.docx")
# Access the core properties
core_properties = doc.core_properties
# Modify the author property
core_properties.author = 'New Author'
# Optionally, modify other properties
core_properties.title = 'New Document Title'
core_properties.subject = 'New Subject'
core_properties.keywords = 'Keyword1, Keyword2'
# Save the document
doc.save('modified_document.docx') I am getting :
Please, could open a bug to the python-docx project team ? |
@elapouya Thank you very much for your investigation and sharing findings. I have posted your findings on an existing - similar reported open issue @ python-openxml/python-docx#1037 |
Describe the bug
The bug happen when I try to use docxtpl (0.18 - latest) to render the docx template file (Ms Word 2010-365 Document).
The file is generated but can't be opened using Libreoffice (24.2.5 - released) - says corrupted (see below).
Last known docxtpl working version: 0.16.4
To Reproduce
Open and save any new .docx file using Libreoffice as Word 2010-365 Document (.docx). May add any jinja template as desired - mine is {{ test }}
Install docxtpl -
pip install docxtpl==0.18.0
Write these simple script (main.py)
python main.py
Expected behavior
As of 0.16.4 (last version working), there's no error regarding duplicated core.xml. On 0.16.5 version onward, the core.xml is duplicated. You can open the docx by renaming it to zip, see the
docProps/core.xml
, should be 2 there. I'm guessing this causing the errorScreenshots
The text was updated successfully, but these errors were encountered: