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:
But the desired result would look like this: