پیگیری تغییرات در یک سند

قابلیت تغییرات مسیر، که به عنوان بررسی نیز شناخته می شود، به شما امکان می دهد تغییرات محتوا و قالب بندی انجام شده توسط خود یا سایر کاربران را ردیابی کنید. این ویژگی تغییر مسیر با Aspose.Words از تغییرات مسیر در Microsoft Word پشتیبانی می کند. با استفاده از این قابلیت، می توانید به بازنگری های فردی در سند خود دسترسی پیدا کنید و ویژگی های مختلفی را برای آنها اعمال کنید.

هنگامی که ویژگی track changes را فعال می کنید، تمام عناصر وارد شده، حذف شده و اصلاح شده سند با اطلاعات مربوط به چه کسی، چه زمانی و چه چیزی تغییر کرده است، به صورت بصری برجسته می شوند. اشیایی که اطلاعات مربوط به آنچه تغییر کرده است را حمل می کنند “تغییرات ردیابی"نامیده می شوند. به عنوان مثال، فرض کنید که می خواهید یک سند را مرور کنید و تغییرات مهمی ایجاد کنید – این ممکن است به این معنی باشد که شما باید تجدید نظر کنید. همچنین، ممکن است لازم باشد که برای بحث در مورد برخی از تغییرات، نظرات را وارد کنید. اینجاست که تغییرات ردیابی در اسناد وارد می شود.

این مقاله توضیح می دهد که چگونه تغییرات ایجاد شده توسط بسیاری از بازبینی کنندگان در یک سند و همچنین ویژگی های ردیابی تغییرات را مدیریت و ردیابی کنید.

بازنگری چیست ؟

قبل از اینکه به بازنگری ها بپردازیم، بیایید معنای بازنگری ها را توضیح دهیم. A 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());