简体   繁体   English

如何动态获取谷歌电子表格的范围

[英]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);
        }
    }
}

The Sheets API does not provide such a functionality Sheets API 不提供这样的功能

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.

相关问题 如何从Google Spreadsheet获取单元格值,该值可以使用Java中的任何语言和Spreadsheet当前时间 - How to get cell value from google spread sheet which in any language and current time of spread sheet in JAVA 阅读Google电子表格 - Reading Google spread sheet 如何使用Java和Drive API在Google Drive上创建电子表格 - How to create a Spread Sheet on Google Drive Using Java and Drive API 使用google电子表格api时如何解决“java.lang.NoSuchMethodError:” - how to solve "java.lang.NoSuchMethodError:" while working with google spread sheet api Google Drive API(java):将数据表/图表添加到电子表格(SpreadsheetEntry) - Google Drive API (java): Add a datatable/chart to a spread sheet (SpreadsheetEntry) 403 - 使用 Java 将数据写入 Google 电子表格的权限不足 - 403 - Insufficient Permission to write data to Google spread sheet using Java 使用 api 读写谷歌电子表格是免费或付费的 - read write to google spread sheet using api is free or paid 按下菜单按钮时,Android,Google Spread Sheet崩溃 - Android, Google Spread Sheet crashes when on menu button is pressed 在不使用任何 Java 凭据的情况下阅读 Google 电子表格 - Reading Google spread sheet without using any credential in Java 如何在 Google 电子表格中获取单个工作表的工作表名称 - Google Sheet Api v4 - Java - How to get Sheet Name of individual Sheets in Google Spreadsheet - Google Sheet Api v4 - Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM