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);
break;
case "Word":
report.ExportDocument(StiExportFormat.Word2007, stream);
break;
case "Excel":
report.ExportDocument(StiExportFormat.Excel2007, stream);
break;
case "Text":
report.ExportDocument(StiExportFormat.Text, stream);
break;
case "Image":
report.ExportDocument(StiExportFormat.ImagePng, stream);
break;
}
MessageBox.Show("The export action is complete.", "Export Report");
}
На скриншоте ниже Вы можете увидеть результат выполнения данного кода: