This example illustrates how to export several components to different worksheets of the same XLSX document.
In this example, the page contains 3 components: ASPxGridView, ASPxTreeList, and WebChartControl. You can export them to different worksheets of the same document in the following way:
-
Create a PrintableComponentLinkBase object for every component.
PrintableComponentLinkBase link1 = new PrintableComponentLinkBase(ps); link1.Component = Grid; PrintableComponentLinkBase link2 = new PrintableComponentLinkBase(ps); link2.Component = Tree; PrintableComponentLinkBase link3 = new PrintableComponentLinkBase(ps); Chart.DataBind(); link3.Component = ((IChartContainer)Chart).Chart;
-
Call the CreatePageForEachLink method to create a separate page for every component.
CompositeLinkBase compositeLink = new CompositeLinkBase(ps); compositeLink.Links.AddRange(new object[] { link1, link2, link3 }); compositeLink.CreatePageForEachLink();
-
Create an XlsxExportOptions object and set its ExportMode property to
SingleFilePageByPage
value to export a document to a single file, page-by-page. Send the options to the ExportToXlsx method to export the document.XlsxExportOptions options = new XlsxExportOptions(); options.ExportMode = XlsxExportMode.SingleFilePageByPage; compositeLink.PrintingSystemBase.ExportToXlsx(stream, options);
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)