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:
private void buttonExport_Click(object sender, EventArgs 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 (comboBoxFormat.Text)
	{
		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() == DialogResult.OK)
{
	// 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");

Auf dem Screenshot unten Sie können das Ergebnis des Beispiel-Codes ansehen:

Exporting a Report from Code

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.