0

I am using the Google Sheets API to to read spreadsheets and operate on the data. My application has limited permissions on the sheet it's operating on. I can not edit cell values, only add comments.

I want to use my application to write comments on specific cells (e.g M64 or A1), but I cannot figure out how to do it. I saw Insert a comment in a Google Sheet with google-sheets-api, but this thread does not present a way to insert comments with Java.

I attempted the following, which I found on Java Google SpreadSheet API, how to update cell to add a note?. It executed with no errors, but the cell never obtained a comment:

Request request = new Request();
request.setRepeatCell(
        new RepeatCellRequest()
        .setCell(
                new CellData()
                .setNote("test"))
        .setRange(
                new GridRange()
                .setSheetId(1)  // Sheet 1
                .setStartRowIndex(0)
                .setEndRowIndex(13)     //
                .setStartColumnIndex(0) // Cell M64
                .setEndColumnIndex(64)  //
        )
        .setFields("note")
        );
BatchUpdateSpreadsheetRequest batch = new BatchUpdateSpreadsheetRequest();
batch.setRequests(Arrays.asList(new Request[] {request}));
service.spreadsheets().batchUpdate(spreadsheetId, batch);

Does anyone know how to use the Google API Client Library for Java and the Sheets API to add a comment to a spreadsheet?

Cardinal System
  • 2,749
  • 3
  • 21
  • 42
  • Although I'm not sure about the whole script, how about modifying from ``service.spreadsheets().batchUpdate(spreadsheetId, batch)`` to ``service.spreadsheets().batchUpdate(spreadsheetId, batch).execute()``? [Ref](https://developers.google.com/sheets/api/guides/batchupdate?hl=en) If this was not the direct solution, I apologize. – Tanaike Jun 17 '19 at 23:02
  • @Tanaike that actually got me somewhere! Now I am having trouble with authentication though... – Cardinal System Jun 18 '19 at 00:01
  • Thank you for replying. I apologize that my proposal was not the direct solution of your issue. – Tanaike Jun 18 '19 at 00:03

0 Answers0