我编码的时间不到一周,但我认为尝试解决此错误不会有太多麻烦。看看其他例子,但我不太可能知道它们如何适用于我的,并且因为它们都没有解决我的问题。这是代码:
function clearButtonClick() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
Logger.log('sheet.getName(): ' + sheet.getName());
if (sheet.getName() !== "TimeCardEntry") {return;};
sheet.getRange(8,2,12,12).clearContent();
sheet.getRange(4,4).clearContent();
sheet.getRange(4,11).clearContent();
}
function submitButtonClick(){
//Begining of entry8 transfer
var ss=SpreadsheetApp.getActive(); //Makes the active spreadsheet available for the program to act on
var sheet = ss.getActiveSheet(); //Makes the active sheet available
Logger.log('The active sheet is: ' + sheet.getName()); //Writes the sheet name to the log so it can be checked
while(sheet.getName() =="TimeCardEntry"){ //If you are on the correct sheet when you try to run...
//change 8
var cellB8 = sheet.getRange(8,2).getValue(); //Pulls in the value of "B8"
//change 8
if(cellB8 === "") {return}; //If B8 is not blank, or in other words, B8 has something in it, then...
var targetSheet = ss.getSheetByName("TimesheetRecord"); //Pulls in the target sheet name
var arrayOfData = []; //Creates the array to temporarily hold the data until it writes to target sheet
var weekBegining = sheet.getRange(4,11).getValue(); //Stores the value of the "Sunday at the Begining of the Week Date"
var employName = sheet.getRange(4,4).getValue(); //Stores the name of the employee from D4
//change 8
var entry8 = sheet.getRange(8,2,1,9); //pulls in row 8 data to be worked on
//change 8
var entry8Data = entry8.getValues()[0]; //pulls row 8 into an inner array
//change 8
Logger.log('Line 8 data is:' = entry8Data); //logs what the data is so you can make sure it got the right stuff
entry*Data.splice (0,0,weekBegining,employName); //Add weekBegining and employName values to the entry data array
//change 8
arrayOfData.push(entry8Data); //Push row data for entry 8 into an outer array because setValues() can't use nested arrays
Logger.log('Array of data is: ' + arrayOfData); //writes the combined data array to the log
var lastRow = targetSheet.getLastRow(); //stores the number of the last row with entries in the target sheet
Logger.log('Last Row is: ' + lastRow); //logs what the last row is for reference
//change 8
targetSheet.getRange(lastRow+1,1,1,entry8Data.length).seValues(arrayOfData); //Adds 1 row to the lastfilled row then selects that row (1st empty one) and 1 row deep by the number of columns in the arrayOfData then copies the arrayOfData values to it.
//change 8
sheet.getRange(8,2,1,9).clearContent(); //goes back to the original sheet and deletes the row 8 data.
}
}
function emailLog(){
//Send an email to yourself with the log from running this script so you can see if any values were wrong
//Comment all this out once the script work right
var emailRecipient = Session.getActiveUser().getEmail();
var emailSubject = 'Log of the last run of Paradigm Weekly Time Card' ;
var emailBody = Logger.getLog();
MailApp.sendEmail(emailRecipient, emailSubject, emailBody);
}

要温柔,它'我的第一次。 ;)
答案 0 :(得分:1)
你有一个拼写错误:
Logger.log('Line 8 data is:' = entry8Data);
我认为你的意思是:
Logger.log('Line 8 data is:' + entry8Data);
此外,最佳做法是始终使用===
来比较事物,而不是==
:)