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

Free Support Forum - aspose.com

Set height of ITable

Hi,


I am using the latest .net slide libraries.
I have a table in presentation template and I keep on adding (cloning) rows to the table.If the table height is more than the window height, I clone the table to the next slide and add the rows.
I would like to know how do we set the height of the table? Sometimes the table has only one row and it’s height is more than the window height. I would like to set the table height to the slide height.

Here’s my part of the code:

FileStream fis = new FileStream(SlideTemplatePath, FileMode.Open, FileAccess.Read);
Presentation pres = new Presentation(fis);
int index = Utils.FindSlideIndexOfTable(pres, priorityText);//Finds the index of the slid
ITable table = Utils.findTableByAltText(pres, index);// Table for which data is added
IRow firstRow = table.Rows[1];

int rowIndex = 1;

for (int i=0;i<9;i++)
{
WriteRiskColumns(table, rowIndex, dataset);//Writes data to each column
table.Rows.AddClone(firstRow, true);
rowIndex++;
}

How do I set the height of the “table”?

Thanks,
Sharanya

Hi Sharanya,

I have observed the requirements shared by you and like to share that table height is actually sum of individual rows. It is some thing that is calculated rather than set. You need to set the table height on rows levels that will affect the over all table height. I hope this will clear the concept to you. Please also observe the following sample code for your kind reference as well.

public static void TestTableHeight()
{

float xPos = 250;
float yPos = 250;

Presentation presEx = new Presentation();
ISlide slide = presEx.Slides[0];
Table table = (Table)slide.Shapes.AddTable(xPos, yPos, new double[] { 72, 72, 144 }, new double[] { 36, 36, 36 });
// 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”);

ShapeFrame frameAfterResize = (ShapeFrame)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.Save(“D:\Aspose Data\TestTableHeight.pptx”,SaveFormat.Pptx);
}

Many Thanks,

Hi,


Thanks a lot for the quick reply. Does the concept of setting the row height apply for the existing table also? because I don’t create a new table instead access the existing table and keep on adding rows to it

My code is similar to this -
ITable table = (ITable)pres.Slides[3].Shapes[0];
WriteFirstRow();
if (table.Height > presEx.SlideSize.Size.Height)
{
table.Rows[0].MinimalHeight = 50;
}

But the table row doesn’t set its height to 50. If the row content is more, it stretches below the border.
Please help.

Thanks,
Sharanya

Hi Sharanya,

I have observed the requirements shared by you and like to share that the same concept is applicable to rows of existing tables that you are trying to access. For second part of your query regarding setting height of row that is failing on your end, I request you to please sample presentation along with source presentation.

Many Thanks,