xem trước bình luận trong tệp ms word

Trong lĩnh vực năng động của việc tạo tài liệu và cộng tác, khả năng thêm và quản lý bình luận trong Microsoft Word là điều không thể thiếu. Bình luận đóng vai trò như một diễn đàn thảo luận ảo, cho phép những người cộng tác trao đổi suy nghĩ, đề xuất cải tiến và cung cấp phản hồi mà không cần thay đổi nội dung gốc. Tính năng này không chỉ tạo điều kiện thuận lợi cho việc giao tiếp hiệu quả mà còn nâng cao quy trình chỉnh sửa cộng tác, giúp quy trình này trở nên hợp lý và hiệu quả hơn. Do đó, trong hướng dẫn này, chúng ta sẽ đi sâu vào các khía cạnh thiết yếu của việc thêm và xóa bình luận, khám phá tiềm năng và lợi ích của tính năng quan trọng này trong MS Word bằng cách sử dụng .NET REST API.

Quản lý bình luận bằng .NET REST API

Thao tác và thêm chú thích bằng Aspose.Words Cloud SDK for .NET mang lại nhiều lợi ích và nhiều khả năng vượt xa việc chỉ quản lý chú thích. Ngoài ra, SDK còn cung cấp nhiều khả năng khác bao gồm tạo tài liệu Word, chuyển đổi Word sang JPG, Word sang PDF, Word sang ODT, v.v., thao tác văn bản và định dạng, xử lý hình ảnh và nhiều tính năng khác, cho phép bạn nâng cao khả năng xử lý tài liệu của mình cho nhiều tình huống.

Nhận bình luận từ các tệp DOCX

Bạn có thể tận dụng để đọc tất cả hoặc các bình luận cụ thể từ tài liệu. Phương thức GetComments cung cấp khả năng đọc các bình luận của người dùng từ tệp DOCX. Được chỉ định bên dưới là lệnh cURL mà bạn có thể sử dụng để đọc các bình luận trên dấu nhắc lệnh.

lệnh cURL

Xin lưu ý rằng để đọc bình luận, bạn cần cung cấp thông tin chi tiết về tài liệu được lưu trữ trên lưu trữ đám mây, cũng như chỉ những người dùng được ủy quyền mới có quyền truy cập API. Do đó, trước tiên bạn cần lấy mã thông báo xác thực JWT và sử dụng nó trong lệnh như đã đề cập ở trên.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=xxxxxxx-1c8e-4ea4-a948-3857547232fa&client_secret=xxxxxx" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accpet: application/json"

Sau khi mã thông báo JWT được tạo, vui lòng thực hiện lệnh sau để lấy tất cả các bình luận trong tài liệu Word.

curl -v "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments" \
-X GET \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>"

Yêu cầu URL

https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments

C#.NET

Để đọc một bình luận cụ thể trong tài liệu, vui lòng làm theo các bước được chỉ định dưới đây:

  • Khởi tạo một thể hiện của lớp WordsApi.
  • Tạo một đối tượng của lớp GetCommentRequest trong đó chúng ta cung cấp tên tệp Volume 1.docx và giá trị chỉ mục bình luận làm đối số đầu vào.
  • Cuối cùng, khởi tạo đối tượng của CommentResponse trong khi truyền giá trị trả về từ phương thức GetComment(..).
const string clientID = "xxxxxxxxx";   // Get AppKey and AppSID from https://dashboard.aspose.cloud/
const string clientSecret = "xxxxxxxx";    // Get AppKey and AppSID from https://dashboard.aspose.cloud/

// khởi tạo và đối tượng của WordsApi
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);

// nhập tên tập tin
String filename= "Volume 1.docx";
// mục lục bình luận
int commentIndex = 0;
// create an object of GetCommentRequest where we pass nhập tên tập tin and comment index value
Aspose.Words.Cloud.Sdk.Model.Requests.GetCommentRequest request = new Aspose.Words.Cloud.Sdk.Model.Requests.GetCommentRequest(filename, commentIndex, null, null, null, null);
// tạo một thể hiện của CommentResponse và đọc bình luận từ tài liệu
Aspose.Words.Cloud.Sdk.Model.CommentResponse response = wordsApi.GetComment(request);
// hiển thị bình luận trong bảng điều khiển
Console.Write(response.Comment);

