Insertion of brackets and quotation marks using Google Apps Script

 ̄綄美尐妖づ 提交于 2021-02-05 05:56:49

问题


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.


回答1:


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 comments, it would be a better choice to use setFormula() in this case. You would still need to handle embedded quotes properly.



来源:https://stackoverflow.com/questions/17616908/insertion-of-brackets-and-quotation-marks-using-google-apps-script

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