admin管理员组

文章数量:1303404

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("/some/data"+variable+"something","something")");

I had tried several ways but none of them worked.

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.

Share Improve this question edited Jul 12, 2013 at 14:31 CharlesB 90.5k29 gold badges201 silver badges228 bronze badges asked Jul 12, 2013 at 14:10 Grzegorz G.Grzegorz G. 4273 gold badges6 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You are trying to include quotes inside quoted text. There are a couple of ways to do that.

  1. Use single quotes inside double quotes, or vice-versa.

    komorkaLinku.setValue('=HYPERLINK("http://www.some.link/some/data'+variable+'"something","something")');
    
  2. Use escaped single quotes.

    komorkaLinku.setValue('=HYPERLINK(\'http://www.some.link/some/data'+variable+'\'something\',\'something\')');
    

As @ScampMichael ments, it would be a better choice to use setFormula() in this case. You would still need to handle embedded quotes properly.

本文标签: javascriptInsertion of brackets and quotation marks using Google Apps ScriptStack Overflow