简体   繁体   中英

Referencing cell value of a query formula in Google Sheets via apps script does not appear to work

I am attempting to copy the value of a cell to another cell using Apps Script. Source cell's value is produced by a query formula:

=sum(iferror(query(ExportDrop!$A$2:$AJ,"select AJ where A matches '" & join("|",C$3:C) & "' AND AH = '" & A3 & "'",0),0))

Source sheet displays the output of this query formula successfully and correctly.

Working within a script, the following code produces a zero (0), which is different than when viewing the sheet.

cellval = sourceSheet.getRange("B3").getValue();
SpreadsheetApp.getUi().alert(cellval); return;

I have attempted getDisplayValue(), getValue(), getValues() (with corresponding change to the range reference), using setActiveRangeSelection(), copyValuesToRange(), copyTo(,{contentsOnly: true}) etc.

Is this a bug in Google Sheet's query function? I wonder because the same thing occurs when I print to PDF the source sheet containing a query function. The resulting PDF shows zero-values. So it appears not to be an issue with my script, but more like an issue with the source sheet. Tests of a "simpler" query-formula sheet printed work fine.

What am I doing wrong?

EDIT:

Here is an example: https://docs.google.com/spreadsheets/d/1eHHV-TJhC_aVNNLspx3suKhrthtcjRfIcZR0dWdTvOI

Try printing Sheet2. The first PDF "preview" looks good, but upon opening the PDF after export, the sum values are all zeros.

ANSWER: Google Sheets Query function has advertised features that are broken/incomplete.

Example: matches run's locally and never on the google server causing desync issue, format boolean does not work at all.

Work around: Use a series of OR in lieu of the matches

=sum(iferror(query(Sheet1!$A$2:C,"select C where (A = " &join(" OR A = ",filter(C$1:C,C$1:C<>"")) & ") AND B = '" & A1 & "'",0),0))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM