Aspose::Words::Drawing::OleFormat::GetOleEntry method
Contents
[
Hide
]OleFormat::GetOleEntry method
Gets OLE object data entry.
System::SharedPtr<System::IO::MemoryStream> Aspose::Words::Drawing::OleFormat::GetOleEntry(const System::String &oleEntryName)
Parameter | Type | Description |
---|---|---|
oleEntryName | const System::String& | Case-sensitive name of the OLE data stream. |
ReturnValue
An OLE data stream or null.
Examples
Shows how to insert linked and unlinked OLE objects.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
// Embed a Microsoft Visio drawing into the document as an OLE object.
builder->InsertOleObject(get_ImageDir() + u"Microsoft Visio drawing.vsd", u"Package", false, false, nullptr);
// Insert a link to the file in the local file system and display it as an icon.
builder->InsertOleObject(get_ImageDir() + u"Microsoft Visio drawing.vsd", u"Package", true, true, nullptr);
// Inserting OLE objects creates shapes that store these objects.
System::ArrayPtr<System::SharedPtr<Aspose::Words::Drawing::Shape>> shapes = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_OfType<System::SharedPtr<Aspose::Words::Drawing::Shape> >()->LINQ_ToArray();
ASSERT_EQ(2, shapes->get_Length());
ASSERT_EQ(2, shapes->LINQ_Count(static_cast<System::Func<System::SharedPtr<Aspose::Words::Drawing::Shape>, bool>>(static_cast<std::function<bool(System::SharedPtr<Aspose::Words::Drawing::Shape> s)>>([](System::SharedPtr<Aspose::Words::Drawing::Shape> s) -> bool
{
return s->get_ShapeType() == Aspose::Words::Drawing::ShapeType::OleObject;
}))));
// If a shape contains an OLE object, it will have a valid "OleFormat" property,
// which we can use to verify some aspects of the shape.
System::SharedPtr<Aspose::Words::Drawing::OleFormat> oleFormat = shapes[0]->get_OleFormat();
ASPOSE_ASSERT_EQ(false, oleFormat->get_IsLink());
ASPOSE_ASSERT_EQ(false, oleFormat->get_OleIcon());
oleFormat = shapes[1]->get_OleFormat();
ASPOSE_ASSERT_EQ(true, oleFormat->get_IsLink());
ASPOSE_ASSERT_EQ(true, oleFormat->get_OleIcon());
ASSERT_TRUE(oleFormat->get_SourceFullName().EndsWith(System::String(u"Images") + System::IO::Path::DirectorySeparatorChar + u"Microsoft Visio drawing.vsd"));
ASSERT_EQ(u"", oleFormat->get_SourceItem());
ASSERT_EQ(u"Microsoft Visio drawing.vsd", oleFormat->get_IconCaption());
doc->Save(get_ArtifactsDir() + u"Shape.OleLinks.docx");
// If the object contains OLE data, we can access it using a stream.
{
System::SharedPtr<System::IO::MemoryStream> stream = oleFormat->GetOleEntry(u"\x0001" u"CompObj");
System::ArrayPtr<uint8_t> oleEntryBytes = stream->ToArray();
ASSERT_EQ(76, oleEntryBytes->get_Length());
}
See Also
- Class OleFormat
- Namespace Aspose::Words::Drawing
- Library Aspose.Words for C++