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

205
Visualizações
Select google spreadsheets to send specific tabs via email

I found this code to send by email all tabs of a Google Spreadsheet as a PDF file (one merged file).

function sendReport() {
var message = {
to: "contact@sexample.com",
subject: "Sales Reports",
body: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
name: "Sales",
attachments:[SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.PDF).setName("sales_report_2021")]
}
MailApp.sendEmail(message);

So, I'd like to merge into the final document only the tabs that "A1" cell is equal "1" and send them by email as attachment.

Thank you very much!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I believe your goal is as follows.

  • You want to create a PDF data with only the tabs of when the cell "A1" is 1.

In this case, how about the following modification?

Modified script:

function sendReport() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ranges = ss.createTextFinder("1").matchEntireCell(true).findAll();
  var showSheets = ranges.reduce((ar, e) => {
    if (e.getA1Notation() == "A1") ar.push(e.getSheet().getSheetName());
    return ar;
  }, []);
  var sheets = ss.getSheets();
  sheets.forEach(s => {
    if (!showSheets.includes(s.getSheetName())) s.hideSheet();
  });
  SpreadsheetApp.flush();
  var pdf = ss.getBlob().setName("sales_report_2021");

  var message = {
    to: "contact@sexample.com",
    subject: "Sales Reports",
    body: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
    name: "Sales",
    attachments: [pdf]
  }
  MailApp.sendEmail(message);

  sheets.forEach(s => s.showSheet());
}
  • In this modification, the cells which have 1 are retrieved from all sheets using TextFinder. And, the sheets that the cell "A1" has 1 are retrieved. And, the sheets that the cell "A1" has no value of 1 are hidden. And then, the Spreadsheet is converted to a PDF data, and used with MailApp.sendEmail. At last, all sheets are shown. By this flow, your goal is achieved.

References:

  • createTextFinder(findText) of Class Spreadsheet
  • hideSheet()
  • showSheet()
about 4 years ago · Juan Pablo Isaza Relatório
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