【发布时间】:2019-07-25 17:12:44
【问题描述】:
我正在尝试更改电子表格中几个单元格的背景颜色和粗体值。我知道我有一个有效的服务,因为我之前正在更新电子表格值并且它有效。
更改值有效,所以我猜它一定是我的配置。我没有收到任何错误,$result 变量保持为空。任何想法将不胜感激,谢谢。
// known to work from changing the values
$client = getClient();
$service = new Google_Service_Sheets($client);
$spreadsheetId = 'MY SPREADSHEET ID';
// new code
$r = $g = $b = 0.5;
$a = 1;
$myRange = [
//'sheetId' => 0, // can be omitted because I'm working on the first sheet
'startRowIndex' => 5,
'endRowIndex' => 10,
//'startColumnIndex' => 0, // can be omitted because default is 0
'endColumnIndex' => 5,
];
$format = [
'backgroundColor' => [
'red' => $r,
'green' => $g,
'blue' => $b,
'alpha' => $a,
],
'textFormat' => [
'bold' => true
]
];
$requests = [
new Google_Service_Sheets_Request([
'repeatCell' => [
'fields' => 'userEnteredFormat.backgroundColor, userEnteredFormat.textFormat.bold',
'range' => $myRange,
'cell' => [
'userEnteredFormat' => $format,
],
],
])
];
$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => $requests
]);
$result = $service->spreadsheets->batchUpdate($spreadsheetId, $batchUpdateRequest);
【问题讨论】:
-
I [don't] get any errors如 我没有注意到任何错误消息? -
谢谢@greybeard,那条评论让我想到了正确的方向。请参阅下面的解决方案。
-
@Ja Nosch 感谢您的回复。我深表歉意,我的回答对解决您的问题没有用。不幸的是,从您的回答中,我无法理解您的最终脚本。那么您可以将最后一个添加到您的答案中吗?然后,从您的回复中,我可以知道我的回答不是必需的。所以我必须删除我的答案,因为我不想混淆其他用户。
-
@Tanaike,我在下面添加了完整的脚本。感谢您的提示,我从最初的问题中删除了错误的呼叫,以免其他人感到困惑。
-
@Ja Nosch 感谢您的回复。非常抱歉我的回答对解决您的问题没有帮助。
标签: php google-sheets google-sheets-api