Google 表格 I 将格式化的单元格范围作为电子邮件发送

问题描述 投票:0回答:1

:)

我想使用脚本通过电子邮件自动发送 Google 表格中的格式化单元格范围。

例如:我按下一个按钮,范围 B2-E30 被发送。

我已经找到了几个关于该主题的代码,但它们总是旨在发送未格式化的文本。

我非常感谢有关此主题的帮助。

提前谢谢您。

最诚挚的问候 斯特凡

email google-sheets range cell
1个回答
0
投票

打开谷歌表格文档 - >扩展 - >应用程序脚本

将脚本编辑器中的任何代码替换为以下代码

function sendFormattedRange() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = sheet.getRange("B2:E30");
  
  // Get the HTML content of the range
  var htmlBody = range.getRichTextValue().getRuns().map(function(run) {
    return run.getText();
  }).join("<br>");
  
  // Send email with formatted content
  var subject = "Formatted Range";
  var recipient = "[email protected]"; // Change this to the recipient's email address
  var body = "Here is the formatted range:<br><br>" + htmlBody;
  MailApp.sendEmail(recipient, subject, "", { htmlBody: body });
}

保存,关闭脚本编辑器

© www.soinside.com 2019 - 2024. All rights reserved.