Skip to content Skip to sidebar Skip to footer

Shape Size Not Equal To The Table Cell Size And Fit The Text Inside The Shape

Trying to insert a shape equal to the table cell size. I created the shape using InsertShape() and copied the height of row (possibly height of cell), width of column (possibly wid

Solution 1:

From your additional information, I could confirm your situation. When I saw it, I could notice that the table has one cell, and the table size is the default size. In this case, the table uses the default row height of the cell. And the height of cell is automatically set by the inputted texts. By this, the row height is only one row which is the height of 381000 EMU (30 pixels). About this situation, I confirmed that the same results were obtained from both Slides service and Slides API. So it seems that this is the current specification.

When you want to retrieve the actual height, in the current stage, I think that it is required to set the height by manual or script and retrieve the height. By this, the table is the actual row height.

Or, although this is not the completely same with the row height of the default table including the texts, I think that the row height can be also calculated using the line breaks and the font size. In this answer, I introduce the sample script for this by modifying your script.

Sample modification:

In order to give the height, as a sample modification, I would like to propose the following script. When your script is modified, it becomes as follows.

From:
var rowHeight = pageElements[0].asTable().getRow(0).getMinimumHeight();
To:
var t = pageElements[0].asTable().getRow(0).getCell(0).getText();
var rowHeight = (t.asString().split("\n").length - 1) * (t.getTextStyle().getFontSize() / 72 * 96);
  • In this modification, the row height is calculated using the line breaks and the font size.
    • t.asString().split("\n").length - 1 is the number of line breaks.
    • t.getTextStyle().getFontSize() / 72 * 96 is the pixel value of the font size. It seems that in Google Slides, 96 DPI is used.
    • But, unfortunately, in the current stage, the result is not the completely same with the default table row height.
    • In this case, when rowHeight is multiplied by 1.08, the same height is obtained. But this factor is unfounded. Please be careful this.

Post a Comment for "Shape Size Not Equal To The Table Cell Size And Fit The Text Inside The Shape"