Nhận tất cả các bình luận

API cũng cung cấp tính năng để lấy tất cả các bình luận từ tài liệu (trong trường hợp chúng ta không muốn duyệt qua giữa các cá nhân).Đối với yêu cầu này, bạn cần tạo một thể hiện của các lớp GetCommentsRequest, CommentsResponse và gọi phương thức GetComments(..) của đối tượng WordsApi.

Chèn chú thích vào tài liệu Word

API cũng có khả năng thêm/chèn các đối tượng chú thích mới vào tài liệu Word.

lệnh cURL

curl -v "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments" \
-X POST \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"RangeStart\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/1/runs/0\",\"Rel\":\"self\",\"Type\":\"string\",\"Title\":\"Heading 2\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"RangeEnd\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/5/runs/0\",\"Rel\":\"self\",\"Type\":\"string\",\"Title\":\"Heading 2\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"Author\":\"Nayyer Shahbaz\",\"Initial\":\"MOU\",\"DateTime\":\"2020-12-07T04:10:03.942Z\",\"Text\":\"Comments Inserted using Aspose.Words Cloud API\"}"

C#.NET

const string clientID = "xxxxxxxxx";   // Get AppKey and AppSID from https://dashboard.aspose.cloud/
const string clientSecret = "xxxxxxxx";    // Get AppKey and AppSID from https://dashboard.aspose.cloud/

// khởi tạo và đối tượng của WordsApi
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);

// nhập tên tập tin
String filename = "Volume 1.docx";
// mục lục bình luận
int commentIndex = 0;

Aspose.Words.Cloud.Sdk.Model.NodeLink link = new Aspose.Words.Cloud.Sdk.Model.NodeLink()
{
    NodeId = "0.1.0.1.1.1.1"
};
Aspose.Words.Cloud.Sdk.Model.DocumentPosition documentPosition = new Aspose.Words.Cloud.Sdk.Model.DocumentPosition()
{
    Node = link,
    Offset = 0
};
Aspose.Words.Cloud.Sdk.Model.CommentInsert commentInsert = new Aspose.Words.Cloud.Sdk.Model.CommentInsert()
{
    Initial = "Aspose",
    Author = "Nayyer Shahbaz",
    RangeStart = documentPosition,
    RangeEnd = documentPosition,
    Text = "Comment added through API"
};


// create an object of GetCommentRequest where we pass nhập tên tập tin and comment index value
Aspose.Words.Cloud.Sdk.Model.Requests.InsertCommentRequest request = 
  new Aspose.Words.Cloud.Sdk.Model.Requests.InsertCommentRequest(filename, commentInsert, null, null, null);
// tạo một thể hiện của CommentResponse và đọc bình luận từ tài liệu
Aspose.Words.Cloud.Sdk.Model.CommentResponse response = wordsApi.InsertComment(request);
Chèn bản xem trước bình luận.

Hình ảnh 1:- xem trước bình luận mới được chèn

Cập nhật bình luận trong file Word

Ngoài việc phân tích cú pháp và thêm chú thích, API còn hỗ trợ tính năng cập nhật các chú thích hiện có bên trong tài liệu Word.

lệnh cURL

curl -X PUT "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments/1" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"RangeStart\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/1/runs/0\",\"Rel\":\"self\",\"Type\":\"string\",\"Title\":\"Heading 1\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"RangeEnd\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/1/runs/0\",\"Rel\":\"string\",\"Type\":\"string\",\"Title\":\"Heading 1\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"Author\":\"Nayyer Shahbaz\",\"Initial\":\"Aspose.Words\",\"DateTime\":\"2020-12-07T06:18:31.348Z\",\"Text\":\"Comments updated using Aspose.Words Cloud API\"}"

C#.NET

