将所选内容从Google Sheet复制到Google Doc中(使用REST API?) [英] Copy selection from Google Sheets into a Google Doc (using REST API?)
本文介绍了将所选内容从Google Sheet复制到Google Doc中(使用REST API?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Google工作表,我使用使用Google的REST API的python脚本更新其内容。
我想自动将该工作表的一部分复制到给定的Google Doc中。(例如,我希望该工作表的A:G栏出现在我的文档中,并在工作表出现时进行更新。)文档中还有其他元素(例如,段落),因此每次在我指定的位置显示小节非常重要(通过自我更新或删除旧小节并插入新小节)。
这可能吗?我会怎么做?
推荐答案
AFAIK,可以使用Apps Script-Extending Google Docs和Extending Google Sheets。
您可以创建具有onChange()
触发器的Container-bound Scripts以获取更新值。
写入文档
//This can be openById() Open a document by ID.
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
// Append a paragraph and a page break to the document body section directly.
body.appendParagraph("A paragraph.");
body.appendPageBreak();
从工作表获取数据
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// This represents ALL the data
var range = sheet.getDataRange();
var values = range.getValues();
// This logs the spreadsheet in CSV format with a trailing comma
for (var i = 0; i < values.length; i++) {
var row = "";
for (var j = 0; j < values[i].length; j++) {
if (values[i][j]) {
row = row + values[i][j];
}
row = row + ",";
}
Logger.log(row);
}
出于实现目的,请查看link。这展示了如何使用Apps脚本创建Google Docs并从Google Sheet传递一个值。
希望这能有所帮助。
这篇关于将所选内容从Google Sheet复制到Google Doc中(使用REST API?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文