C++를 사용하여 DOCX에 주석을 삽입하는 방법

이 튜토리얼에서는 C++를 사용하여 DOCX에 주석을 삽입하는 방법을 배웁니다. 주석은 Word 문서를 검토하는 데 유용합니다. 그들은 문서 자체를 변경하지 않지만 작성자가 Word 문서의 모든 섹션에 대해 토론하거나 의견을 제시하는 데 사용합니다.

C++를 사용하여 DOCX에 주석을 추가하는 단계

  1. Aspose.Words.Cpp NuGet 패키지 설치
  2. Aspose::Words 네임스페이스에 대한 참조 포함
  3. 댓글을 추가하기 위해 DOCX를 로드하려면 Document Class의 인스턴스를 만드세요.
  4. C++를 사용하여 DOCX에 주석을 추가하려면 Comment Class 개체를 인스턴스화하세요.
  5. Save 메서드를 사용하여 C++에서 주석과 함께 Word 파일 저장

다음 코드에서는 Microsoft Word 또는 Office Interop API에 의존하지 않고 C++를 사용하여 DOC 파일에 주석을 얼마나 쉽게 포함할 수 있는지 보여주었습니다. SaveFormat를 사용하여 문서를 DOCX 또는 DOC 형식으로 저장할 수 있습니다.

C++를 사용하여 DOCX에 주석을 추가하는 코드

#pragma once
#include <cstdint>
#include <iostream>
#include <Aspose.Words.Cpp/Body.h>
#include <Aspose.Words.Cpp/Comment.h>
#include <Aspose.Words.Cpp/CommentCollection.h>
#include <Aspose.Words.Cpp/CommentRangeEnd.h>
#include <Aspose.Words.Cpp/CommentRangeStart.h>
#include <Aspose.Words.Cpp/CompositeNode.h>
#include <Aspose.Words.Cpp/Document.h>
#include <Aspose.Words.Cpp/DocumentBuilder.h>
#include <Aspose.Words.Cpp/Node.h>
#include <Aspose.Words.Cpp/NodeCollection.h>
#include <Aspose.Words.Cpp/NodeType.h>
#include <Aspose.Words.Cpp/Paragraph.h>
#include <Aspose.Words.Cpp/ParagraphCollection.h>
#include <Aspose.Words.Cpp/Run.h>
#include <Aspose.Words.Cpp/RunCollection.h>
#include <Aspose.Words.Cpp/SaveFormat.h>
#include <Aspose.Words.Cpp/Saving/SaveOutputParameters.h>
#include <Aspose.Words.Cpp/Section.h>
#include <system/collections/list.h>
#include <system/convert.h>
#include <system/date_time.h>
#include <system/enumerator_adapter.h>
#include <system/exceptions.h>
using System::ArrayPtr;
using System::MakeArray;
using System::MakeObject;
using System::SharedPtr;
using System::String;
using namespace Aspose::Words;
class WorkingWithCommentsinCPP
{
public:
void AddComments()
{
// Create an instance of Document class of Aspose.Words for C++
// to add a blank Word document
SharedPtr<Document> WordDocumentUsingCPP = MakeObject<Document>();
// Instantiate DocumentBuilder class to add content to the Word Document
SharedPtr<DocumentBuilder> WordDocumentBuilder = MakeObject<DocumentBuilder>(WordDocumentUsingCPP);
// Add some text
WordDocumentBuilder->Write(u"Some text is added.");
// Add comment class object to add comment
SharedPtr<Comment> comment = MakeObject<Comment>(WordDocumentUsingCPP, u"Test Author", u"TA",
System::DateTime::get_Today());
// Append comment to current paragraph of document
WordDocumentBuilder->get_CurrentParagraph()->AppendChild(comment);
// Add Comment
comment->get_Paragraphs()->Add(MakeObject<Paragraph>(WordDocumentUsingCPP));
comment->get_FirstParagraph()->get_Runs()->Add(MakeObject<Run>(WordDocumentUsingCPP, u"Comment text."));
// Save the word document with comments to docx format
WordDocumentUsingCPP->Save(u"WorkingWithComments.AddComments.docx");
}
};

이전 예에서 C++를 사용하여 HTML을 PDF로 변환하는 방법을(를) 보았습니다. 이 항목에서는 몇 줄의 코드를 사용하여 C++를 사용하여 DOCX에 주석을 삽입하는 방법을 설명했습니다.

 한국인