【发布时间】:2019-08-22 18:19:24
【问题描述】:
在 Google 表格 java api 中,我正在执行 BatchUpdateSpreadsheetRequest,它正在更新表格中单元格的文本和颜色,但它似乎忽略了我的范围请求,告诉它更新第二张而不是第一张。
当我使用下面的字符串列表为整个电子表格设置文本时,它就开始工作了
service.spreadsheets().values().update(spreadsheetId, "Sheet2", body).execute();
但这并不能处理更改单元格的颜色。因此,我尝试使用 CellData 对象列表进行批量更新,这适用于第一个工作表选项卡,但拒绝遵守告诉每个请求在第二个工作表上工作的范围。它总是只更新 Sheet1 而不是 Sheet2。
//for every row, do an update request updating that row
List<Request> requests = new ArrayList<>();
List<String> ranges = new ArrayList<>();
int row=0;
while(row < values.size())
{
//add the request that will update the rows text and cell colors
requests.add(new Request()
.setUpdateCells(new UpdateCellsRequest()
.setStart(new GridCoordinate().setRowIndex(row).setColumnIndex(0))
.setRows(Arrays.asList(new RowData().setValues(values.get(row))))
.setFields("userEnteredValue,userEnteredFormat.backgroundColor")));
//add the range specifying that this update should be applied to the second sheet
ranges.add("Sheet2");
row++;
}
//Do tha batch update we just defined
BatchUpdateSpreadsheetRequest batchUpdateRequest = new BatchUpdateSpreadsheetRequest()
.setResponseRanges(ranges) //all ranges are set to "Sheet2" so why are the requests still updating "Sheet1"??
.setRequests(requests);
service.spreadsheets().batchUpdate(spreadsheetId, batchUpdateRequest)
.execute();
如何让它将更新应用到 Sheet2?
【问题讨论】: