简体   繁体   English

Google Sheets API(PHP)批量更新

[英]Google Sheets API (PHP) Batch Update

I would like to use the Google Sheets API Batch Update because the calls to update individual cells are extremely slow. 我想使用Google Sheets API批处理更新,因为更新单个单元格的调用非常慢。 The problem is that cells that have no data do not come back as part of a cell feed, so I do not have the necessary edit URL to include those cells in the Batch Update. 问题是没有数据的单元格不会作为单元格提要的一部分返回,因此我没有必要的编辑URL来将这些单元格包括在批处理更新中。 I have seen reference to a "return-empty" parameter in the Google .NET API which will supposedly return all cells, even empty cells, in a cell feed, but I cannot find any reference to that for the "Protocol" API I am using in PHP (here is an example of a reference to the "return-empty" parameter: Writing to an empty cell in Google Spreadsheets ). 我已经在Google .NET API中看到了对“ return-empty”参数的引用,据称该参数会返回单元格供稿中的所有单元格,甚至是空单元格,但是我找不到对“ Protocol” API的任何引用在PHP中使用(这里是对“ return-empty”参数的引用的示例: 写入Google Spreadsheets中的空单元格 )。 Does anyone know how to get the cell feed request to return all cells (including empty cells)? 有谁知道如何获取单元格提要请求以返回所有单元格(包括空单元格)? Or am I doomed to using the abysmally slow cell update requests? 还是我注定要使用abysmally慢单元更新请求?

Quick Hack 快速黑客

If you're using the same API I am , then in googlespraedsheet/api.php at line 152 after 如果您使用的是相同的API ,请在googlespraedsheet/api.php中的第152行之后

$cellRangeCriteriaQuerystringList = [];

You can add: 你可以加:

$cellRangeCriteriaQuerystringList[] = "return-empty=true";

Better Way 更好的方法

There's a better way, which I have added in my own fork . 有一种更好的方法,我已经在自己的fork中添加了。 I created a pull request . 我创建了一个请求请求

If you work with my fork (or if the pull request is accepted), then you can just add 'returnEmpty' => true to your $cellRange . 如果您使用我的叉子(或者如果接受了拉取请求),则只需在$cellRange添加'returnEmpty' => true即可。 For example: 例如:

    $cellList = $spreadsheetAPI->getWorksheetCellList(
                    $spreadsheetKey,
                    $worksheetID,
                    ['rowStart' => $rowStart,
                     'rowEnd' => $rowEnd,
                     'returnEmpty' => true]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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