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);
}
Vídeo recomendado
https://youtu.be/diWPPPhW-9E
https://youtu.be/diWPPPhW-9E
Salvar planilha ativa em pdf (google script)
-
- Acabou de chegar
- Mensagens: 5
- Registrado em: Dom Abr 14, 2019 10:11 am
- Reinaldo
- 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)
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()
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()
- Reinaldo
- 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)
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
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