使用google sheet api删除google sheet中的行
delete row in googlesheet using googlesheetapi
我想使用 googlesheetv4 api 在 googlesheet 中使用 rowno 删除一行。
有人可以为此提供示例代码吗?我创建了一个删除行的方法
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();
}
}
要使用 google Sheet v4 api 删除 google Sheet 中的行,我们必须设置开始索引和结束索引以及 sheet 编号
请参阅下面的示例
public void deleteRow(Integer StartIndex, Integer EndIndex) {
Spreadsheet spreadsheet = null;
try {
spreadsheet = service.spreadsheets().get(GoogleExcelFileUtil.SPREASHEET_ID).execute();
} catch (IOException e1) {
e1.printStackTrace();
}
BatchUpdateSpreadsheetRequest content = new BatchUpdateSpreadsheetRequest();
Request request = new Request();
DeleteDimensionRequest deleteDimensionRequest = new DeleteDimensionRequest();
DimensionRange dimensionRange = new DimensionRange();
dimensionRange.setDimension("ROWS");
dimensionRange.setStartIndex(StartIndex);
dimensionRange.setEndIndex(EndIndex);
dimensionRange.setSheetId(spreadsheet.getSheets().get(0).getProperties().getSheetId());
deleteDimensionRequest.setRange(dimensionRange);
request.setDeleteDimension(deleteDimensionRequest);
List<Request> requests = new ArrayList<Request>();
requests.add(request);
content.setRequests(requests);
try {
service.spreadsheets().batchUpdate(GoogleExcelFileUtil.SPREASHEET_ID, content).execute();
} catch (IOException e) {
e.printStackTrace();
} finally {
dimensionRange = null;
deleteDimensionRequest = null;
request = null;
requests = null;
content = null;
}
}
我想使用 googlesheetv4 api 在 googlesheet 中使用 rowno 删除一行。 有人可以为此提供示例代码吗?我创建了一个删除行的方法 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();
}
}
要使用 google Sheet v4 api 删除 google Sheet 中的行,我们必须设置开始索引和结束索引以及 sheet 编号 请参阅下面的示例
public void deleteRow(Integer StartIndex, Integer EndIndex) {
Spreadsheet spreadsheet = null;
try {
spreadsheet = service.spreadsheets().get(GoogleExcelFileUtil.SPREASHEET_ID).execute();
} catch (IOException e1) {
e1.printStackTrace();
}
BatchUpdateSpreadsheetRequest content = new BatchUpdateSpreadsheetRequest();
Request request = new Request();
DeleteDimensionRequest deleteDimensionRequest = new DeleteDimensionRequest();
DimensionRange dimensionRange = new DimensionRange();
dimensionRange.setDimension("ROWS");
dimensionRange.setStartIndex(StartIndex);
dimensionRange.setEndIndex(EndIndex);
dimensionRange.setSheetId(spreadsheet.getSheets().get(0).getProperties().getSheetId());
deleteDimensionRequest.setRange(dimensionRange);
request.setDeleteDimension(deleteDimensionRequest);
List<Request> requests = new ArrayList<Request>();
requests.add(request);
content.setRequests(requests);
try {
service.spreadsheets().batchUpdate(GoogleExcelFileUtil.SPREASHEET_ID, content).execute();
} catch (IOException e) {
e.printStackTrace();
} finally {
dimensionRange = null;
deleteDimensionRequest = null;
request = null;
requests = null;
content = null;
}
}