Aspose::Words::EditableRangeEnd class
Contents
[
Hide
]EditableRangeEnd class
Represents an end of an editable range in a Word document. To learn more, visit the Aspose.Words Document Object Model (DOM) documentation article.
class EditableRangeEnd : public Aspose::Words::Node,
public Aspose::Words::IDisplaceableByCustomXml,
public Aspose::Words::INodeWithAnnotationId
Methods
Method | Description |
---|---|
Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor. |
Clone(bool) | Creates a duplicate of the node. |
get_CustomNodeId() const | Specifies custom node identifier. |
virtual get_Document() const | Gets the document to which this node belongs. |
get_EditableRangeStart() | Corresponding EditableRangeStart, received by ID. |
get_Id() const | Specifies the identifier of the editable range. |
virtual get_IsComposite() | Returns true if this node can contain other nodes. |
get_NextNode() const | |
get_NextSibling() | Gets the node immediately following this node. |
get_NodeType() const override | Returns EditableRangeEnd. |
get_ParentNode() | Gets the immediate parent of this node. |
get_PreviousSibling() | Gets the node immediately preceding this node. |
get_PrevNode() const | |
get_Range() | Returns a Range object that represents the portion of a document that is contained in this node. |
GetAncestor(Aspose::Words::NodeType) | Gets the first ancestor of the specified NodeType. |
GetAncestorOf() | |
virtual GetText() | Gets the text of this node and of all its children. |
GetType() const override | |
Is(const System::TypeInfo&) const override | |
IsAncestorNode(const System::SharedPtr<Aspose::Words::Node>&) | |
NextPreOrder(const System::SharedPtr<Aspose::Words::Node>&) | Gets next node according to the pre-order tree traversal algorithm. |
static NodeTypeToString(Aspose::Words::NodeType) | A utility method that converts a node type enum value into a user friendly string. |
PreviousPreOrder(const System::SharedPtr<Aspose::Words::Node>&) | Gets the previous node according to the pre-order tree traversal algorithm. |
Remove() | Removes itself from the parent. |
set_CustomNodeId(int32_t) | Setter for Aspose::Words::Node::get_CustomNodeId. |
set_Id(int32_t) | Setter for Aspose::Words::EditableRangeEnd::get_Id. |
set_NextNode(const System::SharedPtr<Aspose::Words::Node>&) | |
set_PrevNode(const System::SharedPtr<Aspose::Words::Node>&) | |
SetParent(const System::SharedPtr<Aspose::Words::Node>&) | |
ToString(Aspose::Words::SaveFormat) | Exports the content of the node into a string in the specified format. |
ToString(const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&) | Exports the content of the node into a string using the specified save options. |
static Type() |
Remarks
A complete editable range in a Word document consists of a EditableRangeStart and a matching EditableRangeEnd with the same Id.
EditableRangeStart and EditableRangeEnd are just markers inside a document that specify where the editable range starts and ends.
Use the EditableRange class as a “facade” to work with an editable range as a single object.
Currently editable ranges are supported only at the inline-level, that is inside Paragraph, but editable range start and editable range end can be in different paragraphs.
Examples
Shows how to limit the editing rights of editable ranges to a specific group/user.
void Visitor()
{
auto doc = MakeObject<Document>();
doc->Protect(ProtectionType::ReadOnly, u"MyPassword");
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(String(u"Hello world! Since we have set the document's protection level to read-only,") +
u" we cannot edit this paragraph without the password.");
// When we write-protect documents, editable ranges allow us to pick specific areas that users may edit.
// There are two mutually exclusive ways to narrow down the list of allowed editors.
// 1 - Specify a user:
SharedPtr<EditableRange> editableRange = builder->StartEditableRange()->get_EditableRange();
editableRange->set_SingleUser(u"john.doe@myoffice.com");
builder->Writeln(String::Format(u"This paragraph is inside the first editable range, can only be edited by {0}.", editableRange->get_SingleUser()));
builder->EndEditableRange();
ASSERT_EQ(EditorType::Unspecified, editableRange->get_EditorGroup());
// 2 - Specify a group that allowed users are associated with:
editableRange = builder->StartEditableRange()->get_EditableRange();
editableRange->set_EditorGroup(EditorType::Administrators);
builder->Writeln(String::Format(u"This paragraph is inside the first editable range, can only be edited by {0}.", editableRange->get_EditorGroup()));
builder->EndEditableRange();
ASSERT_EQ(String::Empty, editableRange->get_SingleUser());
builder->Writeln(u"This paragraph is outside the editable range, and cannot be edited by anybody.");
// Print details and contents of every editable range in the document.
auto editableRangePrinter = MakeObject<ExEditableRange::EditableRangePrinter>();
doc->Accept(editableRangePrinter);
std::cout << editableRangePrinter->ToText() << std::endl;
}
class EditableRangePrinter : public DocumentVisitor
{
public:
EditableRangePrinter() : mInsideEditableRange(false)
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
String ToText()
{
return mBuilder->ToString();
}
void Reset()
{
mBuilder->Clear();
mInsideEditableRange = false;
}
VisitorAction VisitEditableRangeStart(SharedPtr<EditableRangeStart> editableRangeStart) override
{
mBuilder->AppendLine(u" -- Editable range found! -- ");
mBuilder->AppendLine(String(u"\tID:\t\t") + editableRangeStart->get_Id());
if (editableRangeStart->get_EditableRange()->get_SingleUser() == String::Empty)
{
mBuilder->AppendLine(String(u"\tGroup:\t") + System::ObjectExt::ToString(editableRangeStart->get_EditableRange()->get_EditorGroup()));
}
else
{
mBuilder->AppendLine(String(u"\tUser:\t") + editableRangeStart->get_EditableRange()->get_SingleUser());
}
mBuilder->AppendLine(u"\tContents:");
mInsideEditableRange = true;
return VisitorAction::Continue;
}
VisitorAction VisitEditableRangeEnd(SharedPtr<EditableRangeEnd> editableRangeEnd) override
{
mBuilder->AppendLine(u" -- End of editable range --\n");
mInsideEditableRange = false;
return VisitorAction::Continue;
}
VisitorAction VisitRun(SharedPtr<Run> run) override
{
if (mInsideEditableRange)
{
mBuilder->AppendLine(String(u"\t\"") + run->get_Text() + u"\"");
}
return VisitorAction::Continue;
}
private:
bool mInsideEditableRange;
SharedPtr<System::Text::StringBuilder> mBuilder;
};
See Also
- Class Node
- Namespace Aspose::Words
- Library Aspose.Words for C++