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

184
Visualizações
Google Sheets API spreadsheets.values.update doesn't repeat format

I'm trying to create sheets with Google Sheets API with following steps:

  • Create a template sheet and format last row manually using Web GUI
  • Copy this template sheet with Drive API
  • Write many rows to newly copied sheet's last row with Sheets API update method

This approach almost works well, but it doesn't repeat cell formatting. Please let me know how to repeat cell formatting of last row automatically when adding rows by Sheets API update method.

Sample template: https://docs.google.com/spreadsheets/d/1MuJCxuSPuwdzjd3eJA5AJ3mIiZ0IXsdu3G-SamTBM_A/

Sample code:

    const { google } = require('googleapis')
    
    const auth = await google.auth.getClient({
      scopes: [
        'https://www.googleapis.com/auth/drive',
        'https://www.googleapis.com/auth/spreadsheets',
      ],
    })
    const gdrive = google.drive({ version: 'v3', auth })
    const res = await gdrive.files.copy({
      fileId: '1MuJCxuSPuwdzjd3eJA5AJ3mIiZ0IXsdu3G-SamTBM_A',
      resource: {
        name: 'aFileName',
        parents: ['1aths48cSYq8bA0j1gsYi-Kcp5k4lVOwt'],
      },
    })
    
    const { id: spreadsheetId } = res.data
    console.log(`Generated sheet: https://docs.google.com/spreadsheets/d/${spreadsheetId}`)
    
    const sheets = google.sheets({ version: 'v4', auth }).spreadsheets
    await sheets.values.update({
      spreadsheetId,
      range: 'A5',
      valueInputOption: 'USER_ENTERED',
      resource: {
        values: [
          ['2022-12-28', '8.88', '12'],
          ['2022/1/10', '3.2', '3'],
          ['26 Sep 2022', '2.55', '7'],
        ],
      },
    })

Sample result: (Cell formatting applied on manually formatted row only): https://docs.google.com/spreadsheets/d/1-CIGOK6GczVZ4qNvsBJKOs0VJeBO8L3kGqYbh1RkC3A/

Thanks.

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