Esempio n. 1
0
  /**
   * Gets the named range from this workbook. The Range object returns contains all the cells from
   * the top left to the bottom right of the range. If the named range comprises an adjacent range,
   * the Range[] will contain one object; for non-adjacent ranges, it is necessary to return an
   * array of length greater than one. If the named range contains a single cell, the top left and
   * bottom right cell will be the same cell
   *
   * @param name the name to find
   * @return the range of cells
   */
  public Range[] findByName(String name) {
    NameRecord nr = (NameRecord) namedRecords.get(name);

    if (nr == null) {
      return null;
    }

    NameRecord.NameRange[] ranges = nr.getRanges();

    Range[] cellRanges = new Range[ranges.length];

    for (int i = 0; i < ranges.length; i++) {
      cellRanges[i] =
          new RangeImpl(
              this,
              getExternalSheetIndex(ranges[i].getExternalSheet()),
              ranges[i].getFirstColumn(),
              ranges[i].getFirstRow(),
              getLastExternalSheetIndex(ranges[i].getExternalSheet()),
              ranges[i].getLastColumn(),
              ranges[i].getLastRow());
    }

    return cellRanges;
  }
Esempio n. 2
0
  /**
   * Gets the named cell from this workbook. If the name refers to a range of cells, then the cell
   * on the top left is returned. If the name cannot be found, null is returned
   *
   * @param name the name of the cell/range to search for
   * @return the cell in the top left of the range if found, NULL otherwise
   */
  public Cell findCellByName(String name) {
    NameRecord nr = (NameRecord) namedRecords.get(name);

    if (nr == null) {
      return null;
    }

    NameRecord.NameRange[] ranges = nr.getRanges();

    // Go and retrieve the first cell in the first range
    Sheet s = getSheet(ranges[0].getExternalSheet());
    Cell cell = s.getCell(ranges[0].getFirstColumn(), ranges[0].getFirstRow());

    return cell;
  }
  /**
   * Gets the named cell from this workbook. If the name refers to a range of cells, then the cell
   * on the top left is returned. If the name cannot be found, null is returned
   *
   * @param name the name of the cell/range to search for
   * @return the cell in the top left of the range if found, NULL otherwise
   */
  public Cell findCellByName(String name) {
    NameRecord nr = (NameRecord) namedRecords.get(name);

    if (nr == null) {
      return null;
    }

    NameRecord.NameRange[] ranges = nr.getRanges();

    // Go and retrieve the first cell in the first range
    Sheet s = getSheet(getExternalSheetIndex(ranges[0].getExternalSheet()));
    int col = ranges[0].getFirstColumn();
    int row = ranges[0].getFirstRow();

    // If the sheet boundaries fall short of the named cell, then return
    // an empty cell to stop an exception being thrown
    if (col > s.getColumns() || row > s.getRows()) {
      return new EmptyCell(col, row);
    }

    Cell cell = s.getCell(col, row);

    return cell;
  }
Esempio n. 4
0
  /** Reads in the contents of this sheet */
  final void readSheet() {
    // If this sheet contains only a chart, then set everything to
    // empty and do not bother parsing the sheet
    // Thanks to steve.brophy for spotting this
    if (!sheetBof.isWorksheet()) {
      numRows = 0;
      numCols = 0;
      cells = new Cell[0][0];
      //      return;
    }

    SheetReader reader =
        new SheetReader(
            excelFile,
            sharedStrings,
            formattingRecords,
            sheetBof,
            workbookBof,
            nineteenFour,
            workbook,
            startPosition,
            this);
    reader.read();

    // Take stuff that was read in
    numRows = reader.getNumRows();
    numCols = reader.getNumCols();
    cells = reader.getCells();
    rowProperties = reader.getRowProperties();
    columnInfosArray = reader.getColumnInfosArray();
    hyperlinks = reader.getHyperlinks();
    conditionalFormats = reader.getConditionalFormats();
    autoFilter = reader.getAutoFilter();
    charts = reader.getCharts();
    drawings = reader.getDrawings();
    dataValidation = reader.getDataValidation();
    mergedCells = reader.getMergedCells();
    settings = reader.getSettings();
    settings.setHidden(hidden);
    rowBreaks = reader.getRowBreaks();
    columnBreaks = reader.getColumnBreaks();
    workspaceOptions = reader.getWorkspaceOptions();
    plsRecord = reader.getPLS();
    buttonPropertySet = reader.getButtonPropertySet();
    maxRowOutlineLevel = reader.getMaxRowOutlineLevel();
    maxColumnOutlineLevel = reader.getMaxColumnOutlineLevel();

    reader = null;

    if (!workbookSettings.getGCDisabled()) {
      System.gc();
    }

    if (columnInfosArray.size() > 0) {
      ColumnInfoRecord cir = (ColumnInfoRecord) columnInfosArray.get(columnInfosArray.size() - 1);
      columnInfos = new ColumnInfoRecord[cir.getEndColumn() + 1];
    } else {
      columnInfos = new ColumnInfoRecord[0];
    }

    // Add any local names
    if (localNames != null) {
      for (Iterator it = localNames.iterator(); it.hasNext(); ) {
        NameRecord nr = (NameRecord) it.next();
        if (nr.getBuiltInName() == BuiltInName.PRINT_AREA) {
          if (nr.getRanges().length > 0) {
            NameRecord.NameRange rng = nr.getRanges()[0];
            settings.setPrintArea(
                rng.getFirstColumn(), rng.getFirstRow(), rng.getLastColumn(), rng.getLastRow());
          }
        } else if (nr.getBuiltInName() == BuiltInName.PRINT_TITLES) {
          // There can be 1 or 2 entries.
          // Row entries have hardwired column entries (first and last
          //  possible column)
          // Column entries have hardwired row entries (first and last
          // possible row)
          for (int i = 0; i < nr.getRanges().length; i++) {
            NameRecord.NameRange rng = nr.getRanges()[i];
            if (rng.getFirstColumn() == 0 && rng.getLastColumn() == 255) {
              settings.setPrintTitlesRow(rng.getFirstRow(), rng.getLastRow());
            } else {
              settings.setPrintTitlesCol(rng.getFirstColumn(), rng.getLastColumn());
            }
          }
        }
      }
    }
  }