How to generate reports in PowerPoint presentations for data from database in WPF ?
You can generate reports in PowerPoint presentations for the data from database, using Presentation and XlsIO libraries. This can be done in Windows Forms, WPF, ASP.NET, ASP.NET MVC, UWP and Xamarin platforms. For more information about the platform-wise required assemblies, please refer the UG documentation here.
Step 1: Import data from database to an excel file using XlsIO library
The below links demonstrates importing data from a database to an excel file.
KB link: https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datatable
Step 2: Create charts and tables in a PowerPoint presentation for the data in excel sheet
The following screenshot and code example demonstrates importing data from an excel work sheet as charts and tables in a PowerPoint slide.
The below code example demonstrates creating tables and charts in a PowerPoint slide, for the data from different data-ranges of an excel sheet.
// Open presentation by using Essential Presentation.
IPresentation presentation = Presentation.Open("Sample.pptx");
int count = 0;
//Export the date from excel to Presentation
foreach (DataTable splittedDataTable in dataTables)
{
if (count == 1)
break;
ExportToPresentation(presentation, splittedDataTable);
count++;
}
//Add slide to the PowerPoint presentation
ISlide slide = presentation.Slides[0];
//Get the excel file as stream
Stream stream = new FileStream("Microsoft_Excel_Worksheet.xlsx", FileMode.Open);
stream.Position = 0;
//Create a chart for the date in excel file within A1:F6 data range
IPresentationChart columnChart = slide.Charts.AddChart(stream, 1, "A1:F6", new RectangleF(30.96F, 15.12F, 350.64F, 227.52F));
stream.Position = 0;
//Create a chart for the date in excel file within A7:D12 data range
IPresentationChart pieChart = slide.Charts.AddChart(stream, 1, "A7:D12", new RectangleF(30.96F, 289.44F, 350.64F, 227.52F));
//Set the chart type as Pie.
pieChart.ChartType = Syncfusion.OfficeChart.OfficeChartType.Pie;
//Dispose the stream
stream.Dispose();
//Save the presentation
presentation.Save("Presentation.pptx");
///<Summary>
///Exports the values in data table to PowerPoint tables.
///</Summary>
private static void ExportToPresentation(IPresentation presentation, DataTable dataTable)
{
//Add slide to the presentation document.
ISlide slide = presentation.Slides[0];
//Add table to the slide. The height of the table will grow per the content height by default
ITable table = slide.Tables.AddTable(dataTable.Rows.Count, dataTable.Columns.Count 1, 416.16, 101.28, 500.2, 165.36);
//Disable the header row property
table.HasHeaderRow = true;
int rowIndex = 0;
int colIndex = 0;
//Add data to the table in presentation from the DataTable instance
foreach (DataRow row in dataTable.Rows)
{
foreach (object val in row.ItemArray)
{
ICell cell = table[rowIndex, colIndex];
cell.TextBody.AddParagraph(val.ToString());
colIndex++;
if (colIndex == 5)
break;
}
colIndex = 0;
rowIndex++;
}
}
Sample Link:
Conclusion
I hope you enjoyed learning about how to generate reports in PowerPoint presentations for data from database in WPF.
You can refer to our WPF Presentation featuretour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Presentation example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!