
Tệp MS Word là định dạng tệp văn phòng phổ biến để xử lý dữ liệu và chia sẻ thông tin. Nhiều nguồn lực làm việc trong các tổ chức và tạo ra nhiều tài liệu hàng ngày và đối với kho lưu trữ dữ liệu, chúng ta có thể gặp phải yêu cầu hợp nhất các tài liệu do nhiều nhóm ở các vị trí địa lý xa nhau tạo ra. Trong bài viết này, chúng ta sẽ thảo luận về các bước về cách kết hợp nhiều tệp Word thành một đầu ra kết quả duy nhất bằng REST API.
API REST xử lý văn bản
Các tài liệu Word có nhiều định dạng khác nhau và để đáp ứng yêu cầu này, Aspose.Words Cloud cung cấp khả năng kết hợp nhiều tài liệu MS Word và OpenOffice thành một tệp duy nhất. API cho phép bạn thêm một tài liệu hoặc nhiều tài liệu, được chỉ định trong tham số documentList, vào tệp tài nguyên gốc. Các thay đổi được lưu trong tài liệu tài nguyên gốc nếu tham số destFileName không được chỉ định. Trong quá trình thêm tài liệu, chúng ta có tùy chọn để xác định định dạng nào sẽ được sử dụng: tài liệu được thêm vào hoặc tài liệu đích. Vì vậy, các giá trị có thể là KeepSourceFormatting hoặc UseDestinationStyles.
Hợp nhất các tập tin bằng lệnh cURL
Lệnh cURL là cách dễ nhất để thực hiện thao tác hợp nhất tài liệu Word bằng API RESTful.
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}"
Yêu cầu URL
https://api.aspose.cloud/v4.0/words/Working%20with%20Header_Footer%20Objects.docx/appendDocument?destFileName=MergedFile.doc
Ghép các tập tin Word bằng 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 tồn tại ở thư mục gốc của bộ nhớ
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());
}
}
}
Bài viết được đề xuất
Chúng tôi cũng khuyên bạn nên truy cập các bài viết sau để tìm hiểu thêm về: