문서 편집 제한

때로는 문서를 편집 할 수있는 기능을 제한하고 특정 작업 만 허용해야 할 수도 있습니다. 이 기능은 다른 사람이 문서의 민감한 기밀 정보를 편집하지 못하도록 하는 데 유용할 수 있습니다.

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