Writing a setFormula() with a query formula

↘锁芯ラ 提交于 2021-02-10 18:20:47

问题


Good evening, I have a formula in a cell:

=query(IMPORTRANGE("1O9JBXnSpnigfVpMqNHq6nHcaHb7VwdroDgzDqfnD8iM";"'Tableau detail'!$b$3:$c");"select Col2 where (Col1='"&'Feuille 1'!$E$12&"')")

I would like to integrate it into a script with setformula (). I tried with this writing:

formuleNombre.setFormula('=query(IMPORTRANGE("1O9JBXnSpnigfVpMqNHq6nHcaHb7VwdroDgzDqfnD8iM";"'Tableau detail'!$b$3:$c");"select Col2 where (Col1='"&'Feuille 1'!$E$12&"')")');

but it does not work :( I've this error :

formula analysis error.

I tried this one too :

formuleNombre.setFormula('=query(IMPORTRANGE("1O9JBXnSpnigfVpMqNHq6nHcaHb7VwdroDgzDqfnD8iM";"\'Tableau detail\'!$b$3:$c");"select Col2 where (Col1='"&\'Feuille 1\'!$E$12&"')")');

and i've this error

Sign) missing after the argument list. (line 56, file "Code")

Line 56 is the line where there is the formula above..... I do not see at all or where this error is.

Could you help me please.

Cordially.


回答1:


The reason you are having this error is because of the ' '.

The formula you need to input in the setFormula must be a string, and what you give is:

'=query(
    IMPORTRANGE(
        "1O9JBXnSpnigfVpMqNHq6nHcaHb7VwdroDgzDqfnD8iM";
        "'Tableau detail'!$b$3:$c"
    );
    "select Col2 where (Col1='"&'Feuille 1'!$E$12&"')"
)'

You string is between single quotes, but you have single quotes in it. You'll need to escape all the single quotes of the string, something like.

'=query(IMPORTRANGE("1O9JBXnSpnigfVpMqNHq6nHcaHb7VwdroDgzDqfnD8iM";"\'Tableau detail\'!$b$3:$c");"select Col2 where (Col1=\'"&\'Feuille 1\'!$E$12&"\')")'


来源:https://stackoverflow.com/questions/49158072/writing-a-setformula-with-a-query-formula

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