示例#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);
  }
示例#2
0
  public ImportClient(String username, String password, int itemsPerBatch, String spreadsheetName)
      throws Exception {
    ITEMS_PER_BATCH = itemsPerBatch;

    factory = FeedURLFactory.getDefault();
    service = new SpreadsheetService("Props-2-Xls");
    service.setUserCredentials(username, password);
    service.setProtocolVersion(
        SpreadsheetService.Versions
            .V1); // bug workaround! http://code.google.com/p/gdata-java-client/issues/detail?id=103

    spreadsheet = getSpreadsheet(spreadsheetName);
    backingEntry = spreadsheet.getDefaultWorksheet();

    CellQuery cellQuery = new CellQuery(backingEntry.getCellFeedUrl());
    cellQuery.setReturnEmpty(true);
    CellFeed cellFeed = service.getFeed(cellQuery, CellFeed.class);
  }