This example shows how to export a dashboard. First, you need to load dashboard template:
...
private StiReport GetTemplate()
{
var report = StiReport.CreateNewDashboard();
report.Load("Dashboards\\DashboardChristmas.mrt");
return report;
}
...
Next, use
ExportDocument()
method to export the dashboard to format you need:
...
private void buttonPdf_Click(object sender, EventArgs e)
{
var report = GetTemplate();
saveFileDialog.FileName = report.ReportName + ".pdf";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var stream = new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate);
report.ExportDocument(StiExportFormat.Pdf, stream);
stream.Close();
}
}
private void buttonExcel_Click(object sender, EventArgs e)
{
var report = GetTemplate();
saveFileDialog.FileName = report.ReportName + ".xlsx";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var stream = new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate);
report.ExportDocument(StiExportFormat.Excel2007, stream);
stream.Close();
}
}
private void buttonImage_Click(object sender, EventArgs e)
{
var report = GetTemplate();
saveFileDialog.FileName = report.ReportName + ".png";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var stream = new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate);
report.ExportDocument(StiExportFormat.ImagePng, stream);
stream.Close();
}
}
...
In the screenshot below you can see the result of the sample code: