Back to Devexpress

OleFormat.GetRawData() Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-oleformat-ffa16bc1.md

latest3.8 KB
Original Source

OleFormat.GetRawData() Method

Returns the embedded OLE object’s raw data.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
byte[] GetRawData()
vb
Function GetRawData As Byte()

Returns

TypeDescription
Byte[]

A byte array that contains extracted data. Null ( Nothing in Visual Basic) for a linked OLE object.

|

Remarks

The following example loads spreadsheet data from a Word document into the Spreadsheet Document API component. You can modify and save this data to a file.

Important

You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use this example in production code. Refer to the following page for pricing information: DevExpress Subscriptions.

csharp
using System.Linq;
using DevExpress.XtraRichEdit.API.Native;
// Add references to DevExpress.Docs.dll 
// and DevExpress.Spreadsheet.Core.dll.
using DevExpress.Spreadsheet;
// ...

Document document = wordProcessor.Document;
// Obtain an OLE object that stores spreadsheet data.
DevExpress.XtraRichEdit.API.Native.Shape embeddedObject = document.Shapes.FirstOrDefault(
    x => x.Type == DevExpress.XtraRichEdit.API.Native.ShapeType.OleObject &&
    x.OleFormat.InsertType == OleInsertType.Embedded &&
    x.OleFormat.ProgId == OleObjectType.ExcelWorksheet);

if (embeddedObject != null)
{
    // Retrieve data from the OLE object.
    byte[] spreadsheetData = embeddedObject.OleFormat.GetRawData();
    // Create a Workbook instance.
    using (Workbook workbook = new Workbook()) {
        // Load data into the workbook.
        workbook.LoadDocument(spreadsheetData);
        // Modify data.
        // ...

        // Save the document.
        workbook.SaveDocument("ExcelDocument.xlsx", DevExpress.Spreadsheet.DocumentFormat.Xlsx);
    }
}
vb
Imports System.Linq
Imports DevExpress.XtraRichEdit.API.Native
' Add references to DevExpress.Docs.dll 
' and DevExpress.Spreadsheet.Core.dll.
Imports DevExpress.Spreadsheet
' ...

Dim document As Document = wordProcessor.Document
' Obtain an OLE object that stores spreadsheet data.
Dim embeddedObject As DevExpress.XtraRichEdit.API.Native.Shape = 
    document.Shapes.FirstOrDefault(Function(x) x.Type = 
    DevExpress.XtraRichEdit.API.Native.ShapeType.OleObject _
    AndAlso x.OleFormat.InsertType = OleInsertType.Embedded _
    AndAlso x.OleFormat.ProgId = OleObjectType.ExcelWorksheet)

If embeddedObject IsNot Nothing Then
    ' Retrieve data from the OLE object.
    Dim spreadsheetData() As Byte = embeddedObject.OleFormat.GetRawData()
    ' Create a Workbook instance.
    Using workbook As New Workbook()
        ' Load data into the workbook.
        workbook.LoadDocument(spreadsheetData)
        ' Modify data.
        ' ...

        ' Save the document.
        workbook.SaveDocument("ExcelDocument.xlsx", DevExpress.Spreadsheet.DocumentFormat.Xlsx)
    End Using
End If

See Also

OleFormat Interface

OleFormat Members

DevExpress.XtraRichEdit.API.Native Namespace