Table manipulation

Hi,

I just want a confirmation on whether with the new version of Aspose.Slides, the size of the table will be based on the size of the context? For e.g. if my table has just two columns then it will just use the size of the two columns and if my tables has 5 column then it will use the size of the five columns. So with latest version of Aspose.Slides we don't need to fix the size of the table, it will automatically create the table based on the number of columns.? Can you share the code for this, please?

Also, Can I access the cell width and height (i.e. Can I can explicitely set the size of the table cell) in new version?

Thanks,

Mihir

Hi Mahir,


Thanks for inquiring Aspose.Slides.

I have observed the requirements shared by you. Can you please share that if you are interested in PPT or PPTX table. I assume that you are talking of PPTX table and will share my response in accordance to that. There is a property TextFrameEx.AutofitType associated with table cells text frame. If the type is defined as TextAutofitTypeEx.Shape then the table cell size will be content driven and will change w.r.t amount of text. However, when TextAutofitTypeEx.Normal is used the text will be managed with in the cell and cell size will not grow . Also, I have shared the following sample code that you can use as reference to get to know about different properties.

PresentationEx presEx = new PresentationEx();
TableEx table = (TableEx)presEx.Slides[0].Shapes[presEx.Slides[0].Shapes.AddTable(72, 72, new double[] { 72, 72, 144 },
new double[] { 36, 36, 36 })];
ShapeFrameEx frameBefore = table.Frame;
// resizing
table.Columns[0].Width += 10;
table.Rows[1].MinimalHeight += 14;
ShapeFrameEx frameAfterResize = table.Frame;
// changing content
table.Rows[0][0].TextFrame.Text = “line1\nline2”;
table.Rows[1][1].TextFrame.Text = “line1\nline2\nline3”;
ShapeFrameEx frameAfterContentChange = table.Frame;
// rendering
presEx.Slides[0].GetThumbnail(0.01f, 0.01f);
ShapeFrameEx frameAfterRender = table.Frame;
if(frameBefore.Width + 10!= frameAfterResize.Width)
Console.WriteLine(“Column width change error.”);
if(frameBefore.Height + 141!= frameAfterResize.Height)
Console.WriteLine(“Column width change error.”);
if(frameAfterResize.Height!= frameAfterContentChange.Height)
Console.WriteLine(“Error resizing on content change.”);
if(frameAfterContentChange.Height!= frameAfterRender.Height)
Console.WriteLine(“Frame content changed…”);

Many Thanks,

Hi Mudassir,

Thanks for your reply.

If at all possible can I also get the code snippet for PPT too.? Is this adjusting table size based on its content also supported in PPT version of export?

Thanks,

Mihir

Hi Mahir,


Please try using thee following sample as it may serve the purpose for you. Please share if I may help you further in this regard.

Presentation pres = new Presentation();

//Accessing a slide using its slide position
Slide slide = pres.GetSlideByPosition(1);

//Setting table parameters
int xPosition = 880;
int yPosition = 1400;
int tableWidth = 4000;
int tableHeight = 500;
int columns = 4;
int rows = 4;
double borderWidth = 2;


//Adding a new table to the slide using specified table parameters
Table table = slide.Shapes.AddTable(xPosition, yPosition, tableWidth, tableHeight,
columns, rows, borderWidth, Color.Blue);

// resizing
table.SetColumnWidth(0, 10);
table.SetRowHeight(0, 14);
int widthBefore=table.Width ;
int heightBefore=table.Height;
// changing content
table.GetCell(0, 0).TextFrame.FitShapeToText = true;
table.GetCell(0,0).TextFrame.Text = “line1\nline2”;
table.GetCell(1, 1).TextFrame.FitShapeToText = true;
table.GetCell(1, 1).TextFrame.Text = “line1\nline2\nline3”;

int widthAfter=table.Width;;
int heightAfter=table.Height;


Many Thanks,