简体   繁体   English

通过GAS将数字符号(#)插入Google电子表格

[英]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.

相关问题 如何检查用户是否空闲并切换标签页? 通过脚本(谷歌电子表格 - GAS) - How to check if the user is idle and switch tabs? via script (Google Spreadsheet - GAS) 如何基于单个单元格编辑(Google Script / GAS)通过电子邮件发送电子表格中的整行数据 - How to send whole row of data in my spreadsheet via email based on single cell edit (Google Script / GAS) 在GAS中,通过循环读取电子表格中多个工作表中的数据列 - In GAS, reading col of data in multiple sheets in spreadsheet via loop 如何检查谷歌电子表格中的输入数据是否是 GAS 的有效日期类型 - how to check if the input data in google spreadsheet is a valid Date type by GAS 将数据推送到不同的元素,具体取决于使用 GAS 的谷歌电子表格中的列? - Push data to different elements, depending on column in google spreadsheet with GAS? Google脚本中的Amcharts(通过电子表格) - Amcharts in Google script (via Spreadsheet) 通过 JSON 提供超链接的 Google 电子表格 - Google spreadsheet with hyperlinks via JSON GAS:用于电子邮件的SpreadSheet出错 - GAS: Error on SpreadSheet for mailing 我无法通过 GAS 将部分数据从 chrome 扩展发送到电子表格 - I cannot send a part of data from chrome extension to Spreadsheet via GAS 在 Google 表格单元格 (GAS) 中打印未指定数量的数组内容 - Printing Unspecified Number of Array Contents in Google Sheets Cells (GAS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM