首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用API读取google电子表格中的工作表?

如何使用API读取google电子表格中的工作表?
EN

Stack Overflow用户
提问于 2013-01-28 21:31:41
回答 1查看 15.9K关注 0票数 3

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

要做到这一点,我需要使用哪种API方法?我在google spreedsheet API页面上找不到这个。

EN

回答 1

Stack Overflow用户

发布于 2014-04-14 05:56:45

代码语言:javascript
复制
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);
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14563163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档