This example demonstrates how to bind a report to a Microsoft Excel workbook and specify the report layout at runtime.
Do the following to bind a report to an Excel file:
Create the ExcelDataSource class's instance and specify the full path to the source Excel file using the ExcelDataSource.FileName property.
Select the required worksheet by creating a new ExcelWorksheetSettings object and using its ExcelWorksheetSettings.WorksheetName property.
Create the ExcelSourceOptions class's instance to specify the required options for extracting data from the workbook.
Assign the ExcelSourceOptions.ImportSettings property to the previously created ExcelWorksheetSettings object.
Disable the ExcelSourceOptions.SkipHiddenRows and ExcelSourceOptions.SkipHiddenColumns options to include hidden rows and columns to the resulting data source.
Set the ExcelDataSource.SourceOptions property to this ExcelSourceOptions object.
The report engine automatically generates a data source schema by default. Do the following to manually define the data source schema if you need to customize the data fields' display names and types:
- Assign the created data source to the report's XtraReportBase.DataSource property.
- Provide data to report controls using the XRControl.ExpressionBindings or XRControl.DataBindings property depending on the report's data binding mode.
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows.Forms
Namespace BindingReportToExcelWorkbook
Friend NotInheritable Class Program
Private Sub New()
End Sub
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread> _
Shared Sub Main()
'Uncomment this line to switch to the legacy binding mode.
'DevExpress.XtraReports.Configuration.Settings.Default.UserDesignerOptions.DataBindingMode =
' DevExpress.XtraReports.UI.DataBindingMode.Bindings;
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace BindingReportToExcelWorkbook
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Uncomment this line to switch to the legacy binding mode.
//DevExpress.XtraReports.Configuration.Settings.Default.UserDesignerOptions.DataBindingMode =
// DevExpress.XtraReports.UI.DataBindingMode.Bindings;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
See Also