PHP Google Spreadsheet选择sheet写入

PHP Google Spreadsheets choose sheet to write in

我正在实施与 Google Spreadsheets API 和 PHP 的集成。我正在使用 google.

建议的库

我需要在同一个文件中包含多个 sheet(页面)。到目前为止,我发现我可以使用如下方式创建新页面:

    $body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
        'requests' => array('addSheet' => array('properties' => array('title' => $title )))));

    $result = $service->spreadsheets->batchUpdate(SHEET_ID,$body);

但我如何选择何时在一个 sheet(页面)或另一页上书写?有什么方法可以让我根据标签选择 sheet 吗?

希望你能帮助我。

而不是单独指定 sheet,基于 Basic Writing sample,您可以使用 PUT 方法写入特定 sheet 的特定范围:

PUT https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5?valueInputOption=USER_ENTERED

spreadsheets.values.update request will write the values on the cells from A1 to D5 on Sheet1. Note that the ValueInputOption 查询参数是必需的,用于确定写入的值是否会被解析(例如,是否将字符串转换为日期)。

请求正文将如下所示:

{
  "range": "Sheet1!A1:D5",
  "majorDimension": "ROWS",
  "values": [
    ["Item", "Cost", "Stocked", "Ship Date"],
    ["Wheel", ".50", "4", "3/1/2016"],
    ["Door", "", "2", "3/15/2016"],
    ["Engine", "0", "1", "30/20/2016"],
    ["Totals", "=SUM(B2:B4)", "=SUM(C2:C4)", "=MAX(D2:D4)"]
  ],
}