Ejemplo n.º 1
0
  /**
   * Gets the SpreadsheetEntry for the first spreadsheet with that name retrieved in the feed.
   *
   * @param spreadsheet the name of the spreadsheet
   * @return the first SpreadsheetEntry in the returned feed, so latest spreadsheet with the
   *     specified name
   * @throws Exception if error is encountered, such as no spreadsheets with the name
   */
  public SpreadsheetEntry getSpreadsheet(String spreadsheet) throws Exception {

    SpreadsheetQuery spreadsheetQuery = new SpreadsheetQuery(factory.getSpreadsheetsFeedUrl());
    spreadsheetQuery.setTitleQuery(spreadsheet);
    SpreadsheetFeed spreadsheetFeed = service.query(spreadsheetQuery, SpreadsheetFeed.class);
    List<SpreadsheetEntry> spreadsheets = spreadsheetFeed.getEntries();
    if (spreadsheets.isEmpty()) {
      throw new Exception("No spreadsheets with that name");
    }

    return spreadsheets.get(0);
  }
Ejemplo n.º 2
0
 public CSV(String email, String password, String spreadsheetTitle, String worksheetTitle)
     throws ServiceException, IOException {
   SpreadsheetService service = new SpreadsheetService("gsimple-gspreadsheet-1");
   service.setUserCredentials(email, password);
   URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
   SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);
   List<SpreadsheetEntry> spreadsheets = feed.getEntries();
   for (SpreadsheetEntry entry : spreadsheets) {
     if (entry.getTitle().getPlainText().equals(spreadsheetTitle)) {
       List<WorksheetEntry> worksheets = entry.getWorksheets();
       for (WorksheetEntry worksheet : worksheets) {
         if (worksheet.getTitle().getPlainText().equals(worksheetTitle)) {
           URL listFeedUrl = worksheet.getListFeedUrl();
           entries = service.getFeed(listFeedUrl, ListFeed.class).getEntries().iterator();
         }
       }
     }
   }
 }