2017-02-26 36 views
1

我想開始將依賴Google Spreadsheet API(v3)的應用程序遷移到Google Sheets API v4。然而,在我開始之前,我還有一個問題仍然存在。如何處理使用Google Sheets API v4檢索行的結構化查詢

在Google Sheets API v3中,我可以使用請求URL中的sq參數獲得結構化查詢的基於行的Feed。如果工作表有10000行,並且我只需要在特定列中獲取具有特定值的行,這將非常有用。速度方面也非常有效。

在看谷歌的遷移指南,以V4,我發現在「檢索行數據」這一說法:

The Sheets API v4 does not currently have a direct equivalent for the Sheets 
API v3 structured queries. However, you can retrieve the relevant data and 
sort through it as needed in your application. 

我如何去從有效地考慮到10000行的表中檢索「相關數據」在v4 API中沒有結構化查詢。我寧願不必檢索所有10000行來篩選該響應。特別是因爲它會減慢我的應用程序,並可能增加通過電線發送的數據量。

使用v4 API,我如何檢索在特定列(或一組列)中具有特定值的行?

回答

1

我不需要參考文檔,因爲您已經意識到了這一點。在Sheetsv4中沒有這種功能。您必須手動執行Basic Reading methods並解析響應,循環播放並篩選您要查找的值。

這與您的SO question here有關。我已經在那裏寫了一些代碼,所以我只是在這裏發佈結果,以便您瞭解我是如何搜索值的。

enter image description here

爲取得用於phone,我通過JSON響應循環:

arrayBuffer = xhr.response; 
      console.log("arrayBuffer "+ arrayBuffer); 
      myArr = JSON.parse(arrayBuffer); 

       for(var i = 0; i < myArr.values.length; i++){ 

       if(myArr.values[0][i] === "phone"){ 
        console.log("column position is " + (i+1)); // +1 because counting starts at 0 
       } 
       } 

您也可以提交Feature Request here

相關問題