Google Sheets/Excel: IMAGE() formula into plain URL

我的未来我决定 提交于 2021-02-10 18:40:40

问题


I am converting a Google Sheets file into a CSV format.

Some cells have an image inserted into them via =IMAGE("https://placekitten.com/200/300")

I need to be able to extract in plain text https://placekitten.com/200/300

Is this possible? I've tried SUBSTITUTE but of course that doesn't work.

Thanks to whoever can solve this!


回答1:


try:

=REGEXEXTRACT(FORMULATEXT(A2); """(.*)""")




回答2:


I thought that explaining @player0’s answer would be nice, especially for future people.

His answer can be split in 2 parts:

  • Using FORMULATEXT to get the formula
  • Using a regular expression to extract the URL from it

The first part is FORMULATEXT. It is pretty self explanatory: it takes a cell and returns the formula as string.

The second part is using a regular expression (see wikipedia article and documentation on the exact syntax used by Google) to extract the URL. In this case @player0 relies on the fact that the URL is the only quoted text of that formula. So using the regex "(.+)" will match the quoted part inside the quotes of the formula, and thus only the URL. When using literal strings in a formula, you need to surround them with quotes (eg hello as "hello"). Double quotes need to be doubled (eg aaa"aaa is written as "aaa""aaa"). So "(.+)" becomes """(.+)""".

References

  • FORMULATEXT (Docs Editors Help)
  • REGEXEXTRACT (Docs Editors Help)
  • Regular expression (Wikipedia)
  • RE2 syntax (Google’s RE2 repository on GitHub)


来源:https://stackoverflow.com/questions/66027738/google-sheets-excel-image-formula-into-plain-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!