
MS Word ファイルは、データ処理や情報共有によく使われるオフィス ファイル形式です。組織では複数のリソースが働いており、毎日多数のドキュメントを作成しています。データ アーカイブでは、地理的に離れた場所にある複数のチームによって作成されたドキュメントを結合する必要に迫られることがあります。この記事では、REST API を使用して複数の Word ファイルを 1 つの結果出力に結合する手順について説明します。
ワードプロセッシングREST API
Word ドキュメントにはさまざまな形式があり、この要件を満たすために、Aspose.Words Cloud はさまざまな MS Word および OpenOffice ドキュメントを 1 つのファイルに結合できる機能を提供します。API を使用すると、documentList パラメーターで指定された 1 つまたは複数のドキュメントを元のリソース ファイルに追加できます。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());
}
}
}
おすすめの記事
詳細については、以下の記事も参照することをお勧めします。