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

基于ImportJSON的Google Sheets每分钟触发日志记录脚本需求

Google表格自动记录ImportJSON输出的Apps Script代码

以下是实现每分钟记录ImportJSON输出到Data工作表新行的代码:

function logImportJSONResult() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sourceSheet = ss.getSheetByName("Sheet1"); // 替换为存放A1、A2的工作表名
  const targetSheet = ss.getSheetByName("Data");
  
  // 读取参数和ImportJSON结果
  const param = sourceSheet.getRange("A1").getValue();
  const result = sourceSheet.getRange("A2").getValue();
  
  // 仅当参数和结果都非空时执行记录
  if (param && result) {
    const timestamp = new Date(); // 记录日志生成时间(可选)
    targetSheet.appendRow([timestamp, param, result]);
  }
}

配置说明

  1. 修改工作表名:把代码里的"Sheet1"替换为你实际存放A1(参数)和A2(ImportJSON公式)的工作表名称。
  2. 设置定时触发器:
    • 打开表格的「工具」>「脚本编辑器」
    • 点击左侧栏的时钟图标(触发器)
    • 点击「添加触发器」,配置如下:
      • 选择函数:logImportJSONResult
      • 事件源:时间驱动
      • 类型:分钟计时器
      • 间隔:每1分钟

扩展调整

  • 如果ImportJSON返回多列数据:将getRange("A2")改为getRange("A2:C2")(根据实际列数调整),然后把appendRow里的内容改成[timestamp, param, ...result],即可把多列结果一并写入。
  • 不需要时间戳:直接删除timestamp变量,appendRow改为[param, result]即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 14:05:54