How to Change Properties of Word Document in Python

This article offers guidance regarding how to change properties of Word document in Python. It has all the ingredients to set the environment for developing the application and a list of steps to follow along with the runnable sample code to change Word metadata in Python. You will also learn the options to access the selected properties using either index or property name as per the requirements.

Steps to Edit Word Metadata in Python

  1. Set the IDE to use Aspose.Words for Python via .NET to update metadata
  2. Load the source file using the Document object and access the custom properties collection
  3. Check if the target properties exist, then access the property and set the new value
  4. Access the built-in properties and update respective values
  5. Save the resultant Word file with new properties

These steps encapsulate the process to edit document properties in Word in python. The process begins by loading the source document and accessing the custom properties using the custom_document_properties collection where individual properties are accessed using the item index. Similarly, the built-in properties are accessed using the built_in_document_properties collection and modified.

Code to Edit Word Document Metadata in Python

This code segment illustrates the process to develop a Word metadata changer. The getitem() method requires the index of the property that is to be accessed. For this purpose, the index_of() method requires the name of the property, however, if you know the index of the target property, then use the getitem() method.

Within this article, we have delved into the process of changing metadata. If you want to learn the process to insert a bookmark in a Word file, refer to the article on how to insert a bookmark in Word using Python.

 English