Página 1 de 1

Salvar planilha ativa em pdf (google script)

Enviado: Sex Abr 19, 2019 9:39 am
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);

}

Re: Salvar planilha ativa em pdf (google script)

Enviado: Sex Abr 19, 2019 10:28 am
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()

Re: Salvar planilha ativa em pdf (google script)

Enviado: Sex Abr 19, 2019 10:31 am
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