使用Google Apps脚本插入方括号和引号 [英] Insertion of brackets and quotation marks using Google Apps Script
问题描述
我最近开始为Google Spreadsheets编写一些脚本.我没有使用Javascript的经验,但是我有一个关于(我想是)基本问题的问题.
I have recently started writing some scripts for Google Spreadsheets. I have no experience with Javascript though and I have question that is concerning a (as I suppose) basic issue.
我希望我的脚本将下面显示的数据插入工作表的单元格中.我应该如何编码才能使其正常工作?
I would like my script to insert data shown below into a cell in a sheet. How should I encode it to make it work?
komorkaLinku.setValue("=HYPERLINK("http://www.some.link/some/data"+variable+"something","something")");
我尝试了几种方法,但没有一种起作用.
I had tried several ways but none of them worked.
推荐答案
您正试图在引号内添加引号.有两种方法可以做到这一点.
You are trying to include quotes inside quoted text. There are a couple of ways to do that.
-
在双引号中使用单引号,反之亦然.
Use single quotes inside double quotes, or vice-versa.
komorkaLinku.setValue('=HYPERLINK("http://www.some.link/some/data'+variable+'"something","something")');
使用转义单引号.
Use escaped single quotes.
komorkaLinku.setValue('=HYPERLINK(\'http://www.some.link/some/data'+variable+'\'something\',\'something\')');
正如@ScampMichael所评论的,在这种情况下,使用 setFormula()
是一个更好的选择.您仍然需要正确处理嵌入的报价.
As @ScampMichael comments, it would be a better choice to use setFormula()
in this case. You would still need to handle embedded quotes properly.
这篇关于使用Google Apps脚本插入方括号和引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!