The Report class represents a report generated from the data contained within an instance of a GridControl. Although the reporting capabilities of Xceed Grid for WinForms can be used with minimal programming by using the provided end-user forms (GenerateReportForm and CustomizeReportStyleForm, which is called in the former), you can forgo using these forms and perform the functions they contain programmatically.
The following code will instantiate the Report class:
VB.NET | Copy Code |
---|---|
Dim report As New Report( Me.gridControl1 ) |
C# | Copy Code |
---|---|
Report report = new Report( this.gridControl1 ); |
This creates an instance of the Report class with a default report style, using the data contained within gridControl1. You can then use one of the following methods to use the report: Print, PrintPreview, Export or CreatePrintDocument. The first three methods correspond to buttons that are available in the form called GenerateReportForm. The last method allows for more control than the Print method.
These methods print and preview the report, respectively. The default printer settings are used when no argument is passed to the method:
VB.NET |
Copy Code |
---|---|
Imports Xceed.Grid.Reporting Dim report As New Report( Me.gridControl1 ) report.PrintPreview() report.Print() |
C# |
Copy Code |
---|---|
using Xceed.Grid.Reporting; Report report = new Report( this.gridControl1 ); report.PrintPreview(); report.Print(); |
VB.NET |
Copy Code |
---|---|
Dim report As New Report( Me.gridControl1 ) Dim printerSettings As New System.Drawing.Printing.PrinterSettings() '... ' Set the printer settings. '... report.PrintPreview( printerSettings ) report.Print( printerSettings ) |
C# |
Copy Code |
---|---|
Report report = new Report( this.gridControl1 ); System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings(); //... // Set the printer settings. //... report.PrintPreview( printerSettings ); report.Print( printerSettings ); |
The ExportFormat enum value passed to the Export method determines which format will be used to export the report:
Export Format | Page Format |
---|---|
Multi-page format. | |
HTML | Continuous format. |
JPEG | Single-page format. |
TIFF | Multi-page format. |
If you export to a PDF, HTML or TIFF file, the entire report is exported in a single file. With HTML format, all of the report's information is presented in a single, continuous page.
If however you export a report using the JPEG format, each page of the report will be exported to a separate file with a number attaced to the filename. For example, consider this code:
VB.NET |
Copy Code |
---|---|
Imports Xceed.Grid.Reporting Dim report As New Report( Me.gridControl1 ) report.Export( "D:\report", ExportFormat.Jpeg, True, True ) |
C# |
Copy Code |
---|---|
using Xceed.Grid.Reporting; Report report = new Report( this.gridControl1 ); report.Export( "D:\\report", ExportFormat.Jpeg, true, true ); |
A second version of the Export method takes an additional argument of type ExportSettings (or of the derived types PdfExportSettings or ImageExportSettings). These classes let you include information such as a title, author or description in the exported file.
VB.NET |
Copy Code |
---|---|
Dim report As New Report( Me.gridControl1 ) Dim exportSettings As New ExportSettings() exportSettings.Title = "Monthly report" exportSettings.Author = "John Smith" report.Export( "D:\report.html", ExportFormat.Html, True, True, exportSettings ) |
C# |
Copy Code |
---|---|
Report report = new Report( this.gridControl1 ); ExportSettings exportSettings = new ExportSettings(); exportSettings.Title = "Monthly report"; exportSettings.Author = "John Smith"; report.Export( "D:\\report.html", ExportFormat.Html, true, true, exportSettings ); |
The PdfExportSettings class provides two additional properties: EncryptionPassword and UseCompression. EncryptionPassword is a string representing the password that is used to encrypt the PDF report being exported. UseCompression is a boolean indicating that the PDF file should be compressed.
The ImageExportSettings class provides a Resolution property, which holds an ImageExportResolution value specifying whether the image should be exported with standard, fine or super-fine resolution.
The CreatePrintDocument method returns a standard .NET PrintDocument. Using the CreatePrintDocument allows for more control over the print process but means more work.
An important property of the Report class is ReportStyleSheet. The object it references encapsulates the styles used in a report. See the Report styles and report style sheets topic for more details.