本文介绍了我想使用googlesheet api v4删除googlesheet中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用googlesheetv4 API在googlesheet中使用rowno删除一行.有人可以为此提供示例代码吗?我创建了一种删除行的方法:

I want to delete a row using rowno in googlesheet using googlesheetv4 api.Can anybody provide me a sample code for this?I have created a method for delete row:

public void deleteRow() {

    BatchUpdateSpreadsheetRequest content = new BatchUpdateSpreadsheetRequest();
    Request request = new Request();
    request.setDeleteDimension(new DeleteDimensionRequest().setRange(new DimensionRange().setDimension("D30:D31")));

    List<Request> requests = new ArrayList<Request>();
    requests.add(request);
    content.setRequests(requests);
    System.out.println(content.getRequests());

    try {
        service.spreadsheets().batchUpdate(IConstant.SPREADSHEET_ID, content);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

推荐答案

您的代码看起来很接近,但是您没有正确设置DimensionRange.请尝试以下操作:

Your code looks close, but you aren't setting up the DimensionRange correctly. Try the following:

Request request = new Request()
  .setDeleteDimension(new DeleteDimensionRequest()
    .setRange(new DimensionRange()
      .setSheetId(0)
      .setDimension("ROWS")
      .setStartIndex(30)
      .setEndIndex(32)
    )
  );

这篇关于我想使用googlesheet api v4删除googlesheet中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 08:05