0
我已經編寫了不到一週的代碼,但我想我不會有這麼多麻煩試圖解決這個錯誤。通過其他例子來看,但我不太可能知道他們是如何應用於我的,因爲他們都沒有解決我的問題。下面是代碼:無效的左側分配。 (第1行,「代碼」文件) - Google Apps腳本
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);
}
溫柔,這是我的第一次。 ;)
其中一個答案能解決您的問題嗎?如果是這樣,請接受該答案。 –
對不起,這個還是新的。忘記了你需要。 – JLBJones