I'm facing an issue within updating of existing spreadsheet on google drive, without using a batch update (right now I'm not sure whether it is even possible)
I already have existing spreadsheet with some data, then I retrieve file from google drive via
Drive drive = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
drive.files().list().execute().getItems()
I easily match my file by the name and then I just want to update the spreadsheet in the founded file.
Sheets service = new Sheets.Builder(GoogleNetHttpTransport.newTrustedTransport(), JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
Spreadsheet spreadsheet = service.spreadsheets().get(file.getId()).execute().setSheets(new ArrayList<>());
Here I get spreadsheet from file which match the name and then I just want to put there empy sheet (for example).
There is first point, where I'm not sure how to correctly "update" the spreadsheet on drive, because I cannot use
service.spreadsheets().create(spreadsheet).execute();
and I don't want to use batch update, because I already have set the spreadsheet content via setSheet() method.
I think it should be finalized with following:
Permission permission = drive.permissions().get(file.getId(), permissionId).execute().setType("anyone");
drive.permissions().update(
spreadsheet.getSpreadsheetId(),
permissionId,
permission
).execute();
I was checking the google API here: https://developers.google.com/drive/v2/reference/permissions/update and here: https://developers.google.com/sheets/api/guides/batchupdate but they are using batch update.
What I am curious is why there is setSheets() method, which seems to be easily to use for updates, when I already created my sheets, but it seems that I just cannot simply update spreadsheet in existing file.
What is also interesting that every time I use the drive.perm.update, it creates a new file(with spreadsheet that I wanted to update) which actually doesn't make much sense to me.
So is there any chance to simply update file on drive and just use the spreadsheet method?