Java Google SpreadSheet API,如何更新单元格以添加注释? [英] Java Google SpreadSheet API, how to update cell to add a note?
问题描述
好吧,我需要找到一种方法在Google电子表格中添加笔记,我正在使用Java进行连接.
Well, I need to find a way to add a note in a google spreadsheet, I'm using java to connect.
我已经建立了更改单元格颜色的请求,但是我找不到更新单元格以添加便条的方法.
I Have built a request that changes cell colours, but I can't find a way to update cell to add a note.
这是我更改构建请求以更改颜色的方法:
This is how I change build request to change the colour:
private Request buildRequestToPaintCell(int startRow, int endRow, int startColumn, int endColumn, int sheetId) {
Request request = new Request();
request.setRepeatCell(new RepeatCellRequest()
.setCell(new CellData()
.setUserEnteredFormat(new CellFormat().setBackgroundColor(new Color()
.setRed(1f)
.setGreen(0.0f)
.setBlue(0.0f))))
.setRange(new GridRange()
.setSheetId(sheetId)
.setStartRowIndex(startRow)
.setEndRowIndex(endRow)
.setStartColumnIndex(startColumn)
.setEndColumnIndex(endColumn))
.setFields("userEnteredFormat.backgroundColor")
);
return request;
}
我期望它能正常工作,但是由于我将字段设置为"*",所以它不能清除单元格并添加注释,但这不是我所需要的,我想我缺少正确的字段值只是更新便笺,我找不到它.
I was expecting this to work, but it doesn't as I set the field as '*' it clears the cell and adds the note, but that's not what I need, I think I'm missing the correct field value to update just the note, I can not find it yet.
private Request buildRequestAddNoteCell(int startRow, int endRow, int startColumn, int endColumn, int sheetId, String note) {
Request request = new Request();
request.setRepeatCell(new RepeatCellRequest()
.setCell(new CellData().setNote(note))
.setRange(new GridRange()
.setSheetId(sheetId)
.setStartRowIndex(startRow)
.setEndRowIndex(endRow)
.setStartColumnIndex(startColumn)
.setEndColumnIndex(endColumn))
.setFields("userEnteredFormat.note")
);
return request;
}
推荐答案
我找到了它.必须将字段设置为注释".缺少有关单元格字段的文档.
I found it. Had to set the fields as 'note'. It is missing doc about the cell fields.
示例代码:
private Request buildRequestAddNoteCell(int startRow, int endRow, int startColumn, int endColumn, int sheetId, String note) {
Request request = new Request();
request.setRepeatCell(new RepeatCellRequest()
.setCell(new CellData().setNote(note))
.setRange(new GridRange()
.setSheetId(sheetId)
.setStartRowIndex(startRow)
.setEndRowIndex(endRow)
.setStartColumnIndex(startColumn)
.setEndColumnIndex(endColumn))
.setFields("note")
);
return request;
}
这篇关于Java Google SpreadSheet API,如何更新单元格以添加注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!