We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

AddColumn/AddRow dynamically in pptx slides

Hi Aspose

As my requirement i have to create tables in slide with dynamic no. of rows and columns which depends on my datatable. This thing was easy in doing with Power Point 2003 but in Power Point 2007 i am not getting the way to achieve my requirement.

Through the below example code which is in your Demo, i am not able to achieve my requirement

//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, 50, 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;

}

Beacause while creating table i can not specify no. of rows/columns as it is dynamic in my case.

Please suggest me how to do it ASAP.

Thanks a lot.

Waiting for your reply.

Hi Binod,

Thanks for your interest in Aspose.Slides.

We regret to inform you that you can set the number of rows or columns using arrays of columns and rows containing width and height of each of the cells respectively which is unlike in case of PPT tables, whereby you could not set the number of rows and columns without mentioning each cell height and width. As a work around you can add rows dynamically using AddClone() and InsertClone() methods. Please use the following code snippet to accomplish the task.

//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, 50, dblCols, dblRows);

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

//Getting all rows in table

RowsEx Rows = Tbl.Rows;

// we will use second row of the table as template

RowEx Row = Rows[1];

// add new row at the end of the table

Rows.AddClone(row, false);

//There is also InsertClone method where you can specify position of the new row:

Rows.InsertClone(2, row, false); // 2 is row index

Thanks and Regards,