使用PHP的Google电子表格API v4 - 如何在开头插入空行

时间:2016-06-14 15:30:17

标签: php google-spreadsheet-api google-api-php-client

我对新的Google表格API v4感到困惑。 我的问题是:如何在电子表格的开头插入一行?

我无法找到适用于新Google Sheet API v4的任何有用教程,也无法从Google专门针对PHP查找可行的文档。

2 个答案:

答案 0 :(得分:6)

我明白了,

$requests = new Google_Service_Sheets_Request(array(
    'insertDimension' => array(
        'range' => array(
            'sheetId' => 0,
            'dimension' => "ROWS",
            'startIndex' => 1,
            'endIndex' => 2
        )
    )
));


$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
    'requests' => $requests
));


$this->service->spreadsheets->batchUpdate($this->sheetID, $batchUpdateRequest);

其中$ this->服务是Google_Service_Sheets的实例,$ this-> sheetID是来自google docs url的SheetID

答案 1 :(得分:0)

我是这样做的:

//Insert blank new row between R1 and R2 (there is no R0)
$dr = new Google_Service_Sheets_DimensionRange();
$dr->setSheetId(0);//first sheet/tab of spreadsheet file
$dr->setDimension('ROWS');
$dr->setStartIndex(1);
$dr->setEndIndex(2);
$ins = new Google_Service_Sheets_InsertDimensionRequest();
$ins->setRange($dr);
$ins->setInheritFromBefore(false);
$ssr = new Google_Service_Sheets_Request();
$ssr->setInsertDimension($ins);
$busr = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$busr->setRequests([$ssr]);
$response = $sheetsService->spreadsheets->batchUpdate($spreadsheetId, $busr, []);