3

我有一个 google 电子表格,其中包含 2-3 个单独的工作表。我正在寻找一种方法来查看工作表#2 中包含的行,然后遍历之前找到的每一行的列。

我会寻找哪种 API 方法来执行此操作?我无法从谷歌电子表格 API 页面找到这个。

4

1 回答 1

1
package com.Sensor.Data;

import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.data.spreadsheet.ListFeed;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
import com.google.gdata.util.ServiceException;

import java.io.IOException;
import java.net.URL;


public class readData {

    public static final String GOOGLE_ACCOUNT_USERNAME = "piprojectutd@gmail.com"; 
    public static final String GOOGLE_ACCOUNT_PASSWORD = "password"; 

    public static final String SPREADSHEET_URL = <insert your spreadsheet url here until key onlye i.e"https://spreadsheets.google.com/feeds/spreadsheets/0AjyNkJ5x_vajdDRZQ1RBSEw5aHFLRU1yOHFYeFFoekE";>



    public String getData(){
        String status="";

    try{
    /** Our view of Google Spreadsheets as an authenticated Google user. */
        SpreadsheetService service = new SpreadsheetService("Print Google Spreadsheet Demo");

        // Login and prompt the user to pick a sheet to use.
        service.setUserCredentials(GOOGLE_ACCOUNT_USERNAME,
                GOOGLE_ACCOUNT_PASSWORD);

        // Load sheet
        URL metafeedUrl = new URL(SPREADSHEET_URL);
        SpreadsheetEntry spreadsheet = service.getEntry(metafeedUrl,SpreadsheetEntry.class);
        URL listFeedUrl = spreadsheet.getWorksheets().get(0).getListFeedUrl();

        // Print entries
        ListFeed feed = service.getFeed(listFeedUrl, ListFeed.class);

        for (ListEntry entry : feed.getEntries()) {
            System.out.println("new row");
            for (String tag : entry.getCustomElements().getTags())) {
                System.out.println("     " + tag + ": "
                        + entry.getCustomElements().getValue(tag));
                status=entry.getCustomElements().getValue(tag);

            }
        }

    }catch(Exception e){
        System.out.println(e);
    }
    System.out.println(status);
    return(status);
    }
}
于 2014-04-13T21:56:45.090 回答