1

Im currently using this script to send emails from my sheets

My problem is that im not getting the emails with the same format as my table

Any way to send email with the exact format as I have on the sheet ?

Thanks !

This is the code

function Reminder() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName("Sheet1");
  var range = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn()-1);
  var valueToCheck = sheet.getRange("F1").getValue();

 // Optional init, to ensure the spreadsheet config overrides the script's
  var conv = SheetConverter.init(ss.getSpreadsheetTimeZone(),ss.getSpreadsheetLocale());

  // Grab an array for formatted content
  var array = conv.convertRange(range);
  Logger.log(JSON.stringify(array));

  // Get a html table version, with all formatting
  var html = conv.convertRange2html(range);
  Logger.log(html);

//Enter your condition below
  if(valueToCheck != 'OK'){
    MailApp.sendEmail("test@gmail.com", 'Reminder','' ,
    {name: 'Sen',htmlBody: 
    "Message " + "</br></br>" +
    html + "</br></br>" +
     })

}
}

The Sheet converter is a library for the script that should work https://sites.google.com/site/scriptsexamples/custom-methods/sheetconverter

Rubén
  • 34,714
  • 9
  • 70
  • 166
SATH59
  • 149
  • 1
  • 3
  • 15

2 Answers2

0

This: if(valueToCheck = 'OK'){ should be this: if(valueToCheck == 'OK'){

Cooper
  • 59,616
  • 6
  • 23
  • 54
0

Not all the Google Sheets formatting features, i.e. cell borders, can be read by using the Spreadsheet Service from Google Apps Script. You might try to use the Sheets Converter as a starting point and complement it with Google Sheets Advanced Service.

If you use the Sheets Converter library you might have to change the default formatting settings to make it to be able to reproduce the formatting of your table. Among other things you might have to extend this library to support cell rich text formatting.


From https://github.com/mogsdad/SheetConverter/

This script is incomplete, ignoring some types of formatting. (Feel free to fork and enhance it, if you wish! Broadly applicable enhancements can be merged and the library updated) There are also some known issues:

(please read the details on the source)

It's worthy to note that the code was updated 25 days ago (Jan 14, 2021)

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166