Andy S
Andy S

Reputation: 13

Copying Images between Google Spreadsheets

I have a user that created about 50 sheets inside a Google Spreadsheet. Each page has some info and a few pictures. The user didn't realize that they couldn't share the sheets individually and now needs them separated out in to 50 different sheets.

The data is easy, I'm using the following code as proof (I haven't built the loop yet, I'll take care of that once I know this is going to work). I can't however figure out how to move/copy the images over to the new sheets as well.

Any suggestions?

function splitSheets(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var newSS = SpreadsheetApp.create("Testing");

  var dataRange = ss.getSheetByName("CHE").getDataRange();
  var data = ss.getSheetByName("CHE").getDataRange().getValues();
  newSS.getRange(dataRange.getA1Notation()).setValues(data);

  Browser.msgBox(newSS.getUrl());
}

Upvotes: 0

Views: 1690

Answers (1)

AdamL
AdamL

Reputation: 24609

Could you simply use the copyTo() method?

function splitSheets(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var newSS = SpreadsheetApp.create("Testing");
  ss.getSheetByName("CHE").copyTo(newSS);

  Browser.msgBox(newSS.getUrl());
}

Upvotes: 3

Related Questions