【发布时间】:2020-02-03 11:33:28
【问题描述】:
我有一个谷歌电子表格,我必须打印每个单元格的所有数据。 我编写了一个获取数据的代码,但为此,我必须定义 "range" 的值。我希望范围是动态的,即无论谷歌电子表格的范围是什么。
public static void readSampleSpreadsheet() throws IOException {
// Build a new authorized API client service.
Sheets service = getSheetsService();
String spreadsheetId = "1gfLQTGWejFeZmp_HpTVP84ykKkKZbAE";
String range = "A1:AZ70";
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List<List<Object>> values = response.getValues();
System.out.println("this is the values " + values);
if (values == null || values.size() == 0) {
System.out.println("No data found.");
} else {
System.out.println("Name, Major");
for (List row : values) {
// Print columns A and E, which correspond to indices 0 and 4.
System.out.println(row);
}
}
}
【问题讨论】: