
MS Word files are popular office file formats for data processing and information sharing. Multiple resources work in organizations and produce numerous documents on a daily basis and for data archives, we may stumble upon a requirement to merge documents produced by multiple teams located at distant geographical locations. In this article, we are going to discuss the steps on how to combine multiple Word files into single resultant output using REST API.
Word processing REST API
The Word documents have various formats and in order to fulfill this requirement, Aspose.Words Cloud offers the capabilities to combine various MS Word and OpenOffice documents into a single file. The API allows you to append a document or documents, specified in the documentList parameter, to the original resource file. The changes are saved in the original resource document if the destFileName parameter is not specified. During documents append, we get an option to define which formatting will be used: appended or destination document. So the Possible values are KeepSourceFormatting or UseDestinationStyles.
Merge files using the cURL command
The cURL commands are the easiest way to perform Word document merge operation using RESTful APIs.
curl -X PUT "https://api.aspose.cloud/v4.0/words/Working%20with%20Header_Footer%20Objects.docx/appendDocument?destFileName=MergedFile.doc" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"DocumentEntries\":[{\"Href\":\"Another sample file.docx\",\"ImportFormatMode\":\"KeepSourceFormatting\"}],\"ApplyBaseDocumentHeadersAndFootersToAppendingDocuments\":true}"
Request URL
https://api.aspose.cloud/v4.0/words/Working%20with%20Header_Footer%20Objects.docx/appendDocument?destFileName=MergedFile.doc
Merge Word files using C#
C#.NET
string MyAppKey = "xxxxxxxx"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
string MyAppSid = "xxxxxxxxx"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/ | |
public class AppendaDocument | |
{ | |
public static void Run() | |
{ | |
WordsApi wordsApi = new WordsApi(MyAppKey,MyAppSid); | |
try | |
{ | |
string fileName = "Working with Header_Footer Objects.docx"; | |
string documentToAppend = "Another sample file.docx"; | |
// string folder = ""; // File exists at the root of the storage | |
string destName = "Out_Merged.docx"; // // Changes will be made in the source document | |
var body = new Aspose.Words.Cloud.Sdk.Model.DocumentEntryList(); | |
System.Collections.Generic.List<Aspose.Words.Cloud.Sdk.Model.DocumentEntry> docEntries = new System.Collections.Generic.List<Aspose.Words.Cloud.Sdk.Model.DocumentEntry>(); | |
Aspose.Words.Cloud.Sdk.Model.DocumentEntry docEntry = new Aspose.Words.Cloud.Sdk.Model.DocumentEntry { Href = documentToAppend, ImportFormatMode = "KeepSourceFormatting" }; | |
docEntries.Add(docEntry); | |
body.DocumentEntries = docEntries; | |
Aspose.Words.Cloud.Sdk.Model.Requests.AppendDocumentRequest request = new Aspose.Words.Cloud.Sdk.Model.Requests.AppendDocumentRequest(fileName, body, null, null,null,null, destName, null, null); | |
Aspose.Words.Cloud.Sdk.Model.DocumentResponse result = wordsApi.AppendDocument(request); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.ToString()); | |
} | |
} | |
} |
Recommended Articles
We also recommend visiting the following articles to learn more about: