TreeListXlExportOptions.CustomizeSheetHeader Property
Allows you to add rows above grid content in the output document.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
public Action<TreeListExportCustomizeSheetHeaderFooterEventArgs> CustomizeSheetHeader { get; set; }
Property Value
Type | Description |
---|---|
Action<TreeListExportCustomizeSheetHeaderFooterEventArgs> | A delegate method that customizes the document header area. |
Remarks
The TreeList calls the CustomizeSheetHeader
delegate method before the TreeList starts exporting data. You can write the action handler to perform the following actions:
- Add rows below the TreeList data (AddRow(), AddRow(Object[]), AddRow(CellObject[])).
- Insert an image (InsertImage(DXImage, Size), InsertImage(DXImage, XlCellRange)). Not available in WASM.
- Merge cells (MergeCells(XlCellRange)).
@using DevExpress.Printing.ExportHelpers
@using DevExpress.Export
@using DevExpress.Export.Xl
@using DevExpress.Drawing
<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() {
var options = new TreeListXlExportOptions();
options.CustomizeSheetHeader = e => {
// Specify cell formatting.
var FirstCellFormat = new XlFormattingObject();
FirstCellFormat.Font = new XlCellFont();
FirstCellFormat.Font.Size = 24;
FirstCellFormat.Font.Bold = true;
FirstCellFormat.Alignment = new XlCellAlignment();
FirstCellFormat.Alignment.HorizontalAlignment = XlHorizontalAlignment.Center;
FirstCellFormat.Alignment.VerticalAlignment = XlVerticalAlignment.Center;
var SecondCellFormat = FirstCellFormat;
SecondCellFormat.Font.Size = 18;
// Add an image to the top of the document.
for (var i = 0; i < 8; i++) {
e.ExportContext.AddRow();
}
var ImageCellRange = new XlCellRange(new XlCellPosition(0, 0), new XlCellPosition(5, 7));
e.ExportContext.MergeCells(ImageCellRange);
var fileName = @"C:\temp\DevExpress-Logo.png";
using (FileStream outfile = new FileStream(fileName, FileMode.Open))
e.ExportContext.InsertImage(DXImage.FromStream(outfile), ImageCellRange);
// Add an empty row.
e.ExportContext.AddRow();
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(0, 8), new XlCellPosition(5, 8)));
// Add rows with company contacts.
var AddressCellName = new CellObject { Value = "Address :", Formatting = FirstCellFormat };
var AddressCellLocation = new CellObject { Value = "505 N. Brand Blvd Suite 1450", Formatting = SecondCellFormat };
e.ExportContext.AddRow(new[] { AddressCellName, null, AddressCellLocation });
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(0, 9), new XlCellPosition(1, 10)));
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(2, 9), new XlCellPosition(5, 9)));
var AddressCellLocation2 = new CellObject { Value = "Glendale CA 91203 USA", Formatting = SecondCellFormat };
e.ExportContext.AddRow(new[] { null, null, AddressCellLocation2 });
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(2, 10), new XlCellPosition(5, 10)));
var PhoneCellName = new CellObject { Value = "Phone :", Formatting = FirstCellFormat };
var PhoneCellLocation = new CellObject { Value = "+ 1 (818) 844-3383", Formatting = SecondCellFormat };
e.ExportContext.AddRow(new[] { PhoneCellName, null, PhoneCellLocation });
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(0, 11), new XlCellPosition(1, 11)));
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(2, 11), new XlCellPosition(5, 11)));
var FaxCellName = new CellObject { Value = "Fax :", Formatting = FirstCellFormat };
var FaxCellLocation = new CellObject { Value = "+ 1 (818) 844-3395", Formatting = SecondCellFormat };
e.ExportContext.AddRow(new[] { FaxCellName, null, FaxCellLocation });
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(0, 12), new XlCellPosition(1, 12)));
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(2, 12), new XlCellPosition(5, 12)));
var EmailCellName = new CellObject { Value = "Email :", Formatting = FirstCellFormat };
var EmailCellLocation = new CellObject { Value = "clientservices@devexpress.com" };
EmailCellLocation.Hyperlink = "mailto:clientservices@devexpress.com";
e.ExportContext.AddRow(new[] { EmailCellName, null, EmailCellLocation });
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(0, 13), new XlCellPosition(1, 13)));
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(2, 13), new XlCellPosition(5, 13)));
// Add an empty row.
e.ExportContext.AddRow();
e.ExportContext.MergeCells(new XlCellRange(new XlCellPosition(0, 14), new XlCellPosition(5, 14)));
};
await MyTreeList.ExportToXlsxAsync("ExportResult", options);
}
}
See Also