Add a Table below an existing table

How can I add a table using PresentEx… please provide a PPTX sample.

Then how can I add another table just below the first

Ho Jon,


Please use the code snippet below to serve the purpose.

//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx();

//Access first slide
SlideEx sld = pres.Slides[0];

//Define columns with widths and rows with heights
double[] dblCols = { 50, 50, 50 };
double[] dblRows = { 50, 30, 30, 30, 30 };

//Add table shape to slide
int idx = sld.Shapes.AddTable(100, 0, dblCols, dblRows);
TableEx tbl = (TableEx)sld.Shapes[idx];

//Set border format for each cell
foreach (RowEx row in tbl.Rows)
foreach (CellEx cell in row)
{
cell.BorderTop.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderTop.Width = 5;

cell.BorderBottom.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderBottom.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderBottom.Width = 5;

cell.BorderLeft.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderLeft.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderLeft.Width = 5;

cell.BorderRight.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderRight.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderRight.Width = 5;
}

//Merge cells 1 & 2 of row 1
tbl.MergeCells(tbl[0, 0], tbl[1, 0], false);

//Add text to the merged cell
tbl[0, 0].TextFrame.Text = “Merged Cells”;

////////

//Define columns with widths and rows with heights
double[] dblCols2 = { 50, 50, 50 };
double[] dblRows2 = { 50, 30, 30, 30, 30 };

double sumHeight = dblRows2[0] + dblRows2[1] + dblRows2[2] + dblRows2[3] + dblRows2[4];

//Add table shape to slide
// idx = sld.Shapes.AddTable(100, 50, dblCols, dblRows);
idx = sld.Shapes.AddTable(100,( tbl.Height+10), dblCols, dblRows);

tbl = (TableEx)sld.Shapes[idx];

//Set border format for each cell
foreach (RowEx row in tbl.Rows)
foreach (CellEx cell in row)
{
cell.BorderTop.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderTop.Width = 5;

cell.BorderBottom.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderBottom.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderBottom.Width = 5;

cell.BorderLeft.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderLeft.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderLeft.Width = 5;

cell.BorderRight.FillFormat.FillType = FillTypeEx.Solid;
cell.BorderRight.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderRight.Width = 5;
}

//Merge cells 1 & 2 of row 1
tbl.MergeCells(tbl[0, 0], tbl[1, 0], false);

//Add text to the merged cell
tbl[0, 0].TextFrame.Text = “Merged Cells”;



//Write PPTX to Disk
pres.Write(“d:\Aspose Data\table.pptx”);

Many Thanks,