使用Google App Script更改Google Doc中单元格的行间距



我有一个谷歌文档,其中有一个表,需要每周更新和内容从电子表格插入。我成功地将正确的数据粘贴到每个单元格中,但是行间距为1.15而不是单间距。

关于如何实现这一点有什么想法吗?

下面是我试过的代码:


const doc = DocumentApp.getActiveDocument();
var paddingTop = 1.5; // You can adjust the height by modifying this.
var paddingBottom = 1.5; // You can adjust the height by modifying this.
var tables = doc.getBody().getTables();
tables.forEach(table => {
for (var r = 0; r < table.getNumRows(); r++) {
var row = table.getRow(r);
for (var c = 0; c < row.getNumCells(); c++) {
row.getCell(c).setPaddingTop(paddingTop).setPaddingBottom(paddingBottom);
var p=row.getCell(c);
Logger.log(c)
for(i=0;i<p.length; i++){
p[i].setLineSpacing(100);
}
}
}
});

这不会改变单元格内的行间距。

我就是这么做的:

var paddingTop = 1.5; // You can adjust the height by modifying this.
var paddingBottom = 1.5; // You can adjust the height by modifying this.

var paraStyle = {};
paraStyle[DocumentApp.Attribute.LINE_SPACING] = 1;
var tables = doc.getBody().getTables();
tables.forEach(table => {
for (var r = 0; r < table.getNumRows(); r++) {
var row = table.getRow(r);
for (var c = 0; c < row.getNumCells(); c++) {
var cell=row.getCell(c);
cell.setPaddingTop(paddingTop)
cell.setPaddingBottom(paddingBottom);
var items = cell.getNumChildren();
for (var i = 0; i < items; i++){
var paraInCell = cell.getChild(i).asParagraph();
paraInCell.setAttributes(paraStyle);
}
}
}
});

最新更新