merge word documents

How to Merge Word Documents using Python Cloud SDK.

In a professional environment, the need often arises to merge multiple Word documents into a single, cohesive file. Whether you’re working on a collaborative project with colleagues, compiling research findings, or creating a comprehensive report, combining multiple Word documents into one can streamline your workflow and enhance document organization. Without a reliable and efficient method to merge these files, the process can quickly become cumbersome, time-consuming, and prone to errors. Thankfully, with the power of Python Cloud SDK, you can automate and simplify the task of merging Word documents.

Merge Documents REST API

To merge multiple Word documents into a single document, you can use the Aspose.Words Cloud SDK for Python. This SDK provides a simple and easy-to-use interface for merging documents, making it a convenient option for developers. With this SDK, you can merge documents of different formats, including DOC, DOCX, and more.

Now, in order to use the SDK, please execute the following command (on the command line terminal) to install the SDK:

pip install aspose-words-cloud

In case you are using PyCharm IDE, simply search asposewordscloud on the Python Interpreter window under PyCharm -> Preferences… section.

Secondly, we need to create a free account by visiting cloud dashboard. So, simply Sign Up using GitHub or Google account or click the Create a new Account button. Please note your Client Credentials as we are going to use them in the following sections.

Merge Word Documents in Python

Please follow the instructions given below to upload two Word files to Cloud storage and then merge them using a Python code snippet.

  • First step is to create an object of WordsApi class while passing Client ID and Client Secret details as arguments.
  • Secondly, call the upload_file(…) method of WordsApi class to upload the document to Cloud storage.
  • Now create an object of DocumentEntry(…) which takes the document to be merged and ImportFormatMode value as arguments.
  • Then create an object of DocumentEntryList(…) which takes the DocumentEntry object as an argument.
  • Finally, call the AppendDocumentRequest API to merge DOCX and save the output to Cloud storage.

Combine Word Documents using cURL Commands

Another way to accomplish the merging of Word documents is through cURL commands. With this approach, users can easily combine multiple Word documents by sending a request to the API endpoint with the appropriate parameters. This method is especially useful for users who prefer to work with command-line tools or who may not have access to a specific programming language or development environment.

Now, first we need to execute the following command to generate a JWT token based on Client_ID and Client_Secret details.

curl -v "" \
-d "grant_type=client_credentials&client_id=a41d01ef-dfd5-4e02-ad29-bd85fe41e3e4&client_secret=d87269aade6a46cdc295b711e26809af" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

For more information, please visit How to obtain JWT token using a Client_ID and Client_Secret key.

Once we have the JWT Token, please execute the following command to merge documents already available in cloud storage.

curl -v -X PUT "" \
-H  "accept: application/json" \
-H  "Authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{\"DocumentEntries\":[{\"Href\":\"SampleMailMergeTemplate.docx\",\"ImportFormatMode\":\"KeepSourceFormatting\"}],\"ApplyBaseDocumentHeadersAndFootersToAppendingDocuments\":true}"
  • ComparisonResult.docx - is the source document
  • MergedFile.docx - resultant output document
  • SampleMailMergeTemplate.docx - file to be appended


In conclusion, merging multiple Word documents into a single document can be a time-consuming and tedious task if done manually. However, with the help of Aspose.Words Cloud SDK for Python or cURL commands, this process can be simplified and automated. These tools offer a simple and efficient way to merge multiple Word documents while retaining the formatting and content of each document. By using these methods, users can save time and effort, and increase their productivity.

We highly recommend that you go through the following blog posts: