Esempio n. 1
0
    Worksheet(WorksheetEntry backingEntry, SpreadsheetService spreadsheetService)
        throws IOException, ServiceException {

      this.backingEntry = backingEntry;
      this.spreadsheetService = spreadsheetService;
      this.rows = backingEntry.getRowCount();
      this.columns = backingEntry.getColCount();
      refreshCachedData();
    }
Esempio 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();
         }
       }
     }
   }
 }
Esempio n. 3
0
    /** Presents the given cell feed as a map from row, column pair to CellEntry. */
    private void refreshCachedData() throws IOException, ServiceException {

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

      //            A subtlety: Spreadsheets row,col numbers are 1-based whereas the
      //            cellEntries array is 0-based. Rather than wasting an extra row and
      //            column worth of cells in memory, we adjust accesses by subtracting
      //            1 from each row or column number.
      cellEntries = new CellEntry[rows][columns];
      for (CellEntry cellEntry : cellFeed.getEntries()) {
        Cell cell = cellEntry.getCell();
        cellEntries[cell.getRow() - 1][cell.getCol() - 1] = cellEntry;
      }
    }
Esempio n. 4
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);
  }
Esempio n. 5
0
 /**
  * Sets this worksheets's row count.
  *
  * @param newRowCount
  * @throws com.google.gdata.util.ServiceException
  */
 void setRowCount(int newRowCount) throws IOException, ServiceException {
   rows = newRowCount;
   backingEntry.setRowCount(newRowCount);
   backingEntry = backingEntry.update();
   refreshCachedData();
 }