问题
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.
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\')');
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