2016-12-19 28 views
1

クイックスタートチュートリアルの他に、GoogleスプレッドシートにはJavaを使用した例はほとんどありません。GoogleスプレッドシートV4 Java - シートを消去

batchUpdateを使用してシートのすべてのセルを消去しようとしています。

私はそれがすべての細胞を除去するためには値を追加する必要がありませんが、それは何もしません読み:

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"); 
    }   
} 

正しいアプローチは何ですか?

+0

[ '方法:spreadsheets.values.clear']これをチェックしてみてください(https://developers.google.com/sheets/api/reference/rest/v4を/spreadsheets.values/clear)それがあなたを助けることができるなら。スプレッドシートから値をクリアします。呼び出し元はスプレッドシートのIDと範囲を指定する必要があります。値のみがクリアされます。セルのその他のプロパティ(フォーマット、データ検証など)はすべて保持されます。詳細については、この[SOの質問](http://stackoverflow.com/questions/37928947/)をチェックしてください。 – KENdi

答えて

2

作業1は、次のとおりです。

service.spreadsheets().values().clear(spreadsheetId, range, new ClearValuesRequest()).execute() 
関連する問題