Articles in this section
Category / Section

How to generate reports in PowerPoint presentations for data from database in Xamarin.iOS application?

2 mins read

You can generate reports in PowerPoint presentations for the data from a 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 to the UG documentation here.

Step 1: Import data from the database to an Excel file using the 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

 

 

Excel file using XlsIO library

 

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.

 

Data Excel sheet

 

 

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 data 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 a stream
Stream stream = new FileStream("Microsoft_Excel_Worksheet.xlsx", FileMode.Open);
stream.Position = 0;
// Create a chart for the data in the Excel file within the 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 data in the Excel file within the 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 of the stream
stream.Dispose();
// Save the presentation
presentation.Save("Presentation.pptx");

///<Summary>
/// Exports the values in the DataTable 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 the 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:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/PresentationReports-1930231635.zip

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied