Today, we will analyze in detail the process of exporting a dashboard and its elements from code. Additionally, we will discuss the available export formats, starting with them.

Available export formats

Our products provide a range of export formats for applications written on different platforms. For instance, in JavaScript and PHP applications, you can export a dashboard or its element to HTML, MS Excel, and PDF. For other platforms, there is the option to export to various image formats, including PNG, JPEG, SVG, BMP, and more. Additionally, all our products offer the capability to export dashboards to data files such as JSON, XML, CSV, and others.

Exporting a dashboard to WIN/WPF applications

To export the rendered dashboard from a Windows application, simply use the following code snippet:
private void Button1_Click(object sender, EventArgs e)
{
	var report = StiReport.CreateNewDashboard();
	report.Load("Reports\\Vehicle_Production.mrt");

	report.ExportDocument(StiExportFormat.Pdf, "Vehicle_Production.pdf");
}
In this sample, the export will be performed in PDF format and saved to the specified file. The ExportDocument method exports the entire dashboard to the specified format, and the result can be a file, stream, or byte array.

To modify export settings, simply pass the settings class as arguments to the specified method:
private void Button1_Click(object sender, EventArgs e)
{
	var report = StiReport.CreateNewDashboard();
	report.Load("Reports\\Vehicle_Production.mrt");

	var settings = new StiPdfDashboardExportSettings();
	report.ExportDocument(StiExportFormat.Pdf, "Vehicle_Production.pdf", settings);
}

Exporting a dashboard to Web applications

To export a dashboard from code in a Web application, you can use the same method as described above for Windows applications. However, in this case, the exported dashboard will be saved on the server side.

If you wish to load the exported dashboard onto the client computer using a web browser, you will need to use the following code (here is a sample for an ASP.NET application):
protected void ButtonExport_Click(object sender, EventArgs e)
{
	var report = StiReport.CreateNewDashboard();
	var path = Server.MapPath("Reports/Vehicle_Production.mrt");
	report.Load(path);

	StiReportResponse.ResponseAsPdf(report);
}
The StiReportResponse class contains all the necessary methods for exporting a dashboard to various formats. Export settings can be passed as arguments.

For Web applications developed using ASP.NET MVC, the StiMvcReportResponse class is provided; for .NET Core-based Web applications, the StiNetCoreReportResponse class is available. These classes share the same set of methods.

Exporting a dashboard element

A situation may arise in which you need to export only a part of the dashboard, a specific element of it. Here is a code sample for exporting a dashboard table:
private void Button1_Click(object sender, EventArgs e)
{
	var report = StiReport.CreateNewDashboard();
	report.Load("Reports\\Vehicle_Production.mrt");

	var element = report.GetComponentByName("TableList") as IStiElement;
	var settings = new StiPdfDashboardExportSettings();
	//var stream = StiDashboardExportTools.ExportToStream(element, settings);
	StiDashboardExportTools.ExportToFile(element, "d:\TableList.pdf", settings);
}
In this example, an element is selected from a dashboard by its name and exported to a file in PDF. In this case, the export format depends on the settings passed to the dashboard element export method. Additionally, the StiDashboardExportTools class contains methods for exporting to a stream or byte array. Note!

When exporting a single dashboard element containing many rows of information, such as a table or list, all rows of the element will be expanded entirely into as many pages as required. When exporting the entire dashboard, as many rows will be displayed as fit into the dashboard layout, fitting on one page of the specified size.
By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.