تتبع التغييرات في المستند

تتيح لك وظيفة تتبع التغييرات، والمعروفة أيضا باسم المراجعة، تتبع التغييرات في المحتوى والتنسيق التي أجريتها أنت أو المستخدمون الآخرون. هذه الميزة تتبع التغييرات مع Aspose.Words يدعم تتبع التغييرات في Microsoft Word. باستخدام هذه الوظيفة، يمكنك الوصول إلى المراجعات الفردية في المستند وتطبيق خصائص مختلفة عليها.

عند تمكين ميزة تتبع التغييرات، سيتم تمييز جميع عناصر المستند المدرجة والمحذوفة والمعدلة بصريا بمعلومات حول من ومتى وما تم تغييره. تسمى الكائنات التي تحمل معلومات حول ما تم تغييره “تتبع التغييرات”. على سبيل المثال، افترض أنك تريد مراجعة مستند وإجراء تغييرات مهمة – قد يعني هذا أنك بحاجة إلى إجراء مراجعات. أيضا، قد تحتاج إلى إدراج تعليقات لمناقشة بعض التغييرات. هذا هو المكان الذي يأتي فيه تتبع التغييرات في المستندات.

تشرح هذه المقالة كيفية إدارة وتتبع التغييرات التي أنشأها العديد من المراجعين على نفس المستند، بالإضافة إلى خصائص تتبع التغييرات.

ما هي المراجعة

قبل الغوص في المراجعات، دعنا نشرح معنى المراجعات. revision هو تغيير يحدث في عقدة واحدة من المستند بينما مجموعة المراجعة، ممثلة في فئة RevisionGroup، هي مجموعة من المراجعات المتسلسلة التي تحدث في العديد من عقد المستند. المراجعة هي أداة لتتبع التغييرات.

تستخدم المراجعات في ميزة تتبع التغييرات وضمن ميزة مقارنة المستندات، حيث تظهر المراجعات كنتيجة للمقارنة. لذلك، تظهر المراجعات داخل ميزة تتبع التغييرات من قبل من وما تم تغييره.

Aspose.Words يدعم أنواع المراجعة المختلفة، وكذلك في Microsoft Word، مثل الإدراج والحذف و FormatChange و StyleDefinitionChange والتحرك. يتم تمثيل جميع أنواع المراجعة مع RevisionType تعداد.

بدء وإيقاف تتبع التغييرات

عادة لا يتم احتساب تحرير المستند كمراجعة حتى تبدأ في تتبعه. Aspose.Words يسمح لك بتتبع جميع التغييرات في المستند تلقائيا بخطوات بسيطة. يمكنك بسهولة بدء عملية تتبع التغييرات باستخدام طريقة StartTrackRevisions. إذا كنت بحاجة إلى إيقاف عملية تتبع التغييرات بحيث لا تعتبر أي تعديلات مستقبلية مراجعات، فستحتاج إلى استخدام طريقة StopTrackRevisions.

في نهاية عملية تتبع التغييرات في المستند، سيكون لديك القدرة على قبول جميع المراجعات أو رفضها لإعادة المستند إلى شكله الأصلي. يمكن تحقيق ذلك إما باستخدام طريقة AcceptAllRevisions أو RejectAll. بالإضافة إلى ذلك، يمكنك قبول أو رفض كل مراجعة على حدة باستخدام طريقة Accept أو Reject.

سيتم تتبع جميع التغييرات لتكرار واحد من اللحظة التي تبدأ فيها العملية إلى اللحظة التي توقفها فيها. يتم تمثيل الاتصال بين التكرارات المختلفة على النحو التالي: إكمال عملية التتبع، ثم إجراء بعض التغييرات، وبدء تتبع التغييرات مرة أخرى. باستخدام هذا السيناريو، سيتم عرض جميع التغييرات التي لم تقبلها أو ترفضها مرة أخرى.

