Export Reports from Code

This sample project demonstrates how to export reports to the necessary format from code. The sample represents an export to popular formats, if you need you can use any other exports in the same scenario. First, load the report you want to export, and render it with the WPF engine:

private void buttonExport_Click(object sender, RoutedEventArgs e)
{
StiReport report = new StiReport();
report.RegData(dataSet1);

report.Load("..\\" + ((ListBoxItem)lbReports.SelectedItem).Content as string + ".mrt");
report.RenderWithWpf(false);
...


Then, select the file format to which you want to export the report:

...
string file = ((ListBoxItem)lbReports.SelectedItem).Content as string + ".";

if (rbPdf.IsChecked.GetValueOrDefault())
{
file += "pdf";
report.ExportDocument(StiExportFormat.Pdf, file);
System.Diagnostics.Process.Start(file);
}
else if (rbHtml.IsChecked.GetValueOrDefault())
{
file += "html";
report.ExportDocument(StiExportFormat.HtmlTable, file);
System.Diagnostics.Process.Start(file);
}
else if (rbXls.IsChecked.GetValueOrDefault())
{
file += "xls";
report.ExportDocument(StiExportFormat.Excel, file);
System.Diagnostics.Process.Start(file);
}
else if (rbTxt.IsChecked.GetValueOrDefault())
{
file += "txt";
report.ExportDocument(StiExportFormat.Text, file);
System.Diagnostics.Process.Start(file);
}
else if (rbRtf.IsChecked.GetValueOrDefault())
{
file += "rtf";
report.ExportDocument(StiExportFormat.RtfTable, file);
System.Diagnostics.Process.Start(file);
}
}


In the screenshot below you can see the result of the sample code.

Export Reports