0

I'm writing a gmailApp script that looks at a spreadsheet and will send some emails out based on a sheet of names and emails. I'm trying to make it as user-friendly as possible. I'm aware I can use the option parameter and use htmlBody to send an email with formatting but I'd prefer the end-user not to have to enter the script to update the body if they want a link or to bold something.

I have a cell for the email body like this but can't seem to find the function to capture the formatting.

Dear {{name}},

Something something test. Link

Thanks

And when I use getValue or getDisplayValue it just returns

Dear {{name}}, Something something test. Link Thanks

No new lines, no links or formatting, etc. Any advice would be greatly appreciated. Thanks

1 Answer 1

0

There is no direct way to convert a the rich text content from a cell into HTML.

One way is the following

  1. First the code have to get a RichTextValue object
  2. then get the "runs"
  3. then get the content and formatting of each run
  4. then convert the convert that into HTML

Another way is the following:

  1. First the code have to export the spreadsheet to HTML
  2. then get the cell content

References

1
  • Thanks @Rubén. I think this is going to have to be a larger project when I have time but I was able to get runs, I just don't know how to account for all the combinations someone would use. As a temp solution, I am just writing good 'ol HTML directly into the cell and then using .htmlBody with SendMail which works great.
    – Grant
    Dec 29, 2021 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.