Welcome to OpenXML Developer Sign in | Join | Help

Create Table in Slide Dynamically

Last post 10-22-2008, 4:33 PM by jasonp. 1 replies.
Sort Posts: Previous Next
  •  09-29-2008, 1:44 PM 3745

    Create Table in Slide Dynamically

    Can someone help me out with an example of how to add data to a table in a slide.   The PowerPoint slide currently has a table in which I will populate with data from a database/xml file at runtime.

  •  10-22-2008, 4:33 PM 3819 in reply to 3745

    Re: Create Table in Slide Dynamically

    Not much going on in this forum.   I found out how to add data to a table in a slide so I figured I would share with the group...

    Basically I have a template with a table already created on the slide.   I need a way to select the table at run time and update the contents.   Probably a more elegant way of doing it but it serves the purpose for me.   now I need to change the background of the cell during runtime or change the font color.   Any ideas?

     

    a.Table table = frame.Graphic.GraphicData.GetFirstChild<a.Table>();

    var rows = table.Elements<a.TableRow>();

    int sumOfDataPoints = dataPoints.Sum(countSum => countSum.Cnt);

    foreach (var row in rows)

    {

    if (i > 0)

    {

    j = 0;

    foreach (var cell in row.Elements<a.TableCell>())

    {

    foreach (var body in cell.Elements<a.TextBody>())

    {

    foreach (var p in body.Elements<a.Paragraph>())

    {

    foreach (var r in p.Elements<a.Run>())

    {

    foreach (var t in r.Elements<a.Text>())

    {

    j = j + 1;

    //t.Text = "Row " + i + ", Column " + j + " = " + rnd.Next(5, 25).ToString();

    if (j == 1)

    {

    try

    {

    t.Text = dataPoints[i - 1].Answer;

    }

    catch

    {

    }

    }

    else

    {

    try

    {

    int answerVal = dataPoints[i - 1].Cnt;

    decimal percentage = decimal.Divide(answerVal, sumOfDataPoints) * 100;

    t.Text = percentage.ToString("0.0")+ "%";

    }

    catch

    {

    }

    }

    }

    }

    }

    }

    }

    }

    i = i + 1;

View as RSS news feed in XML