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

Free Support Forum - aspose.com

PresentationEx Table Height

Hi,

I tried the following code, but the table height is not getting set.

PresentationEx pres = new PresentationEx();

//Access first slide

SlideEx sld = pres.getSlides().get_Item(0);

//Define columns with widths and rows with heights

double[] dblCols = { 50,50,50 };

double[] dblRows = { 50,30,30,30,30 };

//Add table shape to slide

int idx = sld.getShapes().addTable(100, 50, dblCols, dblRows);

TableEx tbl = (TableEx)sld.getShapes().get_Item(idx);

System.out.println(tbl.getHeight());

tbl.setHeight(400f);

System.out.println(tbl.getHeight());

pres.write("D:\\Reports\\TableHeight.pptx");

Regards,

Kiran.

Hi Kiran,


I like to share that the table width or height is collective property and is sum of all columns widths or rows heights respectively. You need to set the minimum row height for each row that will accumaulate in table height. Please use the following sample code to serve the purpose and share with us if there is any issue.


public static void GetTableHeight() throws Exception
{
// 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
.getSlides()
.get(0)
.getShapes()
.get(
mPres.getSlides().get(0).getShapes()
.addTable(0, 0, mColumnWidths, mRowHeights));
final double heightBefore = mTable.get(0, 1).getOffsetY();
final double tableHeightBefore = mTable.getHeight();
final double cellBefore = mTable.get(0, 0).getHeight();


System.out.println("1: mTable.getHeight() = " + mTable.getHeight());

mTable
.getRows()
.get(0)
.get(0)
.getTextFrame()
.getParagraphs()
.get(0)
.setText(
“Test Stringrhfuqerfrkejfklwergklhwejghkjerghjhergjhwerhgwerhgrwehgwehgjklehwrgjhwekljrghklweghklwerhgkljwerghkwerhgjkwerhgkwerhgkrwehgkwerhgkjerwhgkwerhgkjwerhgkewrhgkwerhgklwerhgklherwklgherklwghkwerjlghklwerjghjklerwhgkwejhgkjlwehgkwekwj”);

/
mTable
.getRows()
.get(0)
.get(0)
.getTextFrame()
.setText(
“Test Stringrhfuqerfrkejfklwergklhwejghkjerghjhergjhwerhgwerhgrwehgwehgjklehwrgjhwekljrghklweghklwerhgkljwerghkwerhgjkwerhgkwerhgkrwehgkwerhgkjerwhgkwerhgkjwerhgkewrhgkwerhgklwerhgklherwklgherklwghkwerjlghklwerjghjklerwhgkwejhgkjlwehgkwekwj”);
/
final double heightAfter = mTable.get(0, 1).getOffsetY();
final double tableHeightAfter = mTable.getHeight();
final double cellAfter = mTable.get(0, 0).getHeight();

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


mPres.save(“D://Aspose Data//Test07.pptx”, com.aspose.slides.export.SaveFormat.PPTX);
}

Many Thanks,