vcl-dxreport-dot-tdxreport-dot-exporttoimage-x28-system-dot-classes-dot-tstream-x29.md
Exports report content to a stream in the current image export format (selected using the Report Designer dialog).
The default image export format is PNG (Portable Network Graphics).
procedure ExportToImage(AStream: TStream);
| Name | Type | Description |
|---|---|---|
| AStream | TStream |
The target stream.
|
Call the ExportToImage procedure to export report content to a stream in the current image format.
The default image export format is Portable Network Graphics (PNG).
You can select any supported image format and configure its settings in the Report Designer dialog ( Behavior | Export Options ):
The following code example loads an XML-based report template (TdxReport.Layout) from a REPX file, populates the template with test data defined in a connection string, and exports the resulting report as a PNG image:
uses
dxReport, // Declares the TdxReport component and related types
dxBackend.ConnectionString.JSON; // Declares the TdxBackendInMemoryJSONConnection component
// ...
procedure TMyForm.Button1Click(Sender: TObject);
var
AJSONDataConnection: TdxBackendInMemoryJSONConnection;
AReport: TdxReport;
AFileStream: TFileStream;
begin
AJSONDataConnection := TdxBackendInMemoryJSONConnection.Create(Self);
try
AJSONDataConnection.Name := 'JSONData';
// Specify in-memory report data as a connection string
AJSONDataConnection.ConnectionString :=
'Json=''[{"id":1, "caption":"test1"},{"id":2, "caption":"test2"}]''';
AReport := TdxReport.Create(Self);
try
AReport.ReportName := 'Report';
AReport.Layout.LoadFromFile('Report.repx'); // Loads a report template
AFileStream := TFileStream.Create('Report.png', fmOpenReadWrite);
try
AReport.ExportToImage(AFileStream); // Exports the report in the default image export format (PNG)
finally
AFileStream.Free;
end;
finally
AReport.Free;
end;
finally
AJSONDataConnection.Free;
end;
end;
#include "dxReport.hpp" // Declares the TdxReport component
#include "dxBackend.ConnectionString.JSON.hpp" // Declares the TdxBackendInMemoryJSONConnection component
// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxReport" // Required for dxReport.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.JSON.hpp declarations
#pragma link "dxBackend.ConnectionString.JSON.o"
#else
#pragma link "dxBackend.ConnectionString.JSON.obj"
// ...
void __fastcall TMyForm::Button1Click(TObject *Sender)
{
TdxBackendInMemoryJSONConnection *AJSONDataConnection;
TdxReport *AReport;
TFileStream *AFileStream;
AJSONDataConnection = new TdxBackendInMemoryJSONConnection(this);
try
{
AJSONDataConnection->Name = "JSONData";
// Specify in-memory report data as a connection string
AJSONDataConnection->ConnectionString =
"Json=\"\"[{\"id\":1, \"caption\":\"test1\"}, {\"id\":2, \"caption\":\"test2\"}]\"";
AReport = new TdxReport(this);
try
{
AReport->ReportName = "Report";
AReport->Layout->LoadFromFile("Report.repx"); // Loads a report template
AFileStream = new TFileStream('Report.png', fmOpenReadWrite);
try
{
AReport->ExportToImage(AFileStream); // Exports the report in the default image export format (PNG)
}
__finally
{
delete AFileStream;
}
}
__finally
{
delete AReport;
}
}
__finally
{
delete AJSONDataConnection;
}
}
To see the report export functionality in action, run the Report Designer/Viewer demo in the VCL Demo Center installed with compiled DevExpress VCL demos. Select any demo in the sidebar on the left, click the Export button, and use any export option listed in the menu.
Tip
You can find full source code for the installed compiled Report demo in the following folder:
_%PUBLIC%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressReports_
You can call the following procedures to export report content to a stream in other formats:
ExportToExports report content to a stream in any supported format.ExportToCSVExports report content to a stream in the comma-separated values (CSV) format.ExportToDOCXExports report content to a stream as an Office OpenXML (DOCX) document.ExportToHTMLExports report content to a stream as an HTML document.ExportToMHTExports report content to a stream as a MIME HTML (MHT) document.ExportToPDFExports report content to a stream in PDF format.ExportToRTFExports report content to a stream as an RTF-formatted string.ExportToTextExports report content to a stream as plain text.ExportToXLSExports report content to a stream in Microsoft Excel® binary format (XLS).ExportToXLSXExports report content to a stream in Office Open XML spreadsheet format (XLSX). See Also
TdxCustomDashboardControl.ExportToPNG Procedure