0

I searched the internet for a answer but can't find one. I've written a few really basic script in the past for excel, but i'm now using google sheets and want to have a button that hide specified rows, then publish the spreadsheet as a PDF.

I currently have 1 button for hidding rows and 1 button to publish, but i would like to combine them.

Here is what i have. Both scripts work fine alone, but when i run the code below, only the second function seems to work.

/* Hide rows */
function hideRows() {
  SpreadsheetApp.getActiveSheet().hideRows(46,160)
}


/* Email Google Spreadsheet as PDF */
function emailGoogleSpreadsheetAsPDF() {
  
  // Send the PDF of the spreadsheet to this email address
  var email = "useremail@useremailcom"; 
  
  // Get the currently active spreadsheet URL (link)
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // Subject of email message
  var date = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd");
  var subject = "" + ss.getName()+ " - " + date ; 

  // Email Body can  be HTML too 
  var body = "You can find attached the Daily Status Report";
  
  var blob = DriveApp.getFileById(ss.getId()).getAs("application/pdf");
  
  blob.setName(ss.getName() + ".pdf");
  
  // If allowed to send emails, send the email with the PDF attachment
  if (MailApp.getRemainingDailyQuota() > 0) 
    GmailApp.sendEmail(email, subject, body, {
      htmlBody: body,
      attachments:[blob]     
    });  
}

Note: I would also like to have the button that call the script to be hidden, can i do it by including the row containing the button in the range of the script ?

Steven
  • 3
  • 1
  • Why not call a third function that does what you want? See also https://stackoverflow.com/q/48304224/9337071 – tehhowch Jul 10 '18 at 13:10
  • i'm not sure i understand your option of a third function. and i've looked at the linked you have shared, it seems to be a good idea maybe. but if someone was kind enough to help me write the code i would be much more happy i will still try to understand the SpreadsheetApp.flush() – Steven Jul 10 '18 at 16:59
  • 2
    `function foo() {...}; function bar() {...}; function doBoth() { foo(); bar(); }` – tehhowch Jul 10 '18 at 17:17

0 Answers0