Exemplo n.º 1
0
  @Override
  protected void createInSpreadsheet() throws RuntimeException {
    try {
      // Create the worksheet
      URL worksheetFeedUrl = ((GSModel) this.model).spreadsheetEntry.getWorksheetFeedUrl();
      this.worksheetEntry =
          ((GSModel) this.model).spreadsheetService.insert(worksheetFeedUrl, this.worksheetEntry);

      this.existsInSpreadsheet = true;

      if (this.headerEmpty) {
        // Worksheet is completely empty - insert a value in the header row, otherwise list feed
        // uses the header row
        CellFeed cf = this.fetchCellFeed(1, true);
        CellEntry cellEntry = new CellEntry(1, 1, "TEMP");
        cf.insert(cellEntry);
      } else {
        // Write any known column names
        CellFeed cf = this.fetchCellFeed(1, true);
        for (SpreadsheetColumn c : this.getHeader()) {
          if (c.getName() != null && !c.getName().isEmpty()) {
            CellEntry cellEntry = new CellEntry(1, c.getIndex(), c.getName());
            cf.insert(cellEntry);
          }
        }
      }

      // Update the worksheet entry to reflect the new state
      this.worksheetEntry = this.worksheetEntry.getSelf();

      // Set up the worksheet
      this.initialiseListFeed();
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage());
    }
  }
  public URL createWorksheet(
      URL url, String worksheetTitle, int rows, int columns, List<String> columnNames)
      throws IOException, ServiceException {
    WorksheetEntry worksheet = new WorksheetEntry();
    worksheet.setTitle(new PlainTextConstruct(worksheetTitle));

    worksheet.setRowCount(rows);
    worksheet.setColCount(columns);

    WorksheetEntry createdWorksheet = spreadsheetService.insert(url, worksheet);

    // create header
    CellFeed cellFeed =
        spreadsheetService.getFeed(createdWorksheet.getCellFeedUrl(), CellFeed.class);
    int i = 1;

    for (String columnName : columnNames) {
      CellEntry cellEntry = new CellEntry(1, i, columnName);
      cellFeed.insert(cellEntry);
      i++;
    }
    return createdWorksheet.getListFeedUrl();
  }