Aspose::Words::Markup::CustomPartCollection класс

CustomPartCollection class

Представляет собой коллекцию объектов CustomPart. Чтобы узнать больше, посетите статью документации Structured Document Tags or Content Control.

class CustomPartCollection : public System::Collections::Generic::IEnumerable<System::SharedPtr<Aspose::Words::Markup::CustomPart>>

Методы

МетодОписание
Add(const System::SharedPtr<Aspose::Words::Markup::CustomPart>&)Добавляет элемент в коллекцию.
begin()
begin() const
cbegin() const
cend() const
Clear()Удаляет все элементы из коллекции.
Clone()Создаёт глубокую копию этой коллекции и её элементов.
CustomPartCollection()
end()
end() const
get_Count()Получает количество элементов, содержащихся в коллекции.
GetEnumerator() overrideВозвращает объект‑перечислитель, который можно использовать для перебора всех элементов в коллекции.
GetType() const override
idx_get(int32_t)Получает или задает элемент по указанному индексу.
idx_set(int32_t, const System::SharedPtr<Aspose::Words::Markup::CustomPart>&)Получает или задает элемент по указанному индексу.
Is(const System::TypeInfo&) const override
RemoveAt(int32_t)Удаляет элемент по указанному индексу.
static Type()
virtualizeBeginConstIterator() const override
virtualizeBeginIterator() override
virtualizeEndConstIterator() const override
virtualizeEndIterator() override

Typedefs

Типовое определениеОписание
const_iterator
iterator
iterator_holder_type
virtualized_iterator
virtualized_iterator_element

Примечания

Обычно вам не требуется создавать экземпляры этого класса. Вы получаете доступ к пользовательским частям, связанным с пакетом OOXML, через свойство PackageCustomParts.

Примеры

Показывает, как получить доступ к коллекции произвольных пользовательских частей документа.

auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Custom parts OOXML package.docx");

ASSERT_EQ(2, doc->get_PackageCustomParts()->get_Count());

// Клонируйте вторую часть, затем добавьте клон в коллекцию.
System::SharedPtr<Aspose::Words::Markup::CustomPart> clonedPart = doc->get_PackageCustomParts()->idx_get(1)->Clone();
doc->get_PackageCustomParts()->Add(clonedPart);

ASSERT_EQ(3, doc->get_PackageCustomParts()->get_Count());

// Переберите коллекцию и выведите каждую часть.
{
    System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::Markup::CustomPart>>> enumerator = doc->get_PackageCustomParts()->GetEnumerator();
    int32_t index = 0;
    while (enumerator->MoveNext())
    {
        std::cout << System::String::Format(u"Part index {0}:", index) << std::endl;
        std::cout << System::String::Format(u"\tName:\t\t\t\t{0}", enumerator->get_Current()->get_Name()) << std::endl;
        std::cout << System::String::Format(u"\tContent type:\t\t{0}", enumerator->get_Current()->get_ContentType()) << std::endl;
        std::cout << System::String::Format(u"\tRelationship type:\t{0}", enumerator->get_Current()->get_RelationshipType()) << std::endl;
        std::cout << (enumerator->get_Current()->get_IsExternal() ? u"\tSourced from outside the document" : System::String::Format(u"\tStored within the document, length: {0} bytes", enumerator->get_Current()->get_Data()->get_Length())) << std::endl;
        index++;
    }
}

// Мы можем удалять элементы из этой коллекции по отдельности или сразу все.
doc->get_PackageCustomParts()->RemoveAt(2);

ASSERT_EQ(2, doc->get_PackageCustomParts()->get_Count());

doc->get_PackageCustomParts()->Clear();

ASSERT_EQ(0, doc->get_PackageCustomParts()->get_Count());

См. также