You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Sheets:实现点击按钮发送单元格内容至Slack

Solution

To send the displayed formula result of a specific cell to Slack instead of hardcoded text, modify your script as follows:

Key Adjustment

Use getDisplayValue()—this method returns the visible text of a cell (including formula-calculated results) rather than the underlying formula itself.

Updated Code

function sendNotification() {
  // Replace with your full Slack webhook URL
  const url = "https://hooks.slack.com/services/your-complete-webhook-path";
  
  // Retrieve target cell's displayed value
  const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  const targetSheet = spreadsheet.getSheetByName("Sheet1"); // Replace with your sheet name
  const cellContent = targetSheet.getRange("A1").getDisplayValue(); // Replace with your cell reference
  
  const params = {
    method: "post",
    contentType: "application/json",
    payload: JSON.stringify({
      "text": cellContent // Use cell's displayed value as Slack message
    })
  };

  const sendMsg = UrlFetchApp.fetch(url, params);
  const respCode = sendMsg.getResponseCode();
  Logger.log(sendMsg);
  Logger.log(respCode);
}

Critical Notes

  • Replace "Sheet1" with the exact name of your spreadsheet tab (check the bottom of your Google Sheet).
  • Replace "A1" with the cell reference containing your formula result (e.g., "C3").
  • Ensure your Slack webhook URL is fully completed (your original code had a partial URL).

Function Breakdown

  • getActiveSpreadsheet() accesses the spreadsheet bound to your script.
  • getSheetByName() targets the specific sheet holding your data.
  • getDisplayValue() pulls the visible text of the cell, bypassing the formula.

内容的提问来源于stack exchange,提问作者JohnnyMelou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 10:20:17