合并word文档

MS Word 文件是用于数据处理和信息共享的流行办公文件格式。组织中有多种资源,每天生成大量文档,对于数据存档,我们可能会遇到合并位于遥远地理位置的多个团队生成的文档的需求。在本文中,我们将讨论如何使用 REST API 将多个 Word 文件合并为单个结果输出的步骤。

文字处理 REST API

Word 文档具有多种格式,为了满足这一要求,Aspose.Words Cloud 提供了将各种 MS Word 和 OpenOffice 文档合并为单个文件的功能。API 允许您将 documentList 参数中指定的一个或多个文档附加到原始资源文件。如果未指定 destFileName 参数,则更改将保存在原始资源文档中。在文档附加期间,我们可以选择定义将使用哪种格式:附加或目标文档。因此,可能的值是 KeepSourceFormatting 或 UseDestinationStyles。

使用 cURL 命令合并文件

cURL 命令是使用 RESTful API 执行 Word 文档合并操作的最简单方法。

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}"

请求 URL

https://api.aspose.cloud/v4.0/words/Working%20with%20Header_Footer%20Objects.docx/appendDocument?destFileName=MergedFile.doc

使用 C# 合并 Word 文件

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 = ""; // 文件存在于存储的根目录中
            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());
        }
    }
}

推荐文章

我们还建议您访问以下文章以了解更多信息: