【问题标题】:Batch updating cell not working for google spreadsheet api批量更新单元格不适用于谷歌电子表格 api
【发布时间】:2015-07-16 09:59:13
【问题描述】:

我设法更新了单个单元格,现在我尝试批量更新多个单元格,但它不起作用。请告诉我这段代码有什么问题。 这是我正在使用的代码:

$feed = "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>\n";
        $feed .= "<id>https://spreadsheets.google.com/feeds/cells/$gID/$workSheetID/private/full</id>\n";

        foreach($postData as $post)
        {
            $row = $post["row"];
            $col = $post["col"];
            $data = $post["data"];
            $rc = "R$row" . "C$col";
            $requestURL = "https://spreadsheets.google.com/feeds/cells/$gID/$workSheetID/private/full/batch";
            $url = "https://spreadsheets.google.com/feeds/cells/$gID/$workSheetID/private/full/$rc";

            $feed .= "<entry>\n";
            $feed .= "<batch:id>A$row</batch:id>\n";
            $feed .= "<batch:operation type = 'update'/>\n";
            $feed .= "<id>$url</id>\n";
            $feed .= "<link rel='edit' type='application/atom+xml' href=$url />\n";
            $feed .= "<gs:cell row=$row col=$col inputValue='newData' />\n";
            $feed .= "</entry>\n";
        }
        $feed .= "</feed>";

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $requestURL);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $feed);
        curl_setopt($curl, CURLOPT_HEADER, false);
        $headers = array(
            "Authorization: Bearer " . $this->accessTokenArray->access_token,
            "GData-Version: 3.0",
            "Content-Type: application/atom+xml",
            "If-Match: *",
        );
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_VERBOSE, true);
        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        return curl_exec($curl);

这是我得到的输出:

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
<id>https://spreadsheets.google.com/feeds/cells/1/13IBClQO0ZUdDXrPhEkpesKE6FKCxWDtPqLQXoK_JWXg/batch/1437040636408</id>
<updated>2015-07-16T09:57:16.413Z</updated>
<title>Batch Feed</title>
<entry>
<id>https://spreadsheets.google.com/feeds/cells/1/13IBClQO0ZUdDXrPhEkpesKE6FKCxWDtPqLQXoK_JWXg/batch/1437040636408/fatal</id>
<updated>2015-07-16T09:57:16.413Z</updated>
<title>Fatal Error</title>
<content>Feed processing was interrupted.</content>
<batch:interrupted reason='[Line 3, Column 8, element feed] The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn&apos;t deleted it.' parsed='0' success='0' error='0' unprocessed='0'/>
</entry>
</feed>

【问题讨论】:

    标签: php google-spreadsheet-api


    【解决方案1】:

    尝试在所有 URL 中交换 key 和 workSheetID 的值以进行批量更新调用,包括 XML 提要中的 URL,并且成功了。

    【讨论】:

      【解决方案2】:

      通过编辑以下代码行来更改版本

      GData-Version: 1.0". 
      

      还有

      $url = "https://spreadsheets.google.com/feeds/cells/$gID/$workSheetID/private/full/$rc";
      

      应该包括$rc之后的版本,必须是这样的

      https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full/R2C5/version, 
      

      检查文档。
      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2013-08-22
        • 1970-01-01
        • 2021-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-10
        • 1970-01-01
        相关资源
        最近更新 更多