合併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 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());
        }
    }
}

推薦文章

我們還建議您訪問以下文章以了解更多資訊: