History : - Shape size not equal to the table cell size and fit the text inside the shape
Solution was working perfectly, but i found some issues when we
How about this modification?
getSpaceAbove()
and getSpaceBelow()
, it seems that those are 0
.getLineSpacing()
might be used.When this points are reflected to your script of https://pastebin.com/keXKHbhC, it becomes as follows.
cellParaText.forEach(function(item, index) {
var t = cellParaText[index].getRange();
//i tried to applied Tanike's solution here
rowHeight = rowHeight + ( t.asString().split("\n").length - 1 ) * ( t.getTextStyle().getFontSize() / 72 * 96 )
//rowHeight = rowHeight + cellParaText[index].getRange().getTextStyle().getFontSize();
rowHeight = rowHeight + cellParaText[index].getRange().getParagraphStyle().getSpaceAbove()
rowHeight = rowHeight + cellParaText[index].getRange().getParagraphStyle().getSpaceBelow()
rowHeight = rowHeight + (cellParaText[index].getRange().getParagraphStyle().getLineSpacing()/100)
});
cellParaText.forEach(function(item, index, a) {
var t = cellParaText[index].getRange();
var lineSpace = cellParaText[index].getRange().getParagraphStyle().getLineSpacing() / 100;
var fontSize = t.getTextStyle().getFontSize() / 72 * 96;
rowHeight += fontSize * (a.length > 1 ? lineSpace : 1);
if (index == a.length - 1) rowHeight += fontSize;
});
And also, please modify as follows.
insertedShape.getText()
.getParagraphStyle()
.setLineSpacing(cellParagraph.getLineSpacing()/100)
.setSpaceAbove(cellParagraph.getSpaceAbove())
.setSpaceBelow(cellParagraph.getSpaceBelow())
.setSpacingMode(cellParagraph.getSpacingMode())
.setParagraphAlignment(cellParagraph.getParagraphAlignment())
insertedShape.getText()
.getParagraphStyle()
.setParagraphAlignment(cellParagraph.getParagraphAlignment())
When your sample Google Slides is used with above modified script, it becomes as follows.