Để cập nhật bình luận trong tài liệu Word theo chương trình, vui lòng làm theo hướng dẫn bên dưới.

  • Tạo một thể hiện của lớp WordsApi.
  • Tạo một đối tượng NodeLink để định nghĩa chú thích NodeID.
  • Một đối tượng mới của lớp DocumentPosition được tạo ra để xác định giá trị RangeStart và RangeEnd.
  • Tạo một đối tượng CommentUpdate để xác định các thông tin chi tiết về Ký tự đầu, Tên tác giả, RangeStart và RangeEnd của bình luận bằng cách gán giá trị thể hiện DocumentPosition và văn bản cần cập nhật trong bình luận.
const string clientID = "xxxxxxxxx";   // Get AppKey and AppSID from https://dashboard.aspose.cloud/
const string clientSecret = "xxxxxxxx";    // Get AppKey and AppSID from https://dashboard.aspose.cloud/

// khởi tạo và đối tượng của WordsApi
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);

// nhập tên tập tin
String filename = "Volume 1.docx";
// mục lục bình luận
int commentIndex = 1;

Aspose.Words.Cloud.Sdk.Model.NodeLink link = new Aspose.Words.Cloud.Sdk.Model.NodeLink()
{
    NodeId = "0.1.0.1.1.1.1"
};
Aspose.Words.Cloud.Sdk.Model.DocumentPosition documentPosition = new Aspose.Words.Cloud.Sdk.Model.DocumentPosition()
{
    Node = link,
    Offset = 0
};
Aspose.Words.Cloud.Sdk.Model.CommentUpdate commentUpdate = new Aspose.Words.Cloud.Sdk.Model.CommentUpdate()
{
    Initial = "Aspose",
    Author = "Nayyer Shahbaz",
    RangeStart = documentPosition,
    RangeEnd = documentPosition,
    Text = "Comments updated using Aspose.Words Cloud API"
};

// create an object of GetCommentRequest where we pass nhập tên tập tin and comment index value
Aspose.Words.Cloud.Sdk.Model.Requests.UpdateCommentRequest request =
                    new Aspose.Words.Cloud.Sdk.Model.Requests.UpdateCommentRequest(filename, commentIndex, commentUpdate, null, null, null);
// tạo một thể hiện của CommentResponse và đọc bình luận từ tài liệu
Aspose.Words.Cloud.Sdk.Model.CommentResponse response = wordsApi.UpdateComment(request);
Cập nhật bản xem trước bình luận

Hình ảnh 2:- xem trước các bình luận đã cập nhật

Tài liệu kết quả Tập 1 - đã cập nhật.docx cũng được đính kèm.

Xóa bình luận khỏi tài liệu Word

Bạn cũng có thể xóa/gỡ bỏ các bình luận khỏi tệp Word bằng REST cloud API.

lệnh cURL

curl -X DELETE "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments/0" \
-H "accept: /" \
-H "Authorization: Bearer <JWT Token>"

C#.NET

  • Tạo một đối tượng của lớp WordsApi.
  • Tạo một phiên bản của lớp DeleteCommentRequest lấy một tệp đầu vào và chỉ mục của bình luận làm đối số.
  • Cuối cùng, phương thức DeleteComment(…) có đối tượng DeleteCommentRequest làm đối số.
const string clientID = "xxxxxxxxx";   // Get AppKey and AppSID from https://dashboard.aspose.cloud/
const string clientSecret = "xxxxxxxx";    // Get AppKey and AppSID from https://dashboard.aspose.cloud/

// khởi tạo và đối tượng của WordsApi
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);

// nhập tên tập tin
String filename = "Volume 1.docx";
// mục lục bình luận
int commentIndex = 0;


Aspose.Words.Cloud.Sdk.Model.Requests.DeleteCommentRequest request = 
  new Aspose.Words.Cloud.Sdk.Model.Requests.DeleteCommentRequest(filename, commentIndex, null, null, null, null, null, null, null);
wordsApi.DeleteComment(request);
Xem trước bình luận đã xóa

Hình ảnh 3:- xem trước các bình luận đã xóa