How to detect if it is end of slide while writing tabular data

Dear Support team,

I have a requirement to write tabular data to SlideEx but the due to large number of rows it overflows the slide area.

Can you please point me to a sample that kind of shows how to detect overflows and insert new slides.

I came across this - Aspose Slides - Detecting Text Overflow

but was wondering if there is another way, as the above is an old link.

Regards,
Varun

Hi Varun,


Thanks for inquiring Aspose.Slides.

I like to share that Aspose.Slides allows to set the minimal row height and it will grow further based on content inside the row. If you set the text auto fit type for cell text using TextFrameEx.AutofitType to Shape then as you will add the text Shape size will be changed to fit the text. However, for AutofitType Normal, the size of text will be changed to accommodate within the shape. In this case the minimal row height of 28 will be set atleast and one can not go beyond that.

So, as the text will populate in the table cells, the row height will dynamically changed and will thus effect the table height. This way you can check the table height and see if it exceeds slide area or not. Please visit this thread link for your convenience. For your further knowledge, please also refer this thread link.

Many Thanks,

Hi Mudassir,

Can you please give me a sample code that calculates table height and the slide area.

I want to calculate table height using dynamic sized rows and then compare to slide height.

Thanks,
Varun




Hi Varun,


I have created the sample code for your convenience. Please use the following sample code to serve the purpose. Please share, if I may help you further in this regard.

public static void TestTableHeight()
{

float xPos = 250;
float yPos = 250;

PresentationEx presEx = new PresentationEx();
TableEx table = (TableEx)presEx.Slides[0].Shapes[presEx.Slides[0].Shapes.AddTable(xPos, yPos, 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;

float tableHeightBefore, tableWidthBefore, tableHeightAfter, tableWidthAfter;

tableHeightBefore = table.Height;
tableWidthBefore = table.Width;

//Defautlt slide size is 720 x 540. So height is 540 max

if (tableHeightBefore + yPos <=presEx.SlideSize.Size.Height)
Console.WriteLine(“Table Height on Slide : " + (tableHeightBefore + yPos).ToString() + " and is not over flowing the slide”);
else
Console.WriteLine(“Table Height on Slide : " + (tableHeightBefore + yPos).ToString() + " and is over flowing the slide”);

ShapeFrameEx frameAfterResize = table.Frame;
// changing content
table.Rows[0][0].TextFrame.Text = “line1\nline2\nline3\nline4\nline5\nline6”;
table.Rows[1][1].TextFrame.Text = “line1\nline2\nline3\nline4\nline5\nline6”;


tableHeightAfter = table.Height;
tableWidthAfter = table.Width;

//Defautlt slide size is 720 x 540. So height is 540 max

if (tableHeightAfter + yPos <= presEx.SlideSize.Size.Height)
Console.WriteLine(“Table Height on Slide : " + (tableHeightAfter + yPos).ToString() + " and is not over flowing the slide”);
else
Console.WriteLine(“Table Height on Slide : " + (tableHeightAfter + yPos).ToString() + " and is over flowing the slide”);

presEx.Write(“D:\Aspose Data\TestTableHeight.pptx”);
}

Many Thanks,

Thanks Mudassir, looks very promising.

I’ll definitely post my findings back here.

Best,
-Varun

Hi Varun,


I hope the code shared will serve the purpose for you. If there is still an issue then please share the feedback with us.

Many Thanks,