How to Remove an Object from an Online Word Document in Python

Editing a document online can be a complicated process without the right tools — that’s why we have a variety of APIs to assist you in your editing process. Our remove object function can be used to delete any object, such as a paragraph, table, or image, from a Word document.

To leverage this helpful tool in Python, we will first need the path of the object; if you need to obtain the path, you can call other functions with our Get-Tables, Get-Images, or Get-Body APIs to assist.

Let’s begin by installing the SDK:

Then, we can call the remove object function with the following code:

# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.EditDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
req_config = cloudmersive_convert_api_client.RemoveDocxPagesRequest() # RemoveDocxPagesRequest | Document input request
# Delete, remove pages from a Word DOCX document
api_response = api_instance.edit_document_docx_delete_pages(req_config)
except ApiException as e:
print("Exception when calling EditDocumentApi->edit_document_docx_delete_pages: %s\n" % e)

In no time at all, the target object will be removed from your Word document. At this point, if you have finished modifying your document, you can run our Finish Editing API to tie everything together and download the document. Retrieve your personal API key on the Cloudmersive website by creating a free account; this will also give you access to 800 calls/month

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store