问题
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