[英]How to get range of google spread sheet dynamically
I have a google spreadsheet and I have to print all the data of each cell.我有一个谷歌电子表格,我必须打印每个单元格的所有数据。 I have written a code that is getting the data but for that, I have to define the value of "range" .
我已经编写了一个获取数据的代码,但为此,我必须定义"range"的值。 I want the range to be dynamical ie whatever the range of the google spreadsheet.
我希望范围是动态的,即无论谷歌电子表格的范围如何。
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);
}
}
}
Instead, you can use Apps Script which features the method sheet.getDataRange() .相反,您可以使用具有方法sheet.getDataRange() 的Apps 脚本。
You can embed the Apps Script code into you java code with the Apps Script API which allows you to execute Apps Script functions remotely .您可以使用Apps Script API将 Apps 脚本代码嵌入到您的 java 代码中,该API允许您 远程执行 Apps 脚本功能。
Alternatively, you can deploy the Apps Script code as a WebApp and incorporate its return values into your code with the deployment URL, see here for a sample.或者,您可以将 Apps 脚本代码部署为WebApp ,并将其返回值与部署 URL 合并到您的代码中,请参阅此处的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.