Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets 谷歌电子表格API:单元格中的注释_Google Sheets_Google Sheets Api - Fatal编程技术网

Google sheets 谷歌电子表格API:单元格中的注释

Google sheets 谷歌电子表格API:单元格中的注释,google-sheets,google-sheets-api,Google Sheets,Google Sheets Api,我制作了一个php脚本,使用api v4将一些信息导出到google电子表格。当我尝试向单元格中添加注释时,我应该为每个注释向API发出请求,这对我来说是一个问题,前面解释过 我目前的方法如下,我尝试在单行的每一列上添加注释($headerNotes是一个数组): 在这种方法中,注释是一个接一个地添加的(使用循环),并且工作正常。主要的问题是,我做的请求和notes一样多,而谷歌的Cuota有限。(每100秒每个用户有100个写入请求)。我需要优化请求的数量,我只需要发出一个请求,在同一行的不同

我制作了一个php脚本,使用api v4将一些信息导出到google电子表格。当我尝试向单元格中添加注释时,我应该为每个注释向API发出请求,这对我来说是一个问题,前面解释过

我目前的方法如下,我尝试在单行的每一列上添加注释($headerNotes是一个数组):

在这种方法中,注释是一个接一个地添加的(使用循环),并且工作正常。主要的问题是,我做的请求和notes一样多,而谷歌的Cuota有限。(每100秒每个用户有100个写入请求)。我需要优化请求的数量,我只需要发出一个请求,在同一行的不同单元格中添加不同的注释。阅读google电子表格文档,我可以看到请求中的“note”节点正在请求字符串值:

  "note": string,


我如何才能向不同的单行单元格添加不同的注释,而不需要发出如此多的请求?

如RowData对象[1]的文档中所述,
字段是一个数组,其中每个值(CellData对象)都是要插入到每个单元格中的值。您还需要使用一个范围,该范围可以覆盖要在每行中插入的所有值。我修改并测试了您的代码,在第一行的前5列中插入注释,并成功地工作:

$client = getClient();
$service = new Google_Service_Sheets($client);
$cellstart = 0;
$cellend = 5;
$note = "whatever";
$row = 1;

$body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
    'requests' => array(
        'updateCells' => array(
            'rows' => array(
                'values' => array(
                    array('note' => $note),
                    array('note' => $note),
                    array('note' => $note),
                    array('note' => $note),
                    array('note' => $note)
                )
            ),
            'fields' => 'note',
            'range' => array(
                'sheetId' => $sheetId,
                'startRowIndex' => $row-1,
                'endRowIndex' => $row,
                'startColumnIndex' => $cellstart,
                'endColumnIndex' => $cellend
            )
        )
    )
));
$service->spreadsheets->batchUpdate($spreadsheetId, $body)

[1]

您知道增加Gsheet的配额吗?每100秒的限制和用户是100写请求,这对我们来说非常低。如果我想提高价格,我找不到有关价格的信息。根据此页面:似乎我应该有一个计费帐户,但没有关于配额增加时定价的信息。因为Sheets是一个G套件应用程序,而不是GCP,由域中的用户计费,而不是为了增加配额。您仍然需要一个计费帐户来请求增加配额,直到每个用户每100秒有500个请求。
$client = getClient();
$service = new Google_Service_Sheets($client);
$cellstart = 0;
$cellend = 5;
$note = "whatever";
$row = 1;

$body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
    'requests' => array(
        'updateCells' => array(
            'rows' => array(
                'values' => array(
                    array('note' => $note),
                    array('note' => $note),
                    array('note' => $note),
                    array('note' => $note),
                    array('note' => $note)
                )
            ),
            'fields' => 'note',
            'range' => array(
                'sheetId' => $sheetId,
                'startRowIndex' => $row-1,
                'endRowIndex' => $row,
                'startColumnIndex' => $cellstart,
                'endColumnIndex' => $cellend
            )
        )
    )
));
$service->spreadsheets->batchUpdate($spreadsheetId, $body)