Getting a Google Spreadsheet Cell's Image URL

前端 未结 2 552
耶瑟儿~
耶瑟儿~ 2021-01-15 06:50

I have a Google Spreadsheet that has an image on the 2nd and 3rd column of each row, and I am trying to log all of the spreadsheet data to the console (for now). I\'m havin

相关标签:
2条回答
  • 2021-01-15 06:58

    Range.getValue() returns the computed value of a cell, which in this case is an image, not a URL. As you've found, you can use getFormula() to get the formula that created the image. You can use a regular expression to extract the image URL from the formula string.

    function getImageUrl(formula) {
      var regex = /=image\("(.*)"/i;
      var matches = formula.match(regex);
      return matches ? matches[1] : null;
    }
    

    This won't work if the URL is computed from another cell or formula, but it should work for the simple case you have listed.

    0 讨论(0)
  • 2021-01-15 06:58

    Use Find And replace Edit > Find and replace

    And check Also search within formulas in Find and replace box

    0 讨论(0)
提交回复
热议问题