![](/img/trans.png)
[英]How can I set the background color of a row in a table using google apps script in Google Docs?
[英]Set “Left Indent” for a table in Google Docs using Google Apps Script
我们可以通过右键单击表格并选择“表格属性”来手动设置 Google Docs 中表格的左缩进:
我试图通过设置INDENT_FIRST_LINE
和INDENT_START
属性来使用 Google Apps 脚本实现相同的INDENT_FIRST_LINE
,但对表没有影响:
var style = {};
style[DocumentApp.Attribute.INDENT_FIRST_LINE] = 72;
style[DocumentApp.Attribute.INDENT_START] = 72;
body.insertTable(elementIndex, table).setAttributes(style);
如何使用 Google Apps 脚本为表设置相同的属性? 有没有其他方法可以实现相同的目标?
请在此问题上加注星标,以便 Google 团队优先处理:
由于 Apps Script 不提供此功能。 我最终做了以下事情:
以下是上述算法的示例脚本:
var insertTableWithIndentation = function(body,
document,
originalTable,
elementIndex,
nestingLevel) {
var docWidth = (document.getPageWidth() -
document.getMarginLeft() -
document.getMarginRight());
var table = body.insertTable(elementIndex);
var attrs = table.getAttributes();
attrs['BORDER_WIDTH'] = 0;
table.setAttributes(attrs);
var row = table.appendTableRow();
var column1Width = (nestingLevel+1) * 36;
row.appendTableCell().setWidth(column1Width);
var cell = row.appendTableCell();
var column2Width = docWidth - column1Width;
cell.setPaddingTop(0)
.setPaddingBottom(0)
.setPaddingLeft(0)
.setPaddingRight(0)
.setWidth(column2Width);
cell.insertTable(0, originalTable);
}
我来这里是为了寻找如何设置信封。 以下对我有用:在附加段落之后设置MarginLeft是关键。
const env = DocumentApp.create('Envelope');
let body = env.getBody();
body.setPageHeight(420);
body.setPageWidth(600);
for(let i = 1; i< 10; i += 1){
body.appendParagraph('');
}
body.appendParagraph('Name');
body.appendParagraph('Address');
body.appendParagraph('Address');
body.appendParagraph('City, State, Zip');
body.setMarginLeft(300);
另一种解决方案是使用 setIndentFirstLine ,如:
par = body.appendParagraph('City, State, Zip');
par.setIndentFirstLine(20);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.