จำกัดการแก้ไขเอกสาร

บางครั้งคุณอาจต้องจำกัดความสามารถในการแก้ไขเอกสารและอนุญาตให้มีการกระทำบ ะเป็นประโยชน์ในการป้องกันไม่ให้ผู้อื่นแก้ไขข้อมูลที่สำคัญและเป็นความลับในเอกสารข.

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());