This sample project shows how to export and print the report from code without using the report viewer. For this action, it is enough to use the special StiNetCoreReportResponse class that implements the methods for report exporting and printing. These methods take the input of all the necessary parameters to configure exporting and printing the report.

The special StiNetCoreReportResponse class contains methods to export report in any format and print report to PDF and HTML. For example, implementing it for one report in order to compare them. Add two links for each print mode and three links for various export formats:
<div class="row">
	<div class="col-md-4">
		<h2>Print to PDF</h2>
		<p>@Html.ActionLink("Print", "PrintPdf")</p>
	</div>
	<div class="col-md-4">
		<h2>Print to HTML</h2>
		<p>@Html.ActionLink("Print", "PrintHtml")</p>
	</div>
</div>
<hr />
<div class="row">
	<div class="col-md-4">
		<h2>Export to PDF</h2>
		<p>@Html.ActionLink("Export", "ExportPdf")</p>
	</div>
	<div class="col-md-4">
		<h2>Export to HTML</h2>
		<p>@Html.ActionLink("Export", "ExportHtml")</p>
	</div>
	<div class="col-md-4">
		<h2>Export to Excel</h2>
		<p>@Html.ActionLink("Export", "ExportXls")</p>
	</div>
</div>

To get the report, the GetReport() method was used. This method loads the report template, loads the XML data file and registers this data for loaded report:
private StiReport GetReport()
{
	var reportPath = StiNetCoreHelper.MapPath(this, "Reports/TwoSimpleLists.mrt");
	var report = new StiReport();
	report.Load(reportPath);

	return report;
}

Now we need to determine the actions that will be invoked when clicking on links. For printing we will use two action methods - PrintPdf and PrintHtml:
public IActionResult PrintPdf()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.PrintAsPdf(report);
}

public IActionResult PrintHtml()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.PrintAsHtml(report);
}

For printing, we will use three action methods - ExportPdf, ExportHtml, and ExportXls. These export formats are taken for example. Also, the methods of exporting a report (and printing) can take, as input, export settings and other necessary parameters:
public IActionResult ExportPdf()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.ResponseAsPdf(report);
}

public IActionResult ExportHtml()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.ResponseAsHtml(report);
}

public IActionResult ExportXls()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.ResponseAsXls(report);
}

На скриншоте ниже Вы можете увидеть результат выполнения данного кода:

Exporting and Printing a Report from Code

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.