0
votes

Thanks to everybody.

I've got a Google spreadsheet containing 7 sheets. I'm trying to move data in the last sheet from cells A1:D1 to a new row appended to the bottom of the same sheet.

Here is the snippet of code I'm using:

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[6];
  var src = sheet.getRange('PaycheckHistory!A1:D1').getValues();
  sheet.appendRow([src]);

After I run the code, on the tab "PaycheckHistory", in a new row appended to the bottom of the sheet, I get the following: "[Ljava.lang.Object;@3e0d05f9"

Can anybody tell me (a) What is this error, (b) What does this mean, and (c) How do I fix this or perform my goal, which is to "move data in the last sheet from cells A1:D1 to a new row appended to the bottom of the same sheet."

Thanks, all!

6/22/18 IDK if this will help, but cannot find an "update this question" button on the screen showing my original post. I DID, however, find an "edit" button, and I'm using that now.

Here's the complete code that I'm using: (apologies if the code is not formatted properly)

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Tasks')
     .addItem('createCopy','createCopy')
      .addToUi();
}

function createCopy() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[6];
  var src = sheet.getRange('PaycheckHistory!A1:D1').getValues();
  sheet.appendRow(src[0]);

  SpreadsheetApp.flush();

  var myValue = 

SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("O58").getValue(); var destinationFolder = DriveApp.getFolderById("1errc7- 2sM**********ZPKJIxjZOTRWo");

DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId()).makeCopy(myValue,destinationFolder);

}

Here's the problem I'm getting: The first part of the function (ABOVE "SpreadsheetApp.flush();") moves data on sheet 6 of the spreadsheet.The next part of the function (BELOW "SpreadsheetApp.flush();") copies the entire spreadsheet, puts the copy in a specified folder, and renames the copy.

I want this function to do more things on other tabs/sheets in the spreadsheet file. I can write additional code to do this, but when I add the new code to the existing function above, the new code does nothing. Simply using "SpreadsheetApp.flush();" does not work.

1
There are other lines of code in my script. Everything works properly EXCEPT this!user3279926

1 Answers

0
votes

Answer to (a)

Value retrieved by getValues() is 2 dimensional array. When it sees the usage of appendRow(rowContents), rowContents is 1 dimensional array. In your script, when this sheet.appendRow([src]) is run, the 3 dimensional array is used. So such string is put.

Answer to (b)

About [Ljava.lang.Object;@, you can see the information at the following threads.

Answer to (c)

In order to avoid such string, in the case of your script, please modify as follows.

sheet.appendRow([src]);
sheet.appendRow(src[0]);

Reference :

If I misunderstand your question, I'm sorry.