How to dynamically set the number of rows in a table at runtime?

Hi…

I’m creating a table with the following:

double[] dblRows = { 30,30,30 ,30 }; // Includes Header

How can I pass in the values for dblRows… for example I want to pass in 10 rows of 30

slide.Shapes.AddTable(35, 205, dblCols, dblRows);
thanks again

Hi Jon,


I have tried to understand the requirement shared by you. I like to share that you need to set the number of rows in table while creation time, using the dblRows array used in your post. You may add entries in dblRows with 10 entries using following code line.

double[] dblRows = { 50,30,30 ,30 ,30,30 ,30,30,30 ,30}; // Includes Header

The above line will add 10 rows with header row of height 50 and rest all of height 30. Moreover, you can also add new row even the table is created using InsertClone() method of rows collection. Please observe the following code snippet to see how to add new rows on run time.


//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, 30, 30, 30, 30, 30 };
//Add table shape to slide
int idx = sld.Shapes.AddTable(100, 50, dblCols, dblRows);
TableEx tbl = (TableEx)sld.Shapes[idx];
float h = tbl.Height;
float w = tbl.Width;

//Adding new rows on run time
tbl.Rows.AddClone(tbl.Rows[0], true);
tbl.Rows.InsertClone(1,tbl.Rows[0], true);
//Write PPTX to Disk
h = tbl.Height;
w = tbl.Width;

pres.Write(“d:\Aspose Data\table.pptx”);
Many Thanks,