简体   繁体   English

通过Apps脚本在Google表格列中写入值

[英]Writing the values in Google Sheet column via Apps Script

I have a 2 column google sheet, column one (A) has the domain names, and I want to populate whether they are verified in Google Apps or not in the column B respectively. 我有一个2列的Google工作表,其中的第一列(A)具有域名,我想分别在B列中填充它们是否已在Google Apps中验证。

I wrote the following script-: When i check for logs, i see that the loop is working fine as i get True/False value to all 4 domain in column A, am facing issues in writing the results to Column B with following script, it seems am missing something around getrange, but not sure. 我编写了以下脚本::当我检查日志时,我看到循环正常运行,因为我对A列中的所有4个域都获得了True / False值,在使用以下脚本将结果写入B列时遇到了问题,似乎缺少getrange周围的东西,但不确定。 any help is appreciated. 任何帮助表示赞赏。

var ss = SpreadsheetApp.getActiveSpreadsheet()
var data = ss.getSheets()[0].getDataRange().getValues();
var customer = "my_customer";
function domainList() {
for(i=0; i<data.length; i++){

  var getDomain = AdminDirectory.Domains.get(customer, data[i])
  var result = JSON.parse(getDomain.verified)
   sheet.getRange('B1').setValue(result)
Logger.log(result)
  } }

I think you need to define sheet. 我认为您需要定义工作表。

 var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var data = ss.getSheets()[0].getDataRange().getValues();
var customer = "my_customer";
function domainList() {
for(i=0; i<data.length; i++){

  var getDomain = AdminDirectory.Domains.get(customer, data[i])
  var result = JSON.parse(getDomain.verified)
   sheet.getRange('B1').setValue(result)
Logger.log(result)
  } }

I think if you will recode your function like this it will work okay. 我认为,如果您将像这样重新编码函数,它将可以正常工作。 I disabled a couple of lines just to get the code right. 为了使代码正确,我禁用了几行。

function domainList() 
{
var sheet = SpreadsheetApp.getActiveSheet();
var data =sheet.getDataRange().getValues();
var customer = "my_customer";
  for(i=0; i<data.length; i++)
  {
    data[i]=[];
    //var getDomain = AdminDirectory.Domains.get(customer, data[i][0]);
    //var result = JSON.parse(getDomain.verified)
    sheet.getRange(i+1,2).setValue('yes')

  } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Apps脚本-从另一个工作表导入工作表值 - Google apps script - Importing sheet values from another sheet 使用“字典”填写 Google Apps 脚本中工作表和列值的公式? - Fill down formula using a "dictionary" for sheet and column values in Google Apps Script? Google Apps脚本在一个工作表中复制一列,将其转置,然后粘贴到另一个 - Google Apps Script Copying a column in one sheet, transposing it, then pasting to another 按 Apps 脚本中的列名读取 Google Sheet Exported JSON - Read Google Sheet Exported JSON by column name in Apps Script 使用 Apps 脚本自动化 Google 表格中列的日期 - Automating date of a column in Google Sheet using Apps Script Google Apps 脚本 - 想要截断表单中特定列中的文本 - Google Apps Script - Want to truncate a text in a particular column in a form sheet Google Sheet 数据应用程序脚本未在 WebApps 中显示值 - Google Sheet data Apps Script not showing values in WebApps 将Google Apps脚本写入电子表格列的第一步 - Google Apps Script Writing to Spreadsheet Column One Step Behind 如何通过 Apps Script 更改 Google Sheets 中的多个单元格值? - How to change multiple cell values in Google Sheets via Apps Script? 如何通过谷歌应用程序脚本从 xlsx gmail 附件中提取谷歌表格中的信息 - How can I extract Information in a Google Sheet from a xlsx gmail attachment via google apps script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM