How to get entire sheet content with formatting and send it via email

Viewed 41

Is it possible to send entire sheet content via e-mail using Apps Script? I have a problem with getting the whole content of the sheet preserving formatting and replacing the text "templatka" with it (dataSpreadsheet). Is it possible - if is is then how?

I use the following instruction to send e-mail https://www.youtube.com/watch?v=ZcNmur6xiX4

My code:

function sendEmails() {
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Emails").activate();
  
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var lr = ss.getLastRow();

  Logger.log(MailApp.getRemainingDailyQuota())

  for (var i=2; i<=lr; i++){
    var currentEmail = ss.getRange(i, 2).getValue();
    var currentMonth = ss.getRange(i, 3).getValue();

    var dataSpreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TEST")
    dataSpreadsheet.getRange('A1').activate();
    var currentCell = dataSpreadsheet.getCurrentCell();
    dataSpreadsheet.getActiveRange().getDataRegion().activate();
    currentCell.activateAsCurrentCell();


    var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(1,1).getValue();
    var emailText = templateText.replace("{month}", currentMonth).replace("{templatka}", dataSpreadsheet)

    MailApp.sendEmail(currentEmail, "testTitle", emailText)

  }
}

The part responsible for getting the whole TEXT spreadheet does not work (I want to replate the text "templatka" which I have in the template with the entire TEXT spreadsheet content and I do not know how to get the entire TEXT spreadsheet content and assign it to the variable). I would be grateful if anyone could help me with it.

Spreadheet: enter image description here

enter image description here

enter image description here

0 Answers
Related