[英]Insertion of number sign (#) into a Google Spreadsheet via GAS
I have encountered a problem when trying to insert a "#" sign into a cell using script (that is triggered to run when a submission comes from a form). 尝试使用脚本在单元格中插入“#”符号时遇到了一个问题(当提交来自表单时会触发运行)。
I have tried to do it this way: 我试图这样做:
somecell.setFormula('=HYPERLINK("http://www.some.link/some/'+var+'#1a2b3c","'+var+'")');
So the output should be: 因此输出应为:
=HYPERLINK("http://www.some.link/some/1234#1a2b3c","1234")
But it is always inserted as only (no # and the rest of link after the sign) 但它总是作为唯一插入(没有#号,符号后的其余链接)
=HYPERLINK("http://www.some.link/some/1234","1234")
There are no errors reported during execution. 执行期间没有错误报告。 How should I put the sign into the script so it will be inserted into the formula?
我应该如何将符号放入脚本中,以便将其插入公式中? I had tried using ...1234(backslash)#1a... but it does not work.
我曾尝试使用... 1234(反斜杠)#1a ...,但不起作用。
Edit How does the script work (in short): firstly, sheet receives a form submission with an URL as one of the entries. 编辑脚本的工作原理(简而言之):首先,工作表接收带有URL的表单提交作为条目之一。 Then, the script cuts off part of the link (using .split('/') and then .pop() to get the last element of the array that .split created) and the variable extracted this was is used in the .setFormula seen above as var .
然后,脚本切断链接的一部分(使用.split('/') ,然后使用.pop()来获取.split创建的数组的最后一个元素),提取出的变量用于.setFormula中。在上面被视为var 。
Also, I have tried again; 另外,我再次尝试过; backslash does not work - everything after (and including) # is deleted.
反斜杠不起作用-删除#(包括)之后的所有内容。
You need to include a backslash to escape the character: 您需要添加一个反斜杠来转义该字符:
function addlink() {
var somecell = SpreadsheetApp.getActiveSpreadsheet().getRange('F2');
var blah = "123";
somecell.setFormula('=HYPERLINK("http://www.some.link/some/'+blah+'\#1a2b3c","'+blah+'")');
// ^^^
}
I tried your example like this : 我尝试了这样的示例:
function test(){
var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var xx = '1234'
sh.getRange('A2').setFormula('=HYPERLINK("http://www.some.link/some/'+xx+'#1a2b3c","'+xx+'")');
}
and I get the expected result 我得到了预期的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.