[英]Create a file for each Google sheet row
I am trying to create a file, in a specific folder for each row in a Google sheet.我正在尝试在 Google 工作表中每一行的特定文件夹中创建一个文件。 I would like the title of the files to be the content of the 1st cell of each row.
我希望文件的标题是每行第一个单元格的内容。
My script seems to be working except for the title.除了标题,我的脚本似乎在工作。 The files are named "untitled" and I can't figure out why.
这些文件被命名为“无标题”,我不明白为什么。 Here is my code
这是我的代码
function iterateThroughRows() {
var sheet = SpreadsheetApp.getActive()
var data = sheet.getDataRange().getValues();
data.forEach(function (row) {
var values = SpreadsheetApp.getActiveSheet().getRange("A:A").getValues();
var folderId = "XXX"
var resource = {
title: values,
mimeType: MimeType.GOOGLE_SHEETS,
parents: [{ id: folderId }]
}
var fileJson = Drive.Files.insert(resource)
var fileId = fileJson.id
});
}
You need to use row
to access the first element of array/or first cell, no need to use SpreadsheetApp.getActiveSheet().getRange("A:A").getValues();
您需要使用
row
来访问数组/或第一个单元格的第一个元素,无需使用SpreadsheetApp.getActiveSheet().getRange("A:A").getValues();
as you already have the data.因为你已经有了数据。
Try following modification:-尝试以下修改:-
function iterateThroughRows() {
var sheet = SpreadsheetApp.getActive()
var data = sheet.getDataRange().getValues();
data.forEach(function (row) {
var folderId = "XXX"
var resource = {
title: row[0], // First Cell/first element of array data
mimeType: MimeType.GOOGLE_SHEETS,
parents: [{ id: folderId }]
}
var fileJson = Drive.Files.insert(resource)
var fileId = fileJson.id
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.