Exemple #1
0
  /**
   * Get the WorksheetEntry for the worksheet in the spreadsheet with the specified name.
   *
   * @param spreadsheetName the name of the spreadsheet
   * @param worksheetName the name of the worksheet in the spreadsheet
   * @return worksheet with the specified name in the spreadsheet with the specified name
   * @throws Exception if error is encountered, such as no spreadsheets with the name, or no
   *     worksheet wiht the name in the spreadsheet
   */
  public Worksheet getWorksheet(String spreadsheetName, String worksheetName) throws Exception {
    SpreadsheetEntry spreadsheetEntry = getSpreadsheet(spreadsheetName);

    WorksheetQuery worksheetQuery = new WorksheetQuery(spreadsheetEntry.getWorksheetFeedUrl());

    worksheetQuery.setTitleQuery(worksheetName);
    WorksheetFeed worksheetFeed = service.query(worksheetQuery, WorksheetFeed.class);
    List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
    if (worksheets.isEmpty()) {
      throw new Exception(
          "No worksheets with that name in spreadhsheet "
              + spreadsheetEntry.getTitle().getPlainText());
    }

    return new Worksheet(worksheets.get(0), service);
  }