Vídeo recomendado
https://youtu.be/diWPPPhW-9E

Salvar planilha ativa em pdf (google script)

Fórum para dúvidas gerais sobre programação Web
marcio.rosalen
Acabou de chegar
Acabou de chegar
Mensagens: 5
Registrado em: Dom Abr 14, 2019 10:11 am

Salvar planilha ativa em pdf (google script)

Mensagem por marcio.rosalen »

Olá! Bom dia a todos e Feliz Páscoa!
Estou com um pequeno desafio e não consigo acertar um detalhe: Eu tenho uma planilha com vária abas. O script abaixo deveria salvar apenas a aba atual (aba ativa) em pdf no gdrive, porem o pdf criado está com todas as abas ( várias paginas, uma para cada aba). Não consegui fazer esse ajuste. Poderiam me ajudar? Obs.: Já tentei aplicar o getActiveSheet() no lugar de getActiveSpreadsheet() e não dá certo.

function generatePdf(){

var newspreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var pdf = DriveApp.getFileById(newspreadsheet.getId()).getAs('application/pdf');
var saveCopy = DriveApp.createFile(pdf);

}
Anexos
Capturar.PNG
Capturar.PNG (21.05 KiB) Exibido 22614 vezes


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Avatar do usuário
Reinaldo
Jedi
Jedi
Mensagens: 1537
Registrado em: Sex Ago 01, 2014 4:09 pm
Localização: Garça - SP / SCS - SP

Re: Salvar planilha ativa em pdf (google script)

Mensagem por Reinaldo »

Não utilizo google drive mas....
SpreadSheet e uma classe que "representa" todo a planilha (workbook) https://developers.google.com/apps-scri ... dsheet-app

Experimente utilizar --> getActive() https://developers.google.com/apps-scri ... etActive()


Avatar do usuário
Reinaldo
Jedi
Jedi
Mensagens: 1537
Registrado em: Sex Ago 01, 2014 4:09 pm
Localização: Garça - SP / SCS - SP

Re: Salvar planilha ativa em pdf (google script)

Mensagem por Reinaldo »

Em adicional: https://stackoverflow.com/questions/331 ... preadsheet
getActiveSpreadsheet() is a container-bound script.

A script is bound to a Google Sheets, Docs or Forms file if it was created from that document rather than as a standalone script. The file a bound script is attached to is referred to as a "container". Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive, they cannot be detached from the file they are bound to, and they gain a few special privileges over the parent file.

getActiveSpreadsheet(), getActiveDocument(), and getActiveForm() allow bound scripts to refer to their parent file without referring to the file's ID.

In Google Sheets, getActiveSheet(), getActiveRange(), and getActiveCell() let the script determine the user's current sheet, selected range of cells, or selected individual cell. setActiveSheet(sheet) and setActiveRange(range) let the script change those selections.

Taken from https://developers.google.com/apps-script/guides/bound


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder