Free Support Forum - aspose.com

Slides table height

Hi,

I'm trying to create 2 tables in a slide.

My first table consists of dynamic rows. I've set the row.height for each row, however each row height could be bigger due to long text in the cells. My second table is created right below the first table. In order for the second table not to overlap with the first table, i set the Y position of the second table = firsttable.Height + firsttbale.Y + 200

Sadly this doesn't work. I suspect the table height I've got is number of rows * row.height. But my problem is, each row height is not fix due to long text per cell.

How can I get the actual height of the first table?

Regards,

Dawn

Dear Dawn,

Thank for using Aspose.Slides.

I have checked on Aspose.Slides 2.7.5.0, Table.Height is updated, whenever the height of table changes because of adding new row or adding more text in the existing row. Therefore the second table is drifted down according to the first table height and does not overlap.

You should add the second table only when you finish working with the first.

Please provide me your source code and sample output presentation to let me check, where the problem is. Also mention the version number of Aspose.Slides.

Hi,

I'm using version 2.7.3.0. Is that why the table height is not working?

Regards,

Dawn

Probably yes, please try it and let me know. If the problem occurs again, then provide me your source code and also source presentation(s) if any. You can download the Aspose.Slides 2.7.5.0 from here.

http://www.aspose.com/Community/Files/51/aspose.slides/default.aspx

Nope it's not working :(

My code is below

------------------------------------------------

if (ds.Tables[0].Rows.Count > 0)

{

Slide emailPerformanceSlide = pres.CloneSlide(slide, pres.Slides.Count + 1);

// set title, find the Alt text in the slide

Rectangle rectTitle = (Rectangle)emailPerformanceSlide.FindShape("Title");

TextFrame txtFrameTitle = rectTitle.TextFrame;

txtFrameTitle.Text = "eDM Performance";

//Setting table parameters

int xPosition = 200;

int yPosition = 900;

int tableWidth = 5000;

int tableHeight = 500;

int columns = 9;

int rows = 1;

double borderWidth = 1;

//Adding a new table to the slide

Table table = emailPerformanceSlide.Shapes.AddTable(xPosition, yPosition, tableWidth,

tableHeight, columns, rows, borderWidth, System.Drawing.Color.Black);

table.AlternativeText = "EmailTable";

// set header here

.........................

foreach(DataRow dr in ds.Tables[0].Rows)

{

table.AddRow();

// set row data here

.........................

}

table.AddRow();

// total row here

.........................

//Setting second table parameters

xPosition = 1000;

yPosition = table.Height + table.Y + 200;

tableWidth = 3500;

tableHeight = 15;

columns = 4;

rows = 2;

borderWidth = 1;

//Adding a new table to the slide

Table tableUndelivered = emailPerformanceSlide.Shapes.AddTable(xPosition, yPosition, tableWidth,

tableHeight, columns, rows, borderWidth, System.Drawing.Color.Black);

tableUndelivered.AlternativeText = "UndeliveredTable";

tableUndelivered.SetRowHeight(0, 15);

// set second table header and row here

.........................

}

I have run your code after making it run able as a console application, which is attached, as you can see, first and second table do not overlap and table height is updated.

When you will run the application, it will ask you to enter the number of rows present in your ds structure, and then it will run rest of your code and generate the output presentation on C: drive.

Below is your code with my modifications which are enclosed in

//-----start my code

//-----end my code

Code:

//-----start my code

Presentation pres = new Presentation();

Slide slide = pres.AddTitleSlide();

slide.Shapes[0].AlternativeText = "Title";

Console.Write("Enter the number of rows in ds table: ");

int RowsCount = Int32.Parse(Console.ReadLine());

Console.WriteLine("Please wait... ");

if (RowsCount > 0)

{

//-----end my code

Slide emailPerformanceSlide = pres.CloneSlide(slide, pres.Slides.Count + 1);

// set title, find the Alt text in the slide

Aspose.Slides.Rectangle rectTitle = (Aspose.Slides.Rectangle)emailPerformanceSlide.FindShape("Title");

TextFrame txtFrameTitle = rectTitle.TextFrame;

txtFrameTitle.Text = "eDM Performance";

//Setting table parameters

int xPosition = 200;

int yPosition = 900;

int tableWidth = 5000;

int tableHeight = 500;

int columns = 9;

int rows = 1;

double borderWidth = 1;

//Adding a new table to the slide

Table table = emailPerformanceSlide.Shapes.AddTable(xPosition, yPosition, tableWidth,

tableHeight, columns, rows, borderWidth, System.Drawing.Color.Black);

table.AlternativeText = "EmailTable";

//----start my code

//set header here

for (int i = 0; i < RowsCount; i++)

//foreach(DataRow dr in ds.Tables[0].Rows)

//----end my code

{

table.AddRow();

// set row data here

}

table.AddRow();

// total row here

//Setting second table parameters

xPosition = 1000;

yPosition = table.Height + table.Y + 200;

tableWidth = 3500;

tableHeight = 15;

columns = 4;

rows = 2;

borderWidth = 1;

//Adding a new table to the slide

Table tableUndelivered = emailPerformanceSlide.Shapes.AddTable(xPosition, yPosition, tableWidth,

tableHeight, columns, rows, borderWidth, System.Drawing.Color.Black);

tableUndelivered.AlternativeText = "UndeliveredTable";

tableUndelivered.SetRowHeight(0, 15);

}

//----start my code

pres.Write("c:\\outTbl.ppt");

Console.Write("Output presentation created C:\\outTbl.ppt\n\nPress any key to continue...");

Console.ReadKey();

//----end my code