يوضح مثال التعليمات البرمجية التالية كيفية العمل مع تتبع التغييرات:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
Document doc = new Document();
Body body = doc.getFirstSection().getBody();
Paragraph para = body.getFirstParagraph();
// Add text to the first paragraph, then add two more paragraphs.
para.appendChild(new Run(doc, "Paragraph 1. "));
body.appendParagraph("Paragraph 2. ");
body.appendParagraph("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("John Doe", new Date());
// This paragraph is a revision and will have the according "IsInsertRevision" flag set.
para = body.appendParagraph("Paragraph 4. ");
if(para.isInsertRevision())
System.out.println("isInsertRevision:" + para.isInsertRevision());
// Get the document's paragraph collection and remove a paragraph.
ParagraphCollection paragraphs = body.getParagraphs();
if(4 == paragraphs.getCount())
System.out.println("count:" + paragraphs.getCount());
para = paragraphs.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.
if(4 == paragraphs.getCount())
System.out.println("count:" + paragraphs.getCount());
if(para.isDeleteRevision())
System.out.println("isDeleteRevision:" + para.isDeleteRevision());
// The delete revision paragraph is removed once we accept changes.
doc.acceptAllRevisions();
if(3 == paragraphs.getCount())
System.out.println("count:" + paragraphs.getCount());
// Stopping the tracking of revisions makes this text appear as normal text.
// Revisions are not counted when the document is changed.
doc.stopTrackRevisions();
// Save the document.
doc.save(dataDir + "Document.Revisions.docx");

يوضح مثال التعليمات البرمجية التالي كيفية إنشاء المراجعات عند نقل عقدة داخل مستند متعقب:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Generate document contents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Paragraph 1");
builder.writeln("Paragraph 2");
builder.writeln("Paragraph 3");
builder.writeln("Paragraph 4");
builder.writeln("Paragraph 5");
builder.writeln("Paragraph 6");
Body body = doc.getFirstSection().getBody();
System.out.println("Paragraph count:" + body.getParagraphs().getCount());
// Start tracking revisions.
doc.startTrackRevisions("Author", new Date());
// Generate revisions when moving a node from one location to another.
Node node = body.getParagraphs().get(3);
Node endNode = body.getParagraphs().get(5).getNextSibling();
Node referenceNode = body.getParagraphs().get(0);
while (node != endNode)
{
Node nextNode = node.getNextSibling();
body.insertBefore(node, referenceNode);
node = nextNode;
}
// Stop the process of tracking revisions.
doc.stopTrackRevisions();
// There are 3 additional paragraphs in the move-from range.
System.out.println("Paragraph count: " + body.getParagraphs().getCount());
doc.save(dataDir + "out.docx");

إدارة وتخزين التغييرات كما التنقيحات

باستخدام ميزة تغييرات التتبع السابقة، يمكنك فهم التغييرات التي تم إجراؤها في المستند ومن أجرى هذه التغييرات. أثناء استخدام ميزة TrackRevisions، فإنك تفرض تخزين أي تغييرات داخل المستند كمراجعات.

Aspose.Words يسمح لك بالتحقق مما إذا كان المستند يحتوي على مراجعة أم لا باستخدام خاصية HasRevision. إذا لم تكن بحاجة إلى تتبع التغييرات في المستند تلقائيا من خلال الطريقتين StartTrackRevisions و StopTrackRevisions، فيمكنك استخدام الخاصية TrackRevisions للتحقق مما إذا كان يتم تتبع التغييرات أثناء تحرير مستند في Microsoft Word وتخزينها كمراجعات.

تقوم ميزة TrackRevisions بإجراء مراجعات بدلا من التغييرات الحقيقية DOM. لكن المراجعات نفسها منفصلة. على سبيل المثال، إذا قمت بحذف أي فقرة، Aspose.Words اجعلها مراجعة، مع وضع علامة عليها كحذف، بدلا من حذفها.

بالإضافة إلى ذلك، Aspose.Words يسمح لك بالتحقق مما إذا تم إدراج كائن أو حذفه أو تغيير التنسيق باستخدام IsDeleteRevision, IsFormatRevision, IsInsertRevision, IsMoveFromRevision, و IsMoveToRevision خصائص.

يوضح مثال الكود التالي كيفية تطبيق خصائص مختلفة مع المراجعات:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Open a blank document.
Document doc = new Document();
// Insert an inline shape without tracking revisions.
Shape shape = new Shape(doc, ShapeType.CUBE);
shape.setWrapType(WrapType.INLINE);
shape.setWidth(100.0);
shape.setHeight(100.0);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(shape);
// Start tracking revisions and then insert another shape.
doc.startTrackRevisions("John Doe");
shape = new Shape(doc, ShapeType.SUN);
shape.setWrapType(WrapType.INLINE);
shape.setWidth(100.0);
shape.setHeight(100.0);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(shape);
// Get the document's shape collection which includes just the two shapes we added.
Node[] shapes = doc.getChildNodes(NodeType.SHAPE, true).toArray();
if(2 == shapes.length)
System.out.println("Shapes Count:" + shapes.length);
// Remove the first shape.
shapes[0].remove();
Shape sh = (Shape) shapes[0];
// Because we removed that shape while changes were being tracked, the shape counts as a delete revision.
if(ShapeType.CUBE == sh.getShapeType())
System.out.println("Shape is CUBE");
if(sh.isDeleteRevision())
System.out.println("isDeleteRevision:" + sh.isDeleteRevision());
// And we inserted another shape while tracking changes, so that shape will count as an insert revision.
sh = (Shape) shapes[1];
if(ShapeType.SUN == sh.getShapeType())
System.out.println("Shape is SUN");
if(sh.isInsertRevision())
System.out.println("IsInsertRevision:" + sh.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 = new Document(dataDir + "Revision shape.docx");
Node[] nc = doc.getChildNodes(NodeType.SHAPE, true).toArray();
if(4 == nc.length)
System.out.println("Shapes Count:" + nc.length);
Shape mvr = (Shape) nc[0];
// This is the move to revision, also the shape at its arrival destination.
if(mvr.isMoveFromRevision())
System.out.println("isMoveFromRevision:" + mvr.isMoveFromRevision());
if(mvr.isMoveToRevision())
System.out.println("isMoveToRevision:" + mvr.isMoveToRevision());
mvr = (Shape) nc[1];
// This is the move from revision, which is the shape at its original location.
if(mvr.isMoveFromRevision())
System.out.println("isMoveFromRevision:" + mvr.isMoveFromRevision());
if(mvr.isMoveToRevision())
System.out.println("isMoveToRevision:" + mvr.isMoveToRevision());