/** * Constructs a new entry with the given row count and column count * @param rowCount the number of rows in the worksheet * @param colCount the number of columns in a worksheet */ public WorksheetEntry(int rowCount, int colCount) { getCategories().add(CATEGORY); addExtension(new RowCount(rowCount)); addExtension(new ColCount(colCount)); }
private CellFeed getHeaderCellFeed() throws Exception { final StringBuilder uri = new StringBuilder(this.worksheetEntry.getCellFeedUrl().toString()); uri.append("?min-row=" + Integer.toString(GSConstants.HEADER_ROW_INDEX)); uri.append("&max-row=" + Integer.toString(GSConstants.HEADER_ROW_INDEX)); uri.append("&return-empty=true"); final URL cellFeedUrl = new URI(uri.toString()).toURL(); return this.model.getWorksheetCellFeed(cellFeedUrl); }
/** * Gets the URL for this worksheet's cells feed. * * <p>With this feed, you can query for arbitrary ranges of cells. * * @return a URL to the cells feed */ public URL getCellFeedUrl() { try { return new URL(getFeedUrlString(Namespaces.CELLS_LINK_REL)); } catch (MalformedURLException e) { throw new RuntimeException("Error in GData server", e); } }
/** * Returns the List Feed URL for working with this worksheet. * * @return URL * @throws ServiceException * @throws IOException */ public URL getListFeedURL() throws IOException, ServiceException { this.worksheetEntry = this.worksheetEntry.getSelf(); return this.worksheetEntry.getListFeedUrl(); }
private String getFeedUrlString(String linkRelKind) { Version spreadsheetVersion = state.service.getProtocolVersion(); if (spreadsheetVersion.isCompatible(SpreadsheetService.Versions.V1)) { Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM); return feedLink.getHref(); } else { // must be SpreadsheetService.Versions.V2; only 2 versions for now // List or Cells feed Url? if (linkRelKind.equals(Namespaces.LIST_LINK_REL)) { // the list feed is stored as a <content> tag return ((OutOfLineContent)(this.getContent())).getUri(); } else { // it must be Namespaces.CELLS_LINK_REL // the cells feed is stored in the <link> tag Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM); return feedLink.getHref(); } } }
private void initialiseListFeed() throws Exception { final URL listFeedUrl = new URL(this.worksheetEntry.getListFeedUrl().toString());// + "?return-empty=true"); this.listFeed = this.model.getWorksheetListFeed(listFeedUrl); }
/** * Constructs a new entry by doing a shallow copy from another BaseEntry * instance. */ public WorksheetEntry(BaseEntry sourceEntry) { super(sourceEntry); getCategories().add(CATEGORY); }
/** * Sets the total number of rows. * * If the new number of rows is greater than the old, (new-old) * blank rows will be appended to the end. If the new number of * rows is less than the old, then (old-new) rows will be removed * from the end which will DELETE ALL DATE IN DELETED ROWS. * * @param count the new row count. */ public void setRowCount(int count) { setExtension(new RowCount(count)); }
/** * Gets the total number of columns. * * This refers to the hard bound on columns. It is possible that your * spreadsheet has many empty columns, all of which are counted in * this count. * * Column positions 1 to getColCount() are valid. */ public int getColCount() { ColCount count = getExtension(ColCount.class); if (count != null) { return count.getCount(); } else { return 0; } }
@Override protected void createInSpreadsheet() { try { if (!super.existsInSpreadsheet) { LOGGER.debug("Creating worksheet '" + this.worksheetEntry.getTitle().getPlainText() + "'"); this.worksheetEntry = this.model.insertWorksheet(this.worksheetEntry); super.existsInSpreadsheet = true; this.writeHeader(); this.worksheetEntry = this.worksheetEntry.getSelf(); this.initialiseListFeed(); this.getGoogleColumnIds(); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } }
private WorksheetEntry getWorkSheet(String sheetName) throws IOException, ServiceException { for (WorksheetEntry workSheet : spreadSheet.getWorksheets()) { if (workSheet.getTitle().getPlainText().equalsIgnoreCase(sheetName)) { return workSheet; } } return null; }
private String getFeedUrlString(String linkRelKind) { Version spreadsheetVersion = state.service.getProtocolVersion(); if (spreadsheetVersion.isCompatible(SpreadsheetService.Versions.V1)) { Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM); return feedLink.getHref(); } else { // must be SpreadsheetService.Versions.V2; only 2 versions for now // List or Cells feed Url? if (linkRelKind.equals(Namespaces.LIST_LINK_REL)) { // the list feed is stored as a <content> tag return ((OutOfLineContent)(this.getContent())).getUri(); } else { // it must be Namespaces.CELLS_LINK_REL // the cells feed is stored in the <link> tag Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM); return feedLink.getHref(); } } }
public ListEntry insertRow(final WorksheetEntry worksheetEntry, final ListEntry row) throws IOException, ServiceException { URL url = worksheetEntry.getListFeedUrl(); ListEntry le = this.spreadsheetService.insert(url, row); return le; }
/** * Constructs a new entry by doing a shallow copy from another BaseEntry * instance. */ public WorksheetEntry(BaseEntry sourceEntry) { super(sourceEntry); getCategories().add(CATEGORY); }
/** * Sets the total number of rows. * * If the new number of rows is greater than the old, (new-old) * blank rows will be appended to the end. If the new number of * rows is less than the old, then (old-new) rows will be removed * from the end which will DELETE ALL DATE IN DELETED ROWS. * * @param count the new row count. */ public void setRowCount(int count) { setExtension(new RowCount(count)); }
/** * Gets the total number of rows. * * This refers to the hard bound on rows. It is possible that your * spreadsheet has many, many empty rows, all of which are counted in * this count. * * Column positions 1 to getRowCount() are valid. */ public int getRowCount() { RowCount count = getExtension(RowCount.class); if (count != null) { return count.getCount(); } else { return 0; } }
public GSWorksheet(final GSModel model, final WorksheetEntry worksheetEntry, final boolean existsInSpreadsheet) throws Exception { super(model, worksheetEntry.getTitle().getPlainText(), existsInSpreadsheet); this.model = model; this.worksheetEntry = worksheetEntry; this.headerInWorksheetIsEmpty = true; this.hasGoogleIdsSet = false; this.rows = null; this.initialise(); }
/** * Constructs a new entry with the given row count and column count * @param rowCount the number of rows in the worksheet * @param colCount the number of columns in a worksheet */ public WorksheetEntry(int rowCount, int colCount) { getCategories().add(CATEGORY); addExtension(new RowCount(rowCount)); addExtension(new ColCount(colCount)); }
private GSRow loadGoogleColumnIds(final int rowIndex, final int lastColumnIndex) throws Exception { final StringBuilder uri = new StringBuilder(this.worksheetEntry.getListFeedUrl().toString()); uri.append("?start-index=" + Integer.toString(rowIndex - GSConstants.HEADER_ROW_INDEX)); uri.append("&max-results=1"); final URL listFeedUrl = new URL(uri.toString()); final ListFeed listFeed = this.model.getWorksheetListFeed(listFeedUrl); final List<ListEntry> listEntries = listFeed.getEntries(); if (listEntries.size() == 1) { final ListEntry temporaryRow = listEntries.get(0); this.extractGoogleIdsFromRow(temporaryRow, lastColumnIndex); return new GSRow(this, temporaryRow); } else { throw new IllegalStateException("Failed to retrieve temporary row"); } }
/** * Constructs a new uninitialized entry to be populated by the * GData parsers. */ public WorksheetEntry() { getCategories().add(CATEGORY); }