更改 google 张工作表的背景颜色
Change background color for google sheets
我正在与 google sheet 合作。我想编辑 sheet 上单元格的颜色。但这似乎不起作用。有人请帮助我。
Color color = new Color().setRed(Float.valueOf("1"))
.setGreen(Float.valueOf("0"))
.setBlue(Float.valueOf("0"));
CellFormat cellFormat = new CellFormat().setBackgroundColor(color);
CellData cellData = new CellData().setEffectiveFormat(cellFormat);
List<CellData> cellDataList = List.of(cellData);
RowData rowData = new RowData().setValues(cellDataList);
List<RowData> rowDataList = List.of(rowData);
GridRange gridRange = new GridRange().setSheetId(0).setStartRowIndex(0).setEndRowIndex(1).setStartColumnIndex(1).setEndColumnIndex(2);
UpdateCellsRequest updateCellsRequest = new UpdateCellsRequest().setRange(gridRange).setRows(rowDataList).setFields("userEnteredFormat.backgroundColor");
Request request = new Request().setUpdateCells(updateCellsRequest);
List<Request> requestList = List.of(request);
BatchUpdateSpreadsheetRequest update =
new BatchUpdateSpreadsheetRequest().setRequests(requestList);
service.spreadsheets().batchUpdate("1uZZkQ8XAgCe1R_tYqoFQ4Kva-H3il-G2mq2cEiAcBqM", update).execute();
通过替换此代码解决问题
CellFormat cellFormat = new CellFormat().setBackgroundColor(color);
CellData cellData = new CellData().setUserEnteredFormat(cellFormat);
RepeatCellRequest repeatCellRequestRed = new RepeatCellRequest()
.setRange(gridRange)
.setCell(cellData)
.setFields("userEnteredFormat.backgroundColor");
Request request = new Request().setRepeatCell(repeatCellRequestRed);
我正在与 google sheet 合作。我想编辑 sheet 上单元格的颜色。但这似乎不起作用。有人请帮助我。
Color color = new Color().setRed(Float.valueOf("1"))
.setGreen(Float.valueOf("0"))
.setBlue(Float.valueOf("0"));
CellFormat cellFormat = new CellFormat().setBackgroundColor(color);
CellData cellData = new CellData().setEffectiveFormat(cellFormat);
List<CellData> cellDataList = List.of(cellData);
RowData rowData = new RowData().setValues(cellDataList);
List<RowData> rowDataList = List.of(rowData);
GridRange gridRange = new GridRange().setSheetId(0).setStartRowIndex(0).setEndRowIndex(1).setStartColumnIndex(1).setEndColumnIndex(2);
UpdateCellsRequest updateCellsRequest = new UpdateCellsRequest().setRange(gridRange).setRows(rowDataList).setFields("userEnteredFormat.backgroundColor");
Request request = new Request().setUpdateCells(updateCellsRequest);
List<Request> requestList = List.of(request);
BatchUpdateSpreadsheetRequest update =
new BatchUpdateSpreadsheetRequest().setRequests(requestList);
service.spreadsheets().batchUpdate("1uZZkQ8XAgCe1R_tYqoFQ4Kva-H3il-G2mq2cEiAcBqM", update).execute();
通过替换此代码解决问题
CellFormat cellFormat = new CellFormat().setBackgroundColor(color);
CellData cellData = new CellData().setUserEnteredFormat(cellFormat);
RepeatCellRequest repeatCellRequestRed = new RepeatCellRequest()
.setRange(gridRange)
.setCell(cellData)
.setFields("userEnteredFormat.backgroundColor");
Request request = new Request().setRepeatCell(repeatCellRequestRed);