הגבל עריכת מסמכים

לפעמים ייתכן שיהיה עליך להגביל את היכולת לערוך מסמך ולאפשר רק פעולות מסוימות איתו. זה יכול להיות שימושי כדי למנוע מאנשים אחרים לערוך מידע רגיש וסודי במסמך שלך.

Aspose.Words מאפשר לך להגביל עריכת מסמך על ידי הגדרת סוג הגבלה. בנוסף, Aspose.Words גם מאפשר לך לציין הגדרות הגנת כתיבה למסמך.

מאמר זה מסביר כיצד להשתמש Aspose.Words לבחירת סוג הגבלה, כיצד להוסיף או להסיר הגנה וכיצד להפוך אזורים בלתי מוגבלים לעריכה.

בחר סוג הגבלת עריכה

Aspose.Words מאפשר לך לשלוט באופן שבו אתה מגביל את התוכן באמצעות פרמטר הספירה ProtectionType. זה יאפשר לך לבחור סוג הגנה מדויק כגון:

  • AllowOnlyComments
  • AllowOnlyFormFields
  • AllowOnlyRevisions
  • ReadOnly
  • NoProtection

כל הסוגים מאובטחים בסיסמה, ואם סיסמה זו לא הוזנה כהלכה, משתמש לא יוכל לשנות באופן חוקי את תוכן המסמך שלך. לפיכך, אם המסמך שלך מוחזר אליך ללא דרישה לספק את הסיסמה הדרושה, זה סימן שמשהו לא בסדר.

אם לא הגדרת סיסמה בעת בחירת סוג האבטחה, משתמשים אחרים יכולים פשוט להתעלם מההגנה על המסמך שלך.

הוסף הגנה על מסמכים

הוספת הגנה למסמך שלך היא תהליך פשוט, שכן כל שעליך לעשות הוא ליישם אחת משיטות ההגנה המפורטות בסעיף זה.

Aspose.Words מאפשר לך להגן על המסמכים שלך מפני שינויים בשיטת Protect. שיטה זו אינה תכונת אבטחה ואינה מצפינה מסמך.

דוגמת הקוד הבאה מראה כיצד להוסיף הגנה באמצעות סיסמה למסמך שלך:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Create a new document and protect it with a password.
auto doc = System::MakeObject<Document>();
// Apply Document Protection.
doc->Protect(ProtectionType::NoProtection, u"password");
// Save the document.
doc->Save(ArtifactsDir + u"DocumentProtection.PasswordProtection.docx");

דוגמת הקוד הבאה מראה כיצד להגביל עריכה במסמך כך שרק עריכה בשדות טופס אפשרית:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Insert two sections with some text.
auto doc = System::MakeObject<Document>();
auto builder = System::MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Text added to a document.");
// A document protection only works when document protection is turned and only editing in form fields is allowed.
doc->Protect(ProtectionType::AllowOnlyFormFields, u"password");
// Save the protected document.
doc->Save(ArtifactsDir + u"DocumentProtection.PasswordProtection.docx");

הסר את הגנת המסמכים

Aspose.Words מאפשר לך להסיר הגנה ממסמך עם שינוי מסמך פשוט וישיר. באפשרותך להסיר את הגנת המסמך מבלי לדעת את הסיסמה בפועל או לספק את הסיסמה הנכונה לביטול נעילת המסמך באמצעות שיטת Unprotect. שתי הדרכים להסרת אין הבדל.

דוגמת הקוד הבאה מראה כיצד להסיר הגנה מהמסמך שלך:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Create a new document and protect it with a password.
auto doc = System::MakeObject<Document>();
// Add text.
auto builder = System::MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Text added to a document.");
// Documents can have protection removed either with no password, or with the correct password.
doc->Unprotect();
doc->Protect(ProtectionType::ReadOnly, u"newPassword");
doc->Unprotect(u"newPassword");
// Save the document.
doc->Save(ArtifactsDir + u"DocumentProtection.RemoveDocumentProtection.docx");

ציין אזורים הניתנים לעריכה ללא הגבלה

אתה יכול להגביל את עריכת המסמך שלך ובמקביל לאפשר שינויים בחלקים שנבחרו ממנו. לכן, כל מי שיפתח את המסמך שלך יוכל לגשת לחלקים בלתי מוגבלים אלה ולבצע שינויים בתוכן.

Aspose.Words מאפשר לך לסמן את החלקים שניתן לשנות במסמך שלך באמצעות StartEditableRange ו EndEditableRange שיטות.

דוגמת הקוד הבאה מראה כיצד לסמן את המסמך כולו כקריאה בלבד ולציין בו אזורים הניתנים לעריכה:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Upload a document and make it as read-only.
auto doc = System::MakeObject<Document>(MyDir + u"Document.docx");
auto builder = System::MakeObject<DocumentBuilder>(doc);
doc->Protect(ProtectionType::ReadOnly, u"MyPassword");
builder->Writeln(u"Hello world! Since we have set the document's protection level to read-only, we cannot edit this paragraph without the password.");
// Start an editable range.
auto edRangeStart = builder->StartEditableRange();
// An EditableRange object is created for the EditableRangeStart that we just made.
auto editableRange = edRangeStart->get_EditableRange();
// Put something inside the editable range.
builder->Writeln(u"Paragraph inside first editable range");
// An editable range is well-formed if it has a start and an end.
auto edRangeEnd = builder->EndEditableRange();
// Save your document.
builder->Writeln(u"This paragraph is outside any editable ranges, and cannot be edited.");
doc->Save(ArtifactsDir + u"DocumentProtection.UnrestrictedEditableRegions.docx");

ניתן גם לבחור הגבלות שונות לעריכת מסמכים עבור חלקים שונים.

דוגמת הקוד הבאה מראה כיצד להוסיף הגבלה עבור המסמך כולו, ולאחר מכן להסיר את ההגבלה עבור אחד הסעיפים:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Insert two sections with some text.
auto doc = System::MakeObject<Document>();
auto builder = System::MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Section 1. Unprotected.");
builder->InsertBreak(BreakType::SectionBreakContinuous);
builder->Writeln(u"Section 2. Protected.");
// Section protection only works when document protection is turned and only editing in form fields is allowed.
doc->Protect(ProtectionType::AllowOnlyFormFields, u"password");
// By default, all sections are protected, but we can selectively turn protection off.
doc->get_Sections()->idx_get(0)->set_ProtectedForForms(false);
doc->Save(ArtifactsDir + u"DocumentProtection.UnrestrictedSection.docx");
doc = System::MakeObject<Document>(ArtifactsDir + u"DocumentProtection.UnrestrictedSection.docx");
ASSERT_FALSE(doc->get_Sections()->idx_get(0)->get_ProtectedForForms());
ASSERT_TRUE(doc->get_Sections()->idx_get(1)->get_ProtectedForForms());