【问题标题】:Google Sheets V4 Java - clear a sheetGoogle Sheets V4 Java - 清除工作表
【发布时间】:2016-12-19 12:36:38
【问题描述】:

除了快速入门教程 - 几乎没有使用 Java 的 Google Sheets v4 示例。

我正在尝试使用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");
    }        
}

什么是正确的方法?

【问题讨论】:

  • 如果它可以帮助你,请尝试检查这个Method: spreadsheets.values.clear。它从电子表格中清除值。调用者必须指定电子表格 ID 和范围。只有值被清除——单元格的所有其他属性(例如格式、数据验证等)都被保留。查看此SO question 了解更多信息。

标签: java google-sheets google-spreadsheet-api


【解决方案1】:

有效的是:

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

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    相关资源
    最近更新 更多