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)
{
var report = new StiReport();
report.Load(@"Reports\TwoSimpleLists.mrt");
report.Render();
...
Then, select the file format to which you want to export the report:
...
var stream = new MemoryStream();
switch (((Label)ComboBoxFormat.SelectedItem).Content)
{
case "PDF":
report.ExportDocument(StiExportFormat.Pdf, stream);
saveFileDialog.DefaultExt = ".pdf";
break;
case "Word":
report.ExportDocument(StiExportFormat.Word2007, stream);
saveFileDialog.DefaultExt = ".docx";
break;
case "Excel":
report.ExportDocument(StiExportFormat.Excel2007, stream);
saveFileDialog.DefaultExt = ".xlsx";
break;
case "Text":
report.ExportDocument(StiExportFormat.Text, stream);
saveFileDialog.DefaultExt = ".txt";
break;
case "Image":
report.ExportDocument(StiExportFormat.ImagePng, stream);
saveFileDialog.DefaultExt = ".png";
break;
}
saveFileDialog.FileName = report.ReportName;
if (saveFileDialog.ShowDialog() == true)
{
// Save to Local Storage
using (var fileStream = File.Create(saveFileDialog.FileName))
{
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
}
}
MessageBox.Show("The export action is complete.", "Export Report");
}
In the screenshot below you can see the result of the sample code: