You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After then file is created, I get an error message when I open the new file
What can I do to avoid having this error show up
Thanks and sorry
Screenshots
print("Template document updated to match source document.")
fromdocximportDocumentfromdocx.oxmlimportparse_xmlfromdocx.oxml.nsimportnsmapfromcopyimportdeepcopy# Load the source documentsource_doc=Document(r'C:\Users\Tal15\Desktop\Word automate\Source folder\file1_source.docx')
# Create a new Word documentnew_doc=Document()
# Function to clear the body of the documentdefclear_body(source_doc):
body=source_doc.element.bodyforchildinlist(body):
body.remove(child)
# Clear the body of the template documentclear_body(new_doc)
# Helper function to copy XML contentdefcopy_element(element):
returndeepcopy(element)
# Copy all elements from source document to template documentforelementinsource_doc.element.body:
new_element=copy_element(element)
new_doc.element.body.append(new_element)
# Save the new document to a specified pathnew_doc.save(r'C:\Users\Tal15\Desktop\Word automate\Destination folder\new_file.docx')
print("Template document updated to match source document.")
The text was updated successfully, but these errors were encountered:
Describe your problem
After then file is created, I get an error message when I open the new file
What can I do to avoid having this error show up
Thanks and sorry
Screenshots
print("Template document updated to match source document.")
The text was updated successfully, but these errors were encountered: