Example #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);
  }