Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

525
Visualizações
How to copy values and preserve formatting in Google Sheets/Apps Script?

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

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda