简体   繁体   中英

Google Sheets V4 Java - clear a sheet

Besides the QuickStart tutorial - There is almost no examples of Google Sheets v4 with Java.

I'm trying to clear all the cells of a sheet using batchUpdate .

I read I need to add no values in order for it to remove all cells but it does nothing:

public void clearSheet(String sheetName) {
    try {
        // Build a new authorized API client service.
        Sheets service = GoogleApi.getInstance().getSheetsService();

        String spreadsheetId = GoogleSheetsSettings.getDataFileId();            

        BatchUpdateValuesRequest oRequest = new BatchUpdateValuesRequest();
        oRequest.setValueInputOption("RAW");
        //oRequest.setData(oList);
        BatchUpdateValuesResponse oResp1 = service.spreadsheets().values().batchUpdate(spreadsheetId, oRequest).execute();
    } catch (IOException ex) {
        Logger.getLogger(GoogleApi.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("Could not execute spreadsheet update");
    }        
}

What is the right approach?

工作的是:

service.spreadsheets().values().clear(spreadsheetId, range, new ClearValuesRequest()).execute()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM