ติดตามการเปลี่ยนแปลงในเอกสาร
ฟังก์ชันการทำงานของการเปลี่ยนแปลงแทร็กหรือที่เรียกว่าการตรวจทานช่วยให้คุณสามา คุณลักษณะการเปลี่ยนแปลงแทร็คนี้ด้วยAspose.Wordsรองรับการเปลี่ยนแปลงแทร็คในMicrosoft Word ด้วยฟังก์ชันการทำงานนี้คุณสามารถเข้าถึงการแก้ไขแต่ละรายการในเอกสารของคุณและ.
เมื่อคุณเปิดใช้งานคุณลักษณะการเปลี่ยนแปลงแทร็กองค์ประกอบทั้งหมดที่แทรกลบและแก้ไข วัตถุที่นำข้อมูลเกี่ยวกับสิ่งที่เปลี่ยนแปลงจะเรียกว่า"การติดตามการเปลี่ยนแปลง" ตัวอย่างเช่นสมมติว่าคุณต้องการตรวจสอบเอกสารและทำการเปลี่ยนแปลงที่สำคัญ-นี้อาจ นอกจากนี้คุณอาจต้องแทรกความคิดเห็นเพื่อหารือเกี่ยวกับการเปลี่ยนแปลงบางอย่าง นั่นคือที่ที่การติดตามการเปลี่ยนแปลงในเอกสารมาใน.
บทความนี้อธิบายถึงวิธีจัดการและติดตามการเปลี่ยนแปลงที่สร้างขึ้นโดยผู้ตรวจทานจำนว.
การแก้ไขคืออะไร
ก่อนที่จะดำน้ำในการแก้ไขขออธิบายความหมายของการแก้ไข revisionคือการเปลี่ยนแปลงที่เกิดขึ้นในโหนดหนึ่งของเอกสารในขณะที่กลุ่มการแก้ไขแสดงโดยRevisionGroupคื การแก้ไขเป็นเครื่องมือสำหรับการติดตามการเปลี่ยนแปลง.
การแก้ไขจะใช้ในคุณลักษณะการเปลี่ยนแปลงการติดตามและภายในคุณลักษณะเปรียบเทีย ดังนั้นการแก้ไขภายในคุณลักษณะการเปลี่ยนแปลงการติดตามจะแสดงโดยใครและสิ่งที่ได้.
Aspose.Wordsรองรับประเภทการแก้ไขที่แตกต่างกันเช่นเดียวกับในMicrosoft Wordเช่นการแทรกการลบFormatChange,StyleDefinitionChangeและการย้าย ประเภทการแก้ไขทั้งหมดจะแสดงด้วยการแจงนับRevisionType.
เริ่มและหยุดการติดตามการเปลี่ยนแปลง
การแก้ไขเอกสารมักจะไม่นับเป็นการแก้ไขจนกว่าคุณจะเริ่มติดตาม Aspose.Wordsช่วยให้คุณสามารถติดตามการเปลี่ยนแปลงทั้งหมดในเอกสารของคุณโดยอัตโนมัติด้วยขั้น คุณสามารถเริ่มกระบวนการติดตามการเปลี่ยนแปลงได้โดยใช้วิธีการStartTrackRevisions การแก้ไขในอนาคตไม่ได้รับการพิจารณาการแก้ไขคุณจะต้องใช้วิธีการStopTrackRevisions.
StartTrackingRevisions
จะไม่เปลี่ยนสถานะของคุณสมบัติTrackRevisionsและไม่ได้ใช้ค่าของมันเพื่อจุดมุ่งหม นอกจากนี้หากโหนดถูกย้ายจากตำแหน่งหนึ่งไปยังอีกตำแหน่งหนึ่งภายในเอกสารที่ติดตาม.
ในตอนท้ายของกระบวนการการติดตามการเปลี่ยนแปลงในเอกสารของคุณ,คุณจะมีความส นี้สามารถทำได้โดยใช้วิธีการAcceptAllRevisionsหรือRejectAll นอกจากนี้คุณสามารถยอมรับหรือปฏิเสธการแก้ไขแต่ละครั้งแยกกันได้โดยใช้วิธีการAcceptหรือReject.
การเปลี่ยนแปลงทั้งหมดจะได้รับการติดตามสำหรับหนึ่งซ้ำจากช่วงเวลาที่คุณเริ่มต้นกระบ การเชื่อมต่อระหว่างการทำซ้ำที่แตกต่างกันจะแสดงเป็นสถานการณ์สมมติต่อไปนี้:คุณทำกระ ด้วยสถานการณ์สมมตินี้การเปลี่ยนแปลงทั้งหมดที่คุณไม่ยอมรับหรือปฏิเสธจะปรากฏขึ้นอีกค.
AcceptAllRevisions
คล้ายกับ"ยอมรับการเปลี่ยนแปลงทั้งหมด"ในMicrosoft Word.
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการทำงานกับการเปลี่ยนแปลงการติดตาม:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
auto doc = System::MakeObject<Document>(); | |
System::SharedPtr<Body> body = doc->get_FirstSection()->get_Body(); | |
System::SharedPtr<Paragraph> para = body->get_FirstParagraph(); | |
// Add text to the first paragraph, then add two more paragraphs. | |
para->AppendChild(System::MakeObject<Run>(doc, u"Paragraph 1. ")); | |
body->AppendParagraph(u"Paragraph 2. "); | |
body->AppendParagraph(u"Paragraph 3. "); | |
// We have three paragraphs, none of which registered as any type of revision | |
// If we add/remove any content in the document while tracking revisions, | |
// they will be displayed as such in the document and can be accepted/rejected. | |
doc->StartTrackRevisions(u"John Doe", System::DateTime::get_Now()); | |
// This paragraph is a revision and will have the according "IsInsertRevision" flag set. | |
para = body->AppendParagraph(u"Paragraph 4. "); | |
ASSERT_TRUE(para->get_IsInsertRevision()); | |
// Get the document's paragraph collection and remove a paragraph. | |
System::SharedPtr<ParagraphCollection> paragraphs = body->get_Paragraphs(); | |
ASSERT_EQ(4, paragraphs->get_Count()); | |
para = paragraphs->idx_get(2); | |
para->Remove(); | |
// Since we are tracking revisions, the paragraph still exists in the document, will have the "IsDeleteRevision" set | |
// and will be displayed as a revision in Microsoft Word, until we accept or reject all revisions. | |
ASSERT_EQ(4, paragraphs->get_Count()); | |
ASSERT_TRUE(para->get_IsDeleteRevision()); | |
// The delete revision paragraph is removed once we accept changes. | |
doc->AcceptAllRevisions(); | |
ASSERT_EQ(3, paragraphs->get_Count()); | |
ASSERT_EQ(0, para->get_Count()); | |
// Stopping the tracking of revisions makes this text appear as normal text. | |
// Revisions are not counted when the document is changed. | |
doc->StopTrackRevisions(); | |
System::String outputPath = outputDataDir + u"WorkingWithRevisions.AcceptRevisions.doc"; | |
doc->Save(outputPath); |
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีสร้างการแก้ไขเมื่อโหนดถูกย้ายภายในเอกสารที่ติดตาม:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
auto doc = System::MakeObject<Document>(); | |
auto builder = System::MakeObject<DocumentBuilder>(doc); | |
builder->Writeln(u"Paragraph 1"); | |
builder->Writeln(u"Paragraph 2"); | |
builder->Writeln(u"Paragraph 3"); | |
builder->Writeln(u"Paragraph 4"); | |
builder->Writeln(u"Paragraph 5"); | |
builder->Writeln(u"Paragraph 6"); | |
System::SharedPtr<Body> body = doc->get_FirstSection()->get_Body(); | |
std::cout << "Paragraph count: " << body->get_Paragraphs()->get_Count() << std::endl; | |
// Start tracking revisions. | |
doc->StartTrackRevisions(u"Author", System::DateTime(2020, 12, 23, 14, 0, 0)); | |
// Generate revisions when moving a node from one location to another. | |
System::SharedPtr<Node> node = body->get_Paragraphs()->idx_get(3); | |
System::SharedPtr<Node> endNode = body->get_Paragraphs()->idx_get(5)->get_NextSibling(); | |
System::SharedPtr<Node> referenceNode = body->get_Paragraphs()->idx_get(0); | |
while (node != endNode) | |
{ | |
System::SharedPtr<Node> nextNode = node->get_NextSibling(); | |
body->InsertBefore(node, referenceNode); | |
node = nextNode; | |
} | |
// Stop the process of tracking revisions. | |
doc->StopTrackRevisions(); | |
// There are 3 additional paragraphs in the move-from range. | |
std::cout << "Paragraph count: " << body->get_Paragraphs()->get_Count() << std::endl; | |
System::String outputPath = outputDataDir + u"WorkingWithRevisions.MoveNodeInTrackedDocument.pdf"; | |
doc->Save(outputPath); |
จัดการและจัดเก็บการเปลี่ยนแปลงเป็นการแก้ไข
ด้วยคุณลักษณะการเปลี่ยนแปลงการติดตามก่อนหน้านี้คุณสามารถเข้าใจว่ามีการเปลี่ยนแป ในขณะที่มีคุณลักษณะTrackRevisionsคุณบังคับให้มีการเปลี่ยนแปลงใดๆในเอกสารของคุณจะถูกเก็บไว้เป็นก.
Aspose.Wordsช่วยให้คุณสามารถตรวจสอบว่าเอกสารมีการแก้ไขหรือไม่โดยใช้คุณสมบัติHasRevision หากคุณไม่จำเป็นต้องติดตามการเปลี่ยนแปลงในเอกสารของคุณโดยอัตโนมัติผ่านวิธีการStartTrackRevisionsและStopTrackRevisionsคุณสามารถใช้คุณสมบัติTrackRevisions
เพื่อตรวจสอบว่ามีการติดตามการเปลี่ยนแปลงขณะแก้ไขเอกสารในMicrosoft Wordและจัดเก็บเป็นการแก้ไขหรือไม่.
คุณลักษณะTrackRevisions
ทำการแก้ไขแทนการเปลี่ยนแปลงจริงDOM แต่การแก้ไขตัวเองแยกกัน ตัวอย่างเช่นถ้าคุณลบย่อหน้าใดๆให้เป็นAspose.Wordsแก้ไขให้ทำเครื่องหมายว่าเป็นลบแทนที่จะลบย่อหน้า.
นอกจากนี้Aspose.Wordsช่วยให้คุณสามารถตรวจสอบว่าวัตถุถูกแทรก,ลบ,หรือเปลี่ยนรูปแบบโดยใช้การIsDeleteRevision, IsFormatRevision, IsInsertRevision, IsMoveFromRevision, และคุณสมบัติIsMoveToRevision.
TrackRevisions
นอกจากนี้คุณสามารถยอมรับ/ปฏิเสธการแก้ไขได้โดยไม่คำนึงถึงคุณลักษณะการเปลี่ยนแป.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการใช้คุณสมบัติที่แตกต่างกันกับการแก้ไข:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
auto doc = System::MakeObject<Document>(); | |
// Insert an inline shape without tracking revisions. | |
ASSERT_FALSE(doc->get_TrackRevisions()); | |
auto shape = System::MakeObject<Shape>(doc, ShapeType::Cube); | |
shape->set_WrapType(WrapType::Inline); | |
shape->set_Width(100.0); | |
shape->set_Height(100.0); | |
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(shape); | |
// Start tracking revisions and then insert another shape. | |
doc->StartTrackRevisions(u"John Doe"); | |
shape = System::MakeObject<Shape>(doc, ShapeType::Sun); | |
shape->set_WrapType(WrapType::Inline); | |
shape->set_Width(100.0); | |
shape->set_Height(100.0); | |
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(shape); | |
// Get the document's shape collection which includes just the two shapes we added. | |
auto shapes = doc->GetChildNodes(NodeType::Shape, true)->LINQ_Cast<System::SharedPtr<Shape>>()->LINQ_ToList(); | |
ASSERT_EQ(2, shapes->get_Count()); | |
// Remove the first shape. | |
shapes->idx_get(0)->Remove(); | |
// Because we removed that shape while changes were being tracked, the shape counts as a delete revision. | |
ASSERT_EQ(ShapeType::Cube, shapes->idx_get(0)->get_ShapeType()); | |
ASSERT_TRUE(shapes->idx_get(0)->get_IsDeleteRevision()); | |
// And we inserted another shape while tracking changes, so that shape will count as an insert revision. | |
ASSERT_EQ(ShapeType::Sun, shapes->idx_get(1)->get_ShapeType()); | |
ASSERT_TRUE(shapes->idx_get(1)->get_IsInsertRevision()); | |
// The document has one shape that was moved, but shape move revisions will have two instances of that shape. | |
// One will be the shape at its arrival destination and the other will be the shape at its original location. | |
doc = System::MakeObject<Document>(inputDataDir + u"Revision shape.docx"); | |
shapes = doc->GetChildNodes(NodeType::Shape, true)->LINQ_Cast<System::SharedPtr<Shape>>()->LINQ_ToList(); | |
ASSERT_EQ(4, shapes->get_Count()); | |
// This is the move to revision, also the shape at its arrival destination. | |
ASSERT_FALSE(shapes->idx_get(0)->get_IsMoveFromRevision()); | |
ASSERT_TRUE(shapes->idx_get(0)->get_IsMoveToRevision()); | |
// This is the move from revision, which is the shape at its original location. | |
ASSERT_TRUE(shapes->idx_get(1)->get_IsMoveFromRevision()); | |
ASSERT_FALSE(shapes->idx_get(1)->get_IsMoveToRevision()); |