Exemplo n.º 1
0
  /**
   * Constructor
   *
   * @param f the excel file
   * @param sst the shared string table
   * @param fr formatting records
   * @param sb the bof record which indicates the start of the sheet
   * @param wb the bof record which indicates the start of the sheet
   * @param nf the 1904 flag
   * @param wp the workbook which this sheet belongs to
   * @throws BiffException
   */
  DefaultSheet(
      File f,
      SSTRecord sst,
      FormattingRecords fr,
      BOFRecord sb,
      BOFRecord wb,
      boolean nf,
      WorkbookParser wp)
      throws BiffException {
    excelFile = f;
    sharedStrings = sst;
    formattingRecords = fr;
    sheetBof = sb;
    workbookBof = wb;
    columnInfosArray = new ArrayList();
    sharedFormulas = new ArrayList();
    hyperlinks = new ArrayList();
    rowProperties = new ArrayList(10);
    columnInfosInitialized = false;
    rowRecordsInitialized = false;
    nineteenFour = nf;
    workbook = wp;
    workbookSettings = workbook.getSettings();

    // Mark the position in the stream, and then skip on until the end
    startPosition = f.getPos();

    if (sheetBof.isChart()) {
      // Set the start pos to include the bof so the sheet reader can handle it
      startPosition -= (sheetBof.getLength() + 4);
    }

    Record r = null;
    int bofs = 1;

    while (bofs >= 1) {
      r = f.next();

      // use this form for quick performance
      if (r.getCode() == Type.EOF.value) {
        bofs--;
      }

      if (r.getCode() == Type.BOF.value) {
        bofs++;
      }
    }
  }
Exemplo n.º 2
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());
            }
          }
        }
      }
    }
  }