0

Using AppScript the goal is to copy a range of values within a Google Spreadsheet to another range within the same sheet while preserving the already applied formatting. In particular, I have

  • merged some Cells
  • highlighted some text by making it bold
  • changed the background color of some ranges
  • applied borders to some ranges and cells

All of this information should be copied as well. Not surprisingly, if I use setValues, only the values without the formatting are copied:

function copyTable() {
  let sheet = SpreadsheetApp.getActive().getSheetByName('ExampleSheet')
  let vals = sheet.getSheetValues(2,2,9,6)
  let range = sheet.getRange(13, 2, 9, 6)
  
  range.setValues(vals)
}

Is there an easy way to extend my code such that it copies all of the formatting information as well?

To make it more clear, this is what my code does at the moment:

enter image description here

But the desired result would look like this:

enter image description here

Moritz Wolff
  • 436
  • 1
  • 7
  • 16
  • Don't merge cells ever. Try `.copyTo()` – TheMaster Oct 12 '21 at 13:57
  • It changes the basic underlying rectangle structure of a spreadsheet. Any expert in any spreadsheet software would agree that merging cells would come back to bite you later. It's the first thing to know about spreadsheets: Never merge cells. – TheMaster Oct 12 '21 at 14:12

0 Answers0