【问题标题】:Creating a hyperlink automatically when giving a cell a value in Google Sheets在 Google 表格中为单元格赋值时自动创建超链接
【发布时间】:2023-01-12 05:21:03
【问题描述】:

我希望将亚马逊订单号输入到 Google 表格中,例如以下 123-1234567-1234567

然后我想要的是让单元格自动成为具有以下格式的超链接:

https://www.amazon.co.uk/gp/your-account/order-details/ref=ppx_yo_dt_b_order_details_o00?ie=UTF8&orderID=ORDER_NUMBER_HERE

我知道我可以将跟踪号输入一个单元格,然后让它旁边的单元格使用 CONCAT 显示此链接,但是我正在寻找我输入订单号的单元格,以自动将其自身更改为超链接版本(带有 https://www... 前缀)

例如,我单击一个空单元格。我输入 123-1234567-1234567。然后单元格自动变为=hyperlink("https://www.amazon.co.uk/gp/your-account/order-details/ref=ppx_yo_dt_b_order_details_o00?ie=UTF8&orderID=123-1234567-1234567", "123-1234567-1234567")

提前致谢。

【问题讨论】:

    标签: google-apps-script google-sheets hyperlink concatenation cell


    【解决方案1】:

    使用 onEdit(e) simple trigger,如下所示:

    /**
    * Simple trigger that runs each time the user manually edits the spreadsheet.
    *
    * @param {Object} e The onEdit() event object.
    */
    function onEdit(e) {
      if (!e) {
        throw new Error(
          'Please do not run the onEdit(e) function in the script editor window. '
          + 'It runs automatically when you hand edit the spreadsheet. '
          + 'See https://stackoverflow.com/a/63851123/13045193.'
        );
      }
      autoAsinHyperlink_(e);
    }
    
    
    /**
    * Monitors values that are manually entered in the spreadsheet and
    * inserts a hyperlink formula when the format matches asinRegex.
    *
    * @param {Object} e The onEdit() event object.
    */
    function autoAsinHyperlink_(e) {
      // version 1.0, written by --Hyde, 11 January 2023
      //  - see https://stackoverflow.com/q/75086109/13045193
      const asinRegex = /^(d[-d]{8,}d)$/;
      if (!e.value || !e.value.trim().match(asinRegex)) {
        return;
      }
      const link = 'https://www.amazon.co.uk/gp/your-account/order-details/ref=ppx_yo_dt_b_order_details_o00?ie=UTF8&orderID=';
      e.range.setFormula(`=hyperlink("${link}${e.value}"; "${e.value}")`);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 2020-10-16
      • 1970-01-01
      • 2021-09-30
      相关资源
      最近更新 更多