【发布时间】:2021-05-29 11:29:01
【问题描述】:
我正在尝试使用谷歌表格中的所有数据填充谷歌文档。我要做的是根据工作表中的数据生成报告。
- 我将使用谷歌表单提交每日报告。
- 报告将提交到谷歌表格中。
- 然后记录在工作表中的报告将自动填充到 google doc(只会填充一个 google doc)。
目前我已经找到了在谷歌文档中填充数据的方法,但它会为每一行数据生成一个新的谷歌文档。
这是我找到的代码
function autofill(e) {
var timestamp = e.values[0];
var name = e.values[1];
var report = e.values[2];
var templateFile = DriveApp.getFileById("Google Doc ID");
var templateResponseFolder = DriveApp.getFolderById("Folder for Google Doc");
var copy = templateFile.makeCopy(name + ',' + report, templateResponseFolder);
var doc = DocumentApp.openById(copy.getId());
var body = doc.getBody();
body.replaceText("{{Timestamp}}", timestamp);
body.replaceText("{{Name}}", name);
body.replaceText("{{Report}}", report);
doc.saveAndClose();
}
Record from Google Sheet
+-----------------+----------+----------+
|Timestamp |Name |Position |
+-----------------+----------+----------+
|3/2/2021 14:12:13|John Doe 1|Position 1|
+-----------------+----------+----------+
|3/2/2021 14:15:13|John Doe 2|Position 2|
+-----------------+----------+----------+
This is the ouput of the above code.
+------------------------+
| John Doe 1 |
| Position 1 |
| |
| |
| |
| |
| |
| |
| |
+------------------------+
John Doe 1, Position 1.docs
+------------------------+
| John Doe 2 |
| Position 2 |
| |
| |
| |
| |
| |
| |
+------------------------+
John Doe 2, Position 2.docs
It will make a new Google Docs document every time a new data is recorded in Google Sheet.
This is what I am trying to achieve
+------------------------+
| John Doe 1 |
| Position 1 |
| |
| |
| |
| |
| |
| Page 1 |
+------------------------+
| John Doe 2 |
| Position 2 |
| |
| |
| |
| |
| |
| Page 2 |
+------------------------+
Report.docs
I am trying to populate all the data recorded in Google Sheet in a single Google Docs which is Report.docs
【问题讨论】:
标签: google-sheets google-docs google-forms populate auto-generate