This example shows how to export a report from code. First, load scripts:
@using Stimulsoft.Base
@using Stimulsoft.Report
@using Stimulsoft.Report.Web
@using Stimulsoft.Report.Blazor
Next, create buttons:
<div align="center">
<button @onclick="ExportReportAsHTML">Export as HTML</button>
<button @onclick="ExportReportAsPDF">Export as PDF</button>
<br /><br />
<p>@message</p>
</div>
After that, initialize JSRuntime service:
@code
{
private MarkupString message;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
//Initialize JSRuntime service
StiBlazorHelper.Initialize(JSRuntime);
}
...
Then, use
ResponseAs
method to export report:
...
private async Task ExportReportAsHTML()
{
message = new MarkupString("Processing...");
//Create empty report object
var report = new StiReport();
//Load report template
var reportBytes = await Http.GetByteArrayAsync("Reports/TwoSimpleLists.mrt");
report.Load(reportBytes);
//Render, without showing progress
report.Render(false);
//Response as HMTL file
StiReportResponse.ResponseAsHtml(report);
message = new MarkupString("Export to HTML is completed.");
}
private async Task ExportReportAsPDF()
{
message = new MarkupString("Processing...");
//Create empty report object
var report = new StiReport();
//Load report template
var reportBytes = await Http.GetByteArrayAsync("Reports/TwoSimpleLists.mrt");
report.Load(reportBytes);
//Render, without showing progress
report.Render(false);
//Response as PDF file
StiReportResponse.ResponseAsPdf(report);
message = new MarkupString("Export to PDF is completed.");
}
}
Auf dem Screenshot unten Sie können das Ergebnis des Beispiel-Codes ansehen: