使用 Apps 脚本在 Google 文档中格式化 table
Formatting a table in Google Doc using Apps Script
我有一个包含 table 的文档,其中 3 列包含名字,还有很多行。如何设置列宽和行高的格式以匹配打印名称标签的模板?
我试过了,但行不通 - 缺少什么?
var doc = DocumentApp.getActiveDocument().getBody();
// needs something to specify it's a table?
doc.setColumnWidth(1,20);
您需要在修改前获取 table。
这将取决于您的数据设置方式,但您可以尝试的一件事是将所有 table 放入 Document
.
function myFunction() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var tables = body.getTables();
Logger.log(tables);
for(var i =0; i< tables.length; i++){
var table = tables[i];
table.setColumnWidth(1, 20);
}
}
先用getActiveDocument()
and after that the Body
得到Document
。
使用 Body
有一种方法可以使用 getTables()
. That would give you an array of Table
获取所有 table。在 class 中有几种方法可以用来制作你想要的 table。如果没有更多关于您希望您的 table 如何结束的指示,则取决于您在 Table
class.
中使用什么方法
我有一个包含 table 的文档,其中 3 列包含名字,还有很多行。如何设置列宽和行高的格式以匹配打印名称标签的模板?
我试过了,但行不通 - 缺少什么?
var doc = DocumentApp.getActiveDocument().getBody();
// needs something to specify it's a table?
doc.setColumnWidth(1,20);
您需要在修改前获取 table。
这将取决于您的数据设置方式,但您可以尝试的一件事是将所有 table 放入 Document
.
function myFunction() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var tables = body.getTables();
Logger.log(tables);
for(var i =0; i< tables.length; i++){
var table = tables[i];
table.setColumnWidth(1, 20);
}
}
先用getActiveDocument()
and after that the Body
得到Document
。
使用 Body
有一种方法可以使用 getTables()
. That would give you an array of Table
获取所有 table。在 class 中有几种方法可以用来制作你想要的 table。如果没有更多关于您希望您的 table 如何结束的指示,则取决于您在 Table
class.