3

I have a public google spreadsheet with some data in tables.

I'm developing an Android app which I want it to read these tables and then make a listview with the fields on the spreadsheet.

Which will be the best way to do that?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
hsg
  • 31
  • 1
  • 3

2 Answers2

2

You can use the code of James Moore: http://blog.restphone.com/2011/05/very-simple-google-spreadsheet-code.html.

package com.banshee;

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

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

public class SpreadsheetSucker {
  public static void main(String[] args) {
    SpreadsheetService service = new SpreadsheetService("com.banshee");
    try {
      // Notice that the url ends
      // with default/public/values.
      // That wasn't obvious (at least to me)
      // from the documentation.
      String urlString = "https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";

      // turn the string into a URL
      URL url = new URL(urlString);

      // You could substitute a cell feed here in place of
      // the list feed
      ListFeed feed = service.getFeed(url, ListFeed.class);

      for (ListEntry entry : feed.getEntries()) {
        CustomElementCollection elements = entry.getCustomElements();
        String name = elements.getValue("name");
        System.out.println(name);
        String number = elements.getValue("Number");
        System.out.println(number);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ServiceException e) {
      e.printStackTrace();
    }

  }
}
Pablo Pantaleon
  • 1,506
  • 1
  • 19
  • 38
  • I used this method and read data form google sheets. but suddenly its not working , can't access sheet using that link. this error coming "Sorry, unable to open the file at this time." – Shameera Anuranga Aug 20 '21 at 16:18
1

I have developed a client Lib for SpreadSheet which works on Android. Please try- http://code.google.com/p/google-spreadsheet-lib-android/

hope it helps.

Cheers, Prasanta

user542954
  • 512
  • 4
  • 2