备份Google应用程序脚本不运行 [英] Backup Google apps script not running
问题描述
我有我认为正在运行的下面的脚本,但是当我刚刚测试时,我得到了错误
I have the below script which i thought was running but when I tested just now I got the error
TypeError:无法读取属性0来自未定义的第31行。
TypeError: Cannot read property "0" from undefined line 31.
我在下面加了粗体。但这是这条线。如果(dataA [j] [0]&& dataA [j] [1]) 。我在A2中有一个
= today()
来获取脚本在归档表中输入的日期,因此不确定这是否是问题,因为它使用的是
$ b
I have bolded it below. but it is this line. if(dataA[j][0] && dataA[j][1])
. I have a =today()
in A2 to get the date that the script uses to enter in the archive sheet, so not sure if this is the issue as it is using the google sheet format "date" in the cell.
function dataBackup()
{
var inputSS = SpreadsheetApp.getActiveSpreadsheet();
var archiveSS = SpreadsheetApp.openById('1uPA_4CRmv2wkqe1uljViJ-
1z1NTNDmwS3aE6TDowe88');
var sheetNames = ['AM trip', 'PM trip', 'Pool / Beach', 'Night Dive'];
for (var i=0; i<sheetNames.length; i++)
{
var inputSheet = inputSS.getSheetByName(sheetNames[i]);
var archiveSheet = archiveSS.getSheetByName(sheetNames[i]);
var date=new Date(inputSheet.getRange('A2').getValue());
var rng=inputSheet.getRange('E7:U37');
var dataA=rng.getValues();
var data=[];
for(var j=0;i<dataA.length;j++)
{
**if(dataA[j][0] && dataA[j][1])**
{
data.push([dataA[j].splice(0,0,date)]);
}
}
var dv=archiveSheet.getRange(archiveSheet.getLastRow(), 1).getValue();
date=(typeof(dv)!='undefined')?dv:'No Date Found';
if (data.length>0)
{
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), data.length);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, data.length, rng.getWidth()+1).setValues(data);
}
else
{
archiveSheet.insertRowsAfter(archiveSheet.getLastRow(), 1);
archiveSheet.getRange(archiveSheet.getLastRow() + 1, 1, 1, 2).setValues([[date, 'No Data']]);
}
}
}
推荐答案
简答
在for循环中有一个错字。对于(var j = 0; i< dataA.length; j ++)
Short answer
There is a typo on the related for loop. On
for(var j=0;i<dataA.length;j++)
用 j替换
i
关于if = TODAY()导致错误,它不是,但它是值得的注意TODAY()返回今天的日期。通过使用getValue()获取日期值可以将日期对象传递给Google Apps脚本引擎,而不是
Regarding if =TODAY() is causing the error, it isn't, but it's worth to note that TODAY() returns today's date. Getting a date value by using getValue() a date object is passed to the Google Apps Script engine, so instead of
var date=new Date(inputSheet.getRange('A2').getValue());
try
var date=inputSheet.getRange('A2').getValue();
这篇关于备份Google应用程序脚本不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!