
문서 생성 및 협업의 역동적인 영역에서 Microsoft Word에서 주석을 추가하고 관리하는 기능은 필수적입니다. 주석은 가상 토론 게시판 역할을 하여 공동 작업자가 생각을 교환하고, 개선 사항을 제안하고, 원본 콘텐츠를 변경하지 않고도 피드백을 제공할 수 있습니다. 이 기능은 효과적인 커뮤니케이션을 용이하게 할 뿐만 아니라 협업 편집 프로세스를 개선하여 보다 간소화되고 효율적으로 만들어줍니다. 따라서 이 가이드에서는 주석을 추가하고 삭제하는 데 있어 필수적인 측면을 살펴보고 .NET REST API를 사용하여 MS Word에서 이 중요한 기능의 잠재력과 이점을 밝혀보겠습니다.
.NET REST API를 사용하여 댓글 관리
Aspose.Words Cloud SDK for .NET을 사용하여 주석을 조작하고 추가하면 주석 관리 외에도 많은 이점과 광범위한 기능을 제공합니다. 이 외에도 SDK는 Word 문서 생성, Word에서 JPG, Word에서 PDF, Word에서 ODT 등으로 변환, 텍스트 및 서식 조작, 이미지 처리 및 광범위한 기능을 포함하여 광범위한 기능을 제공하여 다양한 시나리오에 대한 문서 처리 기능을 향상시킬 수 있습니다.
DOCX 파일에서 주석 가져오기
문서에서 모든 주석이나 특정 주석을 읽을 수 있습니다. GetComments 메서드는 DOCX 파일에서 사용자 주석을 읽을 수 있는 기능을 제공합니다. 아래에 지정된 것은 명령 프롬프트에서 주석을 읽는 데 사용할 수 있는 cURL 명령입니다.
cURL 명령
댓글을 읽으려면 클라우드 스토리지에 저장된 문서에 대한 세부 정보를 제공해야 하며, 권한이 있는 사용자만 API에 액세스할 수 있는 권한을 얻습니다. 따라서 먼저 JWT 인증 토큰을 검색하여 위에서 언급한 대로 명령에 사용해야 합니다.
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"
JWT 토큰이 생성되면 다음 명령을 실행하여 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>"
요청 URL
https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments
C#.NET
문서에서 특정 주석을 읽으려면 아래 단계를 따르세요.
- WordsApi 클래스의 인스턴스를 초기화합니다.
- 입력 인수로 Volume 1.docx 파일 이름과 주석 인덱스 값을 제공하는 GetCommentRequest 클래스의 객체를 생성합니다.
- 마지막으로 GetComment(..) 메서드에서 반환된 값을 전달하면서 CommentResponse 객체를 초기화합니다.
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/
// WordsApi의 초기화 및 객체
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);
// 입력 파일 이름
String filename= "Volume 1.docx";
// 댓글 인덱스
int commentIndex = 0;
// create an object of GetCommentRequest where we pass 입력 파일 이름 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);
// CommentResponse 인스턴스를 생성하고 문서에서 주석을 읽습니다.
Aspose.Words.Cloud.Sdk.Model.CommentResponse response = wordsApi.GetComment(request);
// 콘솔에 주석을 표시하세요
Console.Write(response.Comment);
모든 댓글을 받으세요
API는 또한 문서에서 모든 주석을 가져오는 기능을 제공합니다(개인 간을 이동하고 싶지 않은 경우).이 요구 사항의 경우 GetCommentsRequest, CommentsResponse 클래스의 인스턴스를 만들고 WordsApi 객체의 GetComments(..) 메서드를 호출해야 합니다.
Word 문서에 주석 삽입
API를 사용하면 Word 문서에 새로운 주석 객체를 추가/삽입할 수도 있습니다.
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/
// WordsApi의 초기화 및 객체
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);
// 입력 파일 이름
String filename = "Volume 1.docx";
// 댓글 인덱스
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 입력 파일 이름 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);
// CommentResponse 인스턴스를 생성하고 문서에서 주석을 읽습니다.
Aspose.Words.Cloud.Sdk.Model.CommentResponse response = wordsApi.InsertComment(request);

이미지 1:- 새로 삽입된 주석 미리보기
Word 파일에 주석 업데이트
API는 주석을 구문 분석하고 추가하는 것 외에도 Word 문서 내의 기존 주석을 업데이트하는 기능도 지원합니다.
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
Word 문서의 주석을 프로그래밍 방식으로 업데이트하려면 아래에 지정된 지침을 따르세요.
- WordsApi 클래스의 인스턴스를 생성합니다.
- 댓글 NodeID를 정의하는 NodeLink 객체를 생성합니다.
- RangeStart 및 RangeEnd 값을 정의하는 DocumentPosition 클래스의 새 객체가 생성됩니다.
- DocumentPosition 인스턴스 값과 댓글에 업데이트될 텍스트를 할당하여 댓글의 이니셜, 작성자 이름, RangeStart 및 RangeEnd 세부 정보를 정의하는 CommentUpdate 객체를 생성합니다.
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/
// WordsApi의 초기화 및 객체
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);
// 입력 파일 이름
String filename = "Volume 1.docx";
// 댓글 인덱스
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 입력 파일 이름 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);
// CommentResponse 인스턴스를 생성하고 문서에서 주석을 읽습니다.
Aspose.Words.Cloud.Sdk.Model.CommentResponse response = wordsApi.UpdateComment(request);

이미지 2:- 업데이트된 댓글 미리보기
결과 문서Volume 1 - updated.docx도 첨부되어 있습니다.
Word 문서에서 주석 삭제
REST 클라우드 API를 사용하여 Word 파일에서 주석을 제거/삭제할 수도 있습니다.
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
- WordsApi 클래스의 객체를 생성합니다.
- 입력 파일과 댓글 인덱스를 인수로 받는 DeleteCommentRequest 클래스의 인스턴스를 생성합니다.
- 마지막으로 DeleteCommentRequest 객체를 인수로 갖는 DeleteComment(…) 메서드.
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/
// WordsApi의 초기화 및 객체
Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(clientID, clientSecret);
// 입력 파일 이름
String filename = "Volume 1.docx";
// 댓글 인덱스
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);

이미지 3:- 삭제된 댓글 미리보기