Android:在Google Spread Sheet中添加行

时间:2013-07-24 10:18:17

标签: android google-sheets

我使用以下代码添加列表行,它成功了。但它看起来很复杂。

SpreadsheetService service =
    new SpreadsheetService("MySpreadsheetIntegration-v1");

// Define the URL to request.  This should never change.
URL SPREADSHEET_FEED_URL = new URL(
    "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

// TODO Make a request to the API and get all spreadsheets.

/*
In Here, Instead of request all spread sheets,
I want to request only my spread sheet which I have stored on Google Drive.
*/

SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
    SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();

if (spreadsheets.size() == 0) {
  // TODO: There were no spreadsheets, act accordingly.
}

SpreadsheetEntry spreadsheet = spreadsheets.get(0);
System.out.println(spreadsheet.getTitle().getPlainText());

// Get the first worksheet of the first spreadsheet.
// TODO: Choose a worksheet more intelligently based on your
// app's needs.
WorksheetFeed worksheetFeed = service.getFeed(
    spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);

// Fetch the list feed of the worksheet.
URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);

// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.getCustomElements().setValueLocal("firstname", "Joe");
row.getCustomElements().setValueLocal("lastname", "Smith");

// Send the new row to the API for insertion.
row = service.insert(listFeedUrl, row);

现在,我希望变得简单。

而不是请求所有电子表格, 我只想要求我存储在Google云端硬盘上的电子表格。

我有文件电子表格的链接,docs.google.com/spreadsheet/ccc?key = KEYOFFILE#gid=0。

请告诉我怎么样, 谢谢,

1 个答案:

答案 0 :(得分:1)

好, 我自己解决了。

改为使用

URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");

我们使用:

URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/worksheets/KEYOFTHEFILE/private/full")

谢谢,