Back to Devexpress

DxTreeList.ExportToXlsxAsync(Stream, TreeListXlExportOptions) Method

blazor-devexpress-dot-blazor-dot-dxtreelist-dot-exporttoxlsxasync-x28-system-dot-io-dot-stream-devexpress-dot-blazor-dot-treelistxlexportoptions-x29.md

latest5.0 KB
Original Source

DxTreeList.ExportToXlsxAsync(Stream, TreeListXlExportOptions) Method

Exports TreeList data in XLSX format to a stream.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public Task ExportToXlsxAsync(
    Stream stream,
    TreeListXlExportOptions options = null
)

Parameters

NameTypeDescription
streamStream

The target stream for export.

|

Optional Parameters

NameTypeDefaultDescription
optionsTreeListXlExportOptionsnull

An object that contains export options.

|

Returns

TypeDescription
Task

The task that is completed when the file is exported.

|

Remarks

Call the ExportToXlsxAsync method to export TreeList data in XLSX format. The method overloads allow you to write the result to a stream (the current overload) or to a file downloaded to a client machine (ExportToXlsxAsync(String, TreeListXlExportOptions)).

The method accepts a TreeListXlExportOptions object as a parameter. You can use this parameter to set up export settings.

For additional information about data export in the TreeList component, refer to the following topic: Export Blazor TreeList Data to XLS/XLSX.

Run Demo: TreeList - Export

Example

The following example uses a file stream to export TreeList data to the XLSX file:

razor
<DxButton Text="Export to XLSX" Click="ExportXlsx_Click" />

<DxTreeList Data="TreeListData" 
            KeyFieldName="Id" 
            ParentKeyFieldName="ParentId" 
            @ref="MyTreeList">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>

@code {
    ITreeList MyTreeList { get; set; }

    async Task ExportXlsx_Click() {
        string path = @"C:\MyProjects\MyFile.xlsx";
        FileStream fs = File.OpenWrite(path);
        await MyTreeList.ExportToXlsxAsync(fs);
        fs.Dispose();
    }
}

Export Specifics and Limitations

  • Content of templates is not exported.
  • Excel permits up to seven nesting levels in outlines. Deeper nesting levels are exported at the seventh nesting level.
  • The TreeList exports custom summaries (implemented in the CustomSummary event) as plain text.
  • Data columns anchored to the right edge become regular columns, while columns anchored to the component’s left edge remain frozen.
  • CSS classes applied to the TreeList and its elements do not affect the exported document’s appearance. Handle the CustomizeCell event to customize the output table.
  • In on demand data loading mode, an export operation forces the component to load all data.

If the TreeList is bound to a GridDevExtremeDataSource object, the following limitations apply:

Refer to the following articles for information about Microsoft Excel limitations:

Implements

ExportToXlsxAsync(Stream, TreeListXlExportOptions)

See Also

DxTreeList Class

DxTreeList Members

DevExpress.Blazor Namespace