You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Diogo Luzzardi de Carvalho <di...@gmail.com> on 2017/03/24 18:37:53 UTC

Problem with HSLFTable row height

Hi,

There is an strange problem happen to me when I use table.setRowHeight();

I'm doing the following code:

double x = 0d;
double y = 100d;
HSLFTable table = slide.createTable(1, 1);
HSLFTableCell cell = table.getCell(0, 0);

cell.setText("Some Dynamic unknown size text");

HSLFTextParagraph paragraph = cell.getTextParagraphs().get(0);
paragraph.getTextRuns().get(0).setFontSize(9);

table.setColumnWidth(0, 119);
table.setRowHeight(0, 20);

y += table.getRowHeight(0);
table.moveTo(x, y);

The strange is that the table.getRowHeight(0) is returning 27 as a result
and when I open the ppt file the table has 1.6cm of height. With this I
can't correct move the table to the position that I want. I also tried to
get the value for the y variable using table.getAnchor().getMaxY() but the
result is also 27.

Has I need to create several tables with different number of columns I need
to get the correct value to sum in the y variable to be able to set the
correct position for my tables.

Could any one give me the correct directions to solve my problem?

Best regards
-- 
*Diogo Luzzardi de Carvalho*

*Systems Analyst and Java Developer*

Re: Problem with HSLFTable row height

Posted by Andreas Beeker <ki...@apache.org>.
Hi,

sorry for not answering earlier ...

> The strange is that the table.getRowHeight(0) is returning 27 as a result
> and when I open the ppt file the table has 1.6cm of height. 
the setRowHeight method can't be used to set a height less than necessary to display the cell text.
I've noticed that HSLF is scaling the given points to pixels, opposed to what is written in the javadocs.
Although I regard this as a bug, I'm not sure if I should silently change the implementation or
introduce another (named) method with the correct behavior.

if you need the height in centimeters you can use the following:
        double heightInPoints = table.getRowHeight(0);
        double heightInCm = heightInPoints * Units.EMU_PER_POINT / Units.EMU_PER_CENTIMETER;

> With this I can't correct move the table to the position that I want.
Depending on the text I get correct calculated bounding boxes for the cells.
Please describe a bit more, what you are trying to achieve with the row heights.

Best wishes,
Andi