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

如何使用json-as-xlsx库为Excel添加可点击超链接?

使用json-as-xlsx库导出带可点击超链接的Excel文件

要实现导出包含可点击超链接列的Excel,只需在列配置中为目标列指定type: "hyperlink",同时让value返回对应的链接地址即可。以下是完整实现代码:

数据配置

const data = [
  {
    sheet: "Tasks",
    columns: [
      { 
        label: "Status", 
        value: (row) => row.status_description === "completed" ? "Pending Approval" : "Accepted" 
      },
      { 
        label: "Req Date", 
        value: (row) => moment(row.created_at).format('DD-MM-YYYY hh:mm:ss') 
      },
      { 
        label: "Task Name", 
        value: (row) => row.fields.find(o => o.label === "Task name")?.value 
      },
      { 
        label: "Title", 
        value: (row) => row.name 
      },
      { 
        label: "Content Type", 
        value: (row) => row.fields.find(o => o.label === "Content type")?.value 
      },
      { 
        label: "Final word count", 
        value: (row) => row.word_count 
      },
      { 
        label: "Link", 
        value: (row) => `https://docs.google.com/document/d/${row.doc}`, 
        type: "hyperlink" // 指定该列为超链接类型
      }
    ],
    content: response.items,
  }
];

导出执行逻辑

const filename = `${reqData.query.project_name}-${moment().format('DD-MMM-YYYY')}`;
const settings = {
  fileName: filename,
  extraLength: 1,
  writeMode: 'writeFile',
  writeOptions: {},
  RTL: false,
};

const filepath = path.join(__dirname, `../../../${filename}.xlsx`);

const callback = function () {
  console.log("Download complete:", filename);
  resolve({ filepath: filepath, filename: `${filename}.xlsx` });
};

jsonAsXlsx(data, settings, callback);

关键注意事项

  • 超链接标识:Link列配置中的type: "hyperlink"是让Excel识别该列为可点击链接的核心参数。
  • 链接有效性:value函数必须返回合法的URL字符串,确保导出后单元格内容可正常跳转。
  • 数据完整性:确认response.items中的每条数据都包含doc字段,用于拼接完整的文档链接。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 21:45:29