[英]Google Docs Apps Script get number of columns
On a Google Doc you can set columns from Format > Columns.在 Google Doc 上,您可以从“格式”>“列”中设置列。 Now, though, I want to access those columns from Apps Script to confirm the number of columns.
不过,现在我想从 Apps 脚本访问这些列以确认列数。 I don't even need to modify them, just access.
我什至不需要修改它们,只需访问即可。 I haven't found anything that jumps out at me from the documentation, so I didn't know if there's an extension of the Document service that would allow for such.
我没有发现任何从文档中跳出来的东西,所以我不知道是否有允许这样的文档服务的扩展。 I'm sorry not to include any code, but I have no code obvious to show.
很抱歉没有包含任何代码,但我没有明显的代码可以显示。 I did create a document with 2 columns to see exactly what I'm talking about.
我确实创建了一个包含 2 列的文档以确切了解我在说什么。 https://docs.google.com/document/d/1MyttroeN4kPUm9PfYZnTe_gJqstM3Gb5q3vS3c84dNw/edit
https://docs.google.com/document/d/1MyttroeN4kPUm9PfYZnTe_gJqstM3Gb5q3vS3c84dNw/edit
It is possible using the get method of the Google Docs API可以使用Google Docs API的get方法
get
.get
。content
.content
的数组。sectionBreak
in each element of content
.content
每个元素中搜索一个名为sectionBreak
的对象。sectionBreak>sectionStyle>columnProperties
.sectionBreak>sectionStyle>columnProperties
。columnProperties
.columnProperties
的长度。columnProperties
is in the first element of content
, skip it and start the loop from the second one. columnProperties
是在content
的第一个元素中,跳过它并从第二个元素开始循环。function myFunction() {
var id = DocumentApp.getActiveDocument().getId()
var result = Docs.Documents.get(id)
var content = result["body"]["content"]
for (var i = 1; i < 20; i++) {
try {
var cols = content[i]["sectionBreak"]["sectionStyle"]["columnProperties"]
console.log('number of columns: ' + cols.length)
} catch (error) {
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.