⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sheetimpl.javasafe

📁 jxtl API Java中Excel的生成与导入解析参考文档
💻 JAVASAFE
📖 第 1 页 / 共 2 页
字号:
      
      if (r.getType() == Type.DIMENSION)
      {
        DimensionRecord dr = null;

        if (workbookBof.isBiff8())
        {
          dr = new DimensionRecord(r);
        }
        else
        {
          dr = new DimensionRecord(r, DimensionRecord.biff7);
        }
        numRows = dr.getNumberOfRows();
        numCols = dr.getNumberOfColumns();
        cells = new Cell[numRows][numCols];
        columnInfos = new ColumnInfoRecord[numCols];
      }

      if (r.getType() == Type.LABELSST) 
      {
        LabelSSTRecord label = new LabelSSTRecord(r, 
                                                  sharedStrings, 
                                                  formattingRecords,
                                                  this);
        addCell(label);
      }

      if (r.getType() == Type.RK || r.getType() == Type.RK2) 
      {
        RKRecord rkr = new RKRecord(r, formattingRecords, this);

        if (formattingRecords.isDate(rkr.getXFIndex()))
        {
          DateCell dc = new DateRecord
            (rkr, rkr.getXFIndex(), formattingRecords, nineteenFour, this);
          addCell(dc);
        }
        else
        {
          addCell(rkr);
        }
      }

      if (r.getType() == Type.HLINK)
      {
        HyperlinkRecord hr = new HyperlinkRecord(r,this);
        hyperlinks.add(hr);
      }

      if (r.getType() == Type.MERGEDCELLS)
      {
        Assert.verify(mergedCells == null);
        mergedCells = new MergedCellsRecord(r, this);
      }

      if (r.getType() == Type.MULRK)
      {
        MulRKRecord mulrk = new MulRKRecord(r);

        // Get the individual cell records from the multiple record
        int num = mulrk.getNumberOfColumns();
        int ixf = 0;
        for (int i = 0 ; i < num; i++)
        {
          ixf = mulrk.getXFIndex(i);

          NumberValue nv = new NumberValue
            (mulrk.getRow(), 
             mulrk.getFirstColumn() + i,
             RKHelper.getDouble(mulrk.getRKNumber(i)),
             ixf,
             formattingRecords,
             this);

          
          if (formattingRecords.isDate(ixf))
          {
            DateCell dc = new DateRecord(nv, ixf, formattingRecords, 
                                         nineteenFour, this);
            addCell(dc);
          }
          else
          {
            nv.setNumberFormat(formattingRecords.getNumberFormat(ixf));
            addCell(nv);
          }
        }
      }

      if (r.getType() == Type.NUMBER) 
      {
        NumberRecord nr = new NumberRecord(r, formattingRecords, this);

        if (formattingRecords.isDate(nr.getXFIndex()))
        {
          DateCell dc = new DateRecord
            (nr, nr.getXFIndex(),formattingRecords,
             nineteenFour, this);
          addCell(dc);
        }
        else
        {
          addCell(nr);
        }
      }

      if (r.getType() == Type.BOOLERR)
      {
        BooleanRecord br = new BooleanRecord(r, formattingRecords, this);

        if (br.isError())
        {
          ErrorRecord er = new ErrorRecord(br.getRecord(), formattingRecords, 
                                           this);
          addCell(er);
        }
        else
        {
          addCell(br);
        }
      }

      if (r.getType() == Type.CONTINUE)
      {
        ;//System.out.println("continue");
      }

      if (r.getType() == Type.NOTE)
      {
        ;//System.out.println("note");
      }

      if (r.getType() == Type.ARRAY)
      {
        //System.out.println("array");
      }
      
      if (r.getType() == Type.SHAREDFORMULA)
      {
        SharedFormulaRecord sfr = new SharedFormulaRecord
                                    (r, sharedFormula, workbook, this);
        sharedFormulas.add(sfr);
        sharedFormula = null;
      }

      if (r.getType() == Type.FORMULA || r.getType() == Type.FORMULA2)
      {
        FormulaRecord fr = new FormulaRecord(r, excelFile, 
                                             formattingRecords, workbook, 
                                             this);

        if (fr.isShared())
        {
          BaseSharedFormulaRecord prevSharedFormula = sharedFormula;
          sharedFormula = (BaseSharedFormulaRecord) fr.getFormula();
          
          // See if it fits in any of the shared formulas
          sharedFormulaAdded = addToSharedFormulas(sharedFormula);

          if (sharedFormulaAdded)
          {
            sharedFormula = null;
          }

          // If we still haven't added the previous base shared formula,
          // revert it to an ordinary formula and add it to the cell
          if (!sharedFormulaAdded && prevSharedFormula != null)
          {
            // Do nothing.  It's possible for the biff file to contain the
            // record sequence
            // FORMULA-SHRFMLA-FORMULA-SHRFMLA-FORMULA-FORMULA-FORMULA
            // ie. it first lists all the formula templates, then it
            // lists all the individual formulas

            //  addCell(revertSharedFormula(prevSharedFormula));
          }
        }
        else
        {
          Cell cell = fr.getFormula();

          // See if the formula evaluates to date
          if (fr.getFormula().getType() == CellType.NUMBER_FORMULA)
          {
            NumberFormulaRecord nfr = (NumberFormulaRecord) fr.getFormula();
            if (formattingRecords.isDate(nfr.getXFIndex()))
            {
              cell = new DateFormulaRecord(nfr,
                                           formattingRecords, 
                                           workbook,
                                           nineteenFour, 
                                           this);
            }
          }
          
          addCell(cell);
        }
      }

      if (r.getType() == Type.LABEL)
      {
        LabelRecord lr = null;

        if (workbookBof.isBiff8())
        { 
          lr = new LabelRecord(r, formattingRecords, this);
        }
        else
        {
          lr = new LabelRecord(r, formattingRecords, this, LabelRecord.biff7);
        }
        addCell(lr);
      }

      if (r.getType() == Type.RSTRING)
      {
        RStringRecord lr = null;

        // RString records are obsolete in biff 8
        Assert.verify(!workbookBof.isBiff8());
        {
          lr = new RStringRecord(r, formattingRecords, 
                                 this, RStringRecord.biff7);
        }
        addCell(lr);
      }

      if (r.getType() == Type.NAME)
      {
        ;//System.out.println("name");
      }

      if (r.getType() == Type.ROW)
      {
        RowRecord rr = new RowRecord(r);

        // See if the row has anything funny about it
        if (!rr.isDefaultHeight() || rr.isCollapsed() || rr.isZeroHeight())
        {
          rowProperties.add(rr);
        }
      }

      if (r.getType() == Type.BLANK)
      {
        BlankCell bc = new BlankCell(r, formattingRecords, this);
        addCell(bc);
      }

      if (r.getType() == Type.MULBLANK)
      {
        MulBlankRecord mulblank = new MulBlankRecord(r);

        // Get the individual cell records from the multiple record
        int num = mulblank.getNumberOfColumns();
        int ixf = 0;
        for (int i = 0 ; i < num; i++)
        {
          ixf = mulblank.getXFIndex(i);

          MulBlankCell mbc = new MulBlankCell
            (mulblank.getRow(), 
             mulblank.getFirstColumn() + i,
             ixf,
             formattingRecords,
             this);
          
          addCell(mbc);
        }
      }

      if (r.getType() == Type.COLINFO)
      {
        ColumnInfoRecord cir = new ColumnInfoRecord(r);
        columnInfosArray.add(cir);
      }

      if (r.getType() == Type.HEADER)
      {
        if (workbookBof.isBiff8())
        {
          header = new HeaderRecord(r);
        }
        else
        {
          header = new HeaderRecord(r, HeaderRecord.biff7);
        }
      }

      if (r.getType() == Type.FOOTER)
      {
        
        if (workbookBof.isBiff8())
        {
          footer = new FooterRecord(r);
        }
        else
        {
          footer = new FooterRecord(r, FooterRecord.biff7);
        }
      }

      if (r.getType() == Type.SETUP)
      {
        setup = new SetupRecord(r);
      }

      if (r.getType() == Type.HORIZONTALPAGEBREAKS)
      {
        HorizontalPageBreaksRecord dr = null;

        if (workbookBof.isBiff8())
        {
          dr = new HorizontalPageBreaksRecord(r);
        }
        else
        {
          dr = new HorizontalPageBreaksRecord
            (r, HorizontalPageBreaksRecord.biff7);
        }

        rowBreaks = dr.getRowBreaks();
      }

      if (r.getType() == Type.OBJ)
      {
      }

      if (r.getType() == Type.MSODRAWING)
      {
      }

      if (r.getType() == Type.BOF)
      {
        BOFRecord br = new BOFRecord(r);
        Assert.verify(!br.isWorksheet());
        
        int startpos = excelFile.getPos() - r.getLength() - 4;

        // Skip to the end of the nested bof.  Thanks to Rohit for
        // spotting this
        Record r2 = excelFile.next();
        while (r2.getCode() != Type.EOF.value)
        {
          r2 = excelFile.next();
        }
      }

      if (r.getType() == Type.EOF)
      {
        cont = false;
      }
    }

    // Restore the file to its accurate position
    excelFile.restorePos();

    // Add all the shared formulas to the sheet as individual formulas
    Iterator i = sharedFormulas.iterator();

    while (i.hasNext())
    {
      SharedFormulaRecord sfr = (SharedFormulaRecord) i.next();

      Cell[] sfnr = sfr.getFormulas(formattingRecords, nineteenFour); 
      
      for (int sf = 0; sf < sfnr.length ; sf++)
      {
        addCell(sfnr[sf]);
      }
    }

    // If the last base shared formula wasn't added to the sheet, then
    // revert it to an ordinary formula and add it
    if (!sharedFormulaAdded && sharedFormula != null)
    {
      addCell(revertSharedFormula(sharedFormula));
    }
  }

  /**
   * Gets the hyperlinks on this sheet
   *
   * @return an array of hyperlinks
   */
  public Hyperlink[] getHyperlinks()
  {
    Hyperlink[] hl = new Hyperlink[hyperlinks.size()];

    for (int i = 0; i < hyperlinks.size(); i++)
    {
      hl[i] = (Hyperlink) hyperlinks.get(i);
    }

    return hl;
  }

  /**
   * Gets the cells which have been merged on this sheet
   *
   * @return an array of range objects
   */
  public Range[] getMergedCells()
  {
    if (mergedCells == null)
    {
      return new Range[0];
    }

    return mergedCells.getRanges();
  }

  /**
   * Gets the non-default rows.  Used when copying spreadsheets
   *
   * @return an array of row properties
   */
  public RowRecord[] getRowProperties()
  {
    RowRecord[] rp = new RowRecord[rowProperties.size()];
    for (int i = 0; i < rp.length ; i++)
    {
      rp[i] = (RowRecord) rowProperties.get(i);
    }

    return rp;
  }

  /**
   * Gets the row record.  Usually called by the cell in the specified
   * row in order to determine its size
   *
   * @param r the row
   * @return the RowRecord for the specified row
   */
  RowRecord getRowInfo(int r)
  {
    if (!rowRecordsInitialized)
    {
      rowRecords = new RowRecord[getRows()];
      Iterator i = rowProperties.iterator();

      RowRecord rr = null;
      while (i.hasNext())
      {
        rr = (RowRecord) i.next();
        rowRecords[rr.getRowNumber()] = rr;
      }
    }

    return rowRecords[r];
  }

  /**
   * Gets the header.  Called when copying sheets
   *
   * @return the page header
   */
  public final HeaderRecord getHeader()
  {
    return header;
  }

  /**
   * Gets the footer.  Called when copying sheets
   *
   * @return the page footer
   */
  public final FooterRecord getFooter()
  {
    return footer;
  }

  /**
   * Gets the setup record.  Called when copying sheets
   *
   * @return the page setup
   */
  public final SetupRecord getSetup()
  {
    return setup;
  }


  /**
   * Gets the row breaks.  Called when copying sheets
   *
   * @return the explicit row breaks
   */
  public final int[] getRowPageBreaks()
  {
    return rowBreaks;
  }

  /**
   * Sees if the shared formula belongs to any of the shared formula
   * groups
   * 
   * @param fr the candidate shared formula
   */
  private boolean addToSharedFormulas(BaseSharedFormulaRecord fr)
  {
    Iterator i = sharedFormulas.iterator();
    boolean added = false;
    SharedFormulaRecord sfr = null;

    while (i.hasNext() && !added)
    {
      sfr = (SharedFormulaRecord) i.next();
      added = sfr.add(fr);
    }

    return added;
  }

  /**
   * Reverts the shared formula passed in to an ordinary formula and adds
   * it to the list
   *
   * @return the formula
   */
  private Cell revertSharedFormula(BaseSharedFormulaRecord f)
  {
    FormulaRecord fr = new FormulaRecord(f.getRecord(),
                                         excelFile,
                                         formattingRecords,
                                         workbook,
                                         FormulaRecord.ignoreSharedFormula,
                                         this);
            
    Cell cell = fr.getFormula();
            
    // See if the formula evaluates to date
    if (fr.getFormula().getType() == CellType.NUMBER_FORMULA)
    {
      NumberFormulaRecord nfr = (NumberFormulaRecord) fr.getFormula();
      if (formattingRecords.isDate(fr.getXFIndex()))
      {
        cell = new DateFormulaRecord(nfr,
                                     formattingRecords, 
                                     workbook,
                                     nineteenFour,
                                     this);
      }
    }
    
    return cell;
  }
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -