Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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

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电子表格API PHP_Php_Google Sheets_Google Api_Google Sheets Api - Fatal编程技术网

无法隐藏网格线Google电子表格API PHP

无法隐藏网格线Google电子表格API PHP,php,google-sheets,google-api,google-sheets-api,Php,Google Sheets,Google Api,Google Sheets Api,我正在尝试隐藏刚用Google Sheets API创建的文件中的所有网格线,我使用以下代码: $service = $this->GoogleServiceSheets(); $sheetID = null; $worksheetSheets = $service->spreadsheets->get($fileID)->sheets; foreach($worksheetSheets as $sheet){ $sheetID = $sheet->pro

我正在尝试隐藏刚用Google Sheets API创建的文件中的所有网格线,我使用以下代码:

$service = $this->GoogleServiceSheets();
$sheetID = null;
$worksheetSheets = $service->spreadsheets->get($fileID)->sheets;
foreach($worksheetSheets as $sheet){ 
    $sheetID = $sheet->properties['sheetId'];     
    break;
}
$service = $this->GoogleServiceSheets(); 

$requests = [
    new \Google_Service_Sheets_Request([
        'updateDimensionProperties' => [
            'range'=> new \Google_Service_Sheets_DimensionRange([
                'sheetId' => $sheetID,
                'dimension' => 'COLUMNS',
                'startIndex' => 0,
                'endIndex' => 1000        
            ]),
            'properties'=> new Google_Service_Sheets_DimensionProperties([
                "hideGridlines"=> True,                 
            ]),
            'fields' => 'hideGridlines'
        ]
    ])
];



$batchUpdateRequest = new \Google_Service_Sheets_BatchUpdateSpreadsheetRequest(['requests' => $requests]);
$service->spreadsheets->batchUpdate($fileID, $batchUpdateRequest);   
但是没有隐藏,反而给了我一个错误。
我做错了什么?

为了用Sheets API隐藏Google电子表格的网格线,使用了batchUpdate的UpdateSheetProperties请求。不幸的是,
updateDimensionProperties
无法实现这一点。我想这就是你的问题所在。为了实现您的目标,当您的脚本被修改时,它将变成如下所示

$requests = [
    new \Google_Service_Sheets_Request([
        'updateSheetProperties' => [
            'properties' => [
                'sheetId' => $sheetID,
                'gridProperties' => [
                    'hideGridlines' => true
                ],
            ],
            'fields' => 'gridProperties.hideGridlines'
        ],
    ])
];
修改脚本: 在此修改中,您的
$requests
修改如下

$requests = [
    new \Google_Service_Sheets_Request([
        'updateSheetProperties' => [
            'properties' => [
                'sheetId' => $sheetID,
                'gridProperties' => [
                    'hideGridlines' => true
                ],
            ],
            'fields' => 'gridProperties.hideGridlines'
        ],
    ])
];
注:
  • 在这个修改中,它假设您的
    $service=$this->GoogleServiceSheets()
    $sheetID
    是有效值。此外,它还假设您已经能够使用Sheets API获取和输入Google电子表格的值。请小心这个
参考: