简体   繁体   English

为每个 Google 工作表行创建一个文件

[英]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.

相关问题 尝试为Google表格中的每一行创建多个PDF - Trying to create multiple PDF for each row in a Google Sheet 不需要的多行条目/副本(Google 表单 --> Google Sheet 文件,sheet1 --> Google Sheet 文件,sheet 2) - Unwanted multiple row entries / copies (Google Form --> Google Sheet file, sheet1 --> Google Sheet file, sheet 2) 从新的 Google 工作表行创建文件夹 - Create Folder from new Google sheet Row 使用 Google 工作表中的脚本修改导入数据中的每一行 - Modify each row in imported data with a script in Google sheet 谷歌表格 - 每天将行复制到表格中数据的底部 - Google Sheets - Copy row to bottom of data in the sheet each day 如何按字母顺序对Google表格的每一行进行排序 - How to sort each row of a Google Sheet in Alphabetical Order 如何为电子表格的每一行创建一个谷歌文档? - How to create a google doc for each row of a spreadsheet? 在现有电子表格中为Google表单的每个响应创建一个新工作表 - Create a new sheet in an existing spreadsheet for EACH RESPONSE from a Google Form 编辑表单回复时为工作表上的更改行创建 Google 文档 - Create a Google Doc for Changed Row on Sheet When Editing Form Responses Google Sheet Script - 将每个选项卡保存到特定文件夹中的单独文件中 - Google Sheet Script - save each tab into seperate file in specific folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM