วิธีใส่ความคิดเห็นลงใน DOCX โดยใช้ C++

ในบทช่วยสอนนี้ เราจะเรียนรู้วิธีแทรกความคิดเห็นลงใน DOCX โดยใช้ C++ ความคิดเห็นมีประโยชน์สำหรับการตรวจสอบเอกสาร Word พวกเขาไม่ได้เปลี่ยนแปลงตัวเอกสาร แต่ผู้เขียนใช้เพื่อหารือหรือแสดงความคิดเห็นเกี่ยวกับส่วนใด ๆ ของเอกสาร Word

ขั้นตอนในการเพิ่มความคิดเห็นใน DOCX โดยใช้ C++

  1. ติดตั้งแพ็คเกจ Aspose.Words.Cpp NuGet
  2. รวมการอ้างอิงถึงเนมสเปซ Aspose::Words
  3. สร้างอินสแตนซ์ของ Document Class เพื่อโหลด DOCX เพื่อเพิ่มความคิดเห็น
  4. สร้างอินสแตนซ์ Comment Class วัตถุเพื่อเพิ่มความคิดเห็นใน DOCX โดยใช้ C++
  5. บันทึกไฟล์ Word ด้วยความคิดเห็นใน C ++ โดยใช้วิธีบันทึก

ในโค้ดต่อไปนี้ เราได้แสดงให้เห็นว่าคุณสามารถรวมความคิดเห็นในไฟล์ DOC ได้ง่ายเพียงใดโดยใช้ C++ โดยไม่ต้องพึ่งพา Microsoft Word หรือ Office Interop API คุณสามารถใช้ SaveFormat เพื่อบันทึกเอกสารในรูปแบบ DOCX หรือ DOC

รหัสเพื่อเพิ่มความคิดเห็นใน DOCX โดยใช้ C ++

#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");
}
};

ในตัวอย่างก่อนหน้านี้ เราเห็น วิธีแปลง HTML เป็น PDF โดยใช้ C++ ในหัวข้อนี้ เราได้อธิบายวิธีการแทรกความคิดเห็นใน DOCX โดยใช้ C++ โดยใช้โค้ดไม่กี่บรรทัด

 ไทย