Skip to content
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

Implements extended-properties #1206

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

AxDSan
Copy link

@AxDSan AxDSan commented Apr 24, 2023

This PR adds support for extended-properties https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.extendedproperties?view=openxml-2.8.1

Solves #911, #572, #780 just to mention a few... I think we needed this for some time now, as I looked everywhere and the properties were not supported... and saw the couple of issues going on about it, so hopefully this takes care of that...

Example usage:

from docx import Document

def main():
    path = 'path/to/document.docx'
    doc = Document(path)

    # Sets Extended Properties, total_time, company and application
    doc.extended_properties.set_property('total_time', '1')
    doc.extended_properties.set_property('company', 'ACME')
    doc.extended_properties.set_property('manager', 'Mr. Trance')
    doc.extended_properties.set_property('application', 'LibreOffice Word')

    # Prints some Extended Properties
    print("# Pages:", doc.extended_properties.pages)
    print("# Characters:", doc.extended_properties.characters)

    # Just sets some of the regular Core Properties
    doc.core_properties.author = 'Jon Doe'
    doc.core_properties.last_modified_by = 'Jon Doe'
    
    doc.save(path)

    print(f'Successfully modified properties of "{path}".')


main()

this is wrong, and I have made some changes already, but they were not uploaded... my bad 🤷
The `'extended_properties'` elements are now being parsed... although there is an ugly hack, basically, hardcoding what I want to get from the element (text) and from which element (eg. element[1[)
This implementation introduces a very hacky and ugly way of reading and writing to the document app.xml file, which is in charge of the extended properties.
extendedprops are now being properly populated.
still a very rough version, needs to be polished a just a tad bit more...
toxicphreAK added a commit to toxicphreAK/python-docx-ng that referenced this pull request May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant