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

Free Support Forum - aspose.com

Object sizing question in PPTX files

I have a process that creates a table in a PPTX slide but both the row count and cell content is dynamic. Is there a way to find out if the table has gone beyond the bottom of the page so that I can split it on several pages?

Hi,


Thanks for inquiring Aspose.Slides.

I like to share that Aspose.Slides does provide the facility to check the table height on run time based on contents inside the table. You can use the mechanism to identify whether the table height has spilled over the slide or not. The default slide height is 520. So, you get the table height and adds that to Y position of slide. If the resultant is more than 520, it means that text has spilled over the slide.

public static void GetTableHeight()
{

// TODO Auto-generated method stub
PresentationEx mPres = new PresentationEx();

double[] mColumnWidths = new double[2];
double[] mRowHeights = new double[8];

mColumnWidths[0] = 100;
mColumnWidths[1] = 600;

mRowHeights[0] = 10;
mRowHeights[1] = 10;
mRowHeights[2] = 10;
mRowHeights[3] = 10;
mRowHeights[4] = 10;
mRowHeights[5] = 10;
mRowHeights[6] = 10;
mRowHeights[7] = 10;

TableEx mTable = (TableEx) mPres.Slides[0].Shapes[ mPres.Slides[0].Shapes.AddTable(0, 0, mColumnWidths, mRowHeights)];
double heightBefore = mTable[0, 1].OffsetY;
double tableHeightBefore = mTable.Height;
double cellBefore = mTable[0, 0].Height;


Console.WriteLine("1: mTable.Height = " + mTable.Height);

mTable
.Rows[0][0].TextFrame.Paragraphs[0].Text= “Test Stringrhfuqerfrkejfklwergklhwejghkjerghjhergjhwerhgwerhgrwehgwehgjklehwrgjhwekljrghklweghklwerhgkljwerghkwerhgjkwerhgkwerhgkrwehgkwerhgkjerwhgkwerhgkjwerhgkewrhgkwerhgklwerhgklherwklgherklwghkwerjlghklwerjghjklerwhgkwejhgkjlwehgkwekwj”;

double heightAfter = mTable[0, 1].OffsetY;
double tableHeightAfter = mTable.Height;
double cellAfter = mTable[0, 0].Height;

Console.WriteLine("offset: " + heightBefore + ", " + heightAfter); //offset: 10.0, 10.0
Console.WriteLine("table height: " + tableHeightBefore + ", " + tableHeightAfter); //table height: 20.0, 20.0
Console.WriteLine("cell height: " + cellBefore + ", " + cellAfter); //cell height: 10.0, 10.0


mPres.Save(“D://Aspose Data//Test07.pptx”,Aspose.Slides.Export.SaveFormat.Pptx);

}

The above sample code provide the difference between table heights before and after adding text in cell.

Many Thanks,

That’s great but in your code you defined 7 rows. I dont know in advance how many rows I will need. I mean i know how many i need total but there is a good chance that the last 10 will spill over so i will need to add them to a separate slide. In this case how do i define the table? Can i create a row for each one I will possibly need and, once i reach the height limit, delete the remaining rows (that are blank)? Or is there another approach?

Hi,


What I would like to suggest you is to start with minimum number of rows. Add the new rows using RowExCollection.AddClone() method on run time and fill the content in the row. Then check the table height and if it is spilling over then move to next slide otherwise keep filling the table on current slide. I hope this will help.

Many Thanks,

Can you show some example code on detecting that your next row would flow over the slide and move that row to a new slide. I tried googling and looking at the documentation but i can’t figure out how to do this

Hi Adam,


I have observed the requirement shared and like to share that there is property table.Height gives the height of table dynamically. In order to verify that if the table has exceeded slide size or not, you may please try following approach.

float HeightToCheck=table.Y+table.Height;
if(HeightToCheck>presentationEx.SlideSize.Size.Height)
{
Console.WriteLine(“Table exceeded slide height…”);
}

Many Thanks,