xtrareports-115726-feature-guide-to-devexpress-reports-reporting-api-create-reports-in-code.md
The following steps describe how to create a report in code:
After the report layout is complete, you have an instance of the XtraReport class descendant.
The following examples illustrate how to generate specific report types in code:
The following topics describe the report object model and events:
Once you create the XtraReport (or its descendant) instance, as described in the help topics in the previous section, you can perform the actions listed below. The XtraReport1 class mentioned in the code snippets is the XtraReport descendant.
Use the following code in a WinForms application:
using DevExpress.XtraReports.UI;
// ...
ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());
printTool.ShowPreview();
Imports DevExpress.XtraReports.UI
' ...
Dim printTool As New ReportPrintTool(New XtraReport1())
printTool.ShowPreview()
Review the following help topic for information specific to Web platforms: Document Viewer for Web.
Use the following code in a WinForms application:
using DevExpress.XtraReports.UI;
// ...
ReportDesignTool designTool = new ReportDesignTool(new XtraReport1());
designTool.ShowDesigner();
Imports DevExpress.XtraReports.UI
' ...
Dim designTool As New ReportDesignTool(New XtraReport1())
designTool.ShowDesigner()
Review the following help topic for information specific to Web platforms: End-User Report Designer for Web.
Use the following code in a WinForms application:
using DevExpress.XtraReports.UI;
// ...
ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());
printTool.PrintDialog()
Imports DevExpress.XtraReports.UI
' ...
Dim printTool As New ReportPrintTool(New XtraReport1())
printTool.PrintDialog()
Review the following help topic for information specific to Web platforms: Printing and Export in Reporting Tools for Web.
using DevExpress.XtraReports.UI;
// ...
string pdfFilePath = @"C:\Temp\Report1.pdf";
XtraReport1 report = new XtraReport1();
report.ExportToPdf(pdfFilePath);
Imports DevExpress.XtraReports.UI
' ...
Dim pdfFilePath As String = "C:\Temp\Report1.repx"
Dim report As New XtraReport1()
report.ExportToPdf(pdfFilePath)
Review the following help topic for more information: Document Export Overview.
using DevExpress.XtraReports.UI;
// ...
string reportFilePath = @"C:\Temp\Report1.repx";
string styleSheetFilePath = @"C:\Temp\ReportStyleSheet1.repss";
XtraReport1 report = new XtraReport1();
report.SaveLayoutToXml(reportFilePath);
report.StyleSheet.SaveXmlToFile(styleSheetFilePath);
Imports DevExpress.XtraReports.UI
' ...
Dim reportFilePath As String = "C:\Temp\Report1.repx"
Dim styleSheetFilePath As String = "C:\Temp\ReportStyleSheet1.repss"
Dim report As New XtraReport1()
report.SaveLayoutToXml(reportFilePath)
report.StyleSheet.SaveXmlToFile(styleSheetFilePath)
Review the following help topic for more information: Save Report Layouts.
If a runtime-generated report does not work as expected or you want to know how to implement a particular feature in code, follow these steps:
Use the report’s SaveLayoutToXml method to save the generated report as a REPX file.
Add a new report to your .NET Framework project, expand the report’s smart tag, and import the generated REPX file.
Specify the report’s data source and preview the changes.
Modify the report layout.
The XtraReport.Designer.cs or XtraReport.Designer.vb file contains code that generates the report. Use this code in your application to get a similar result.
See Also