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

📄 workbookparser.java

📁 jexcelapi_2_4, JXL的API, JXL是JAVA读取EXCEL的开源项目
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      }      else if (r.getType() == Type.FONT)      {        FontRecord fr = null;        if (bof.isBiff8())        {          fr = new FontRecord(r, settings);        }        else        {          fr = new FontRecord(r, settings, FontRecord.biff7);        }        fonts.addFont(fr);      }      else if (r.getType() == Type.PALETTE)      {        PaletteRecord palette = new PaletteRecord(r);        formattingRecords.setPalette(palette);      }      else if (r.getType() == Type.NINETEENFOUR)      {        NineteenFourRecord nr = new NineteenFourRecord(r);        nineteenFour = nr.is1904();      }      else if (r.getType() == Type.FORMAT)      {        FormatRecord fr = null;        if (bof.isBiff8())        {          fr = new FormatRecord(r, settings, FormatRecord.biff8);        }        else        {          fr = new FormatRecord(r, settings, FormatRecord.biff7);        }        try        {          formattingRecords.addFormat(fr);        }        catch (NumFormatRecordsException e)        {          // This should not happen.  Bomb out          Assert.verify(false, e.getMessage());        }      }      else if (r.getType() == Type.XF)      {        XFRecord xfr = null;        if (bof.isBiff8())        {          xfr = new XFRecord(r, XFRecord.biff8);        }        else        {          xfr = new XFRecord(r, XFRecord.biff7);        }        try        {          formattingRecords.addStyle(xfr);        }        catch (NumFormatRecordsException e)        {          // This should not happen.  Bomb out          Assert.verify(false, e.getMessage());        }      }      else if (r.getType() == Type.BOUNDSHEET)      {        BoundsheetRecord br = null;        if (bof.isBiff8())        {          br = new BoundsheetRecord(r);        }        else        {          br = new BoundsheetRecord(r, BoundsheetRecord.biff7);        }        if (br.isSheet() || br.isChart())        {          boundsheets.add(br);        }      }      else if (r.getType() == Type.EXTERNSHEET)      {        if (bof.isBiff8())        {          externSheet = new ExternalSheetRecord(r, settings);        }        else        {          externSheet = new ExternalSheetRecord(r, settings,                                                ExternalSheetRecord.biff7);        }      }      else if (r.getType() == Type.SUPBOOK)      {        SupbookRecord sr = new SupbookRecord(r, settings);        supbooks.add(sr);      }      else if (r.getType() == Type.PROTECT)      {        ProtectRecord pr = new ProtectRecord(r);        wbProtected = pr.isProtected();      }      else if (r.getType() == Type.MSODRAWINGGROUP)      {        msoDrawingGroup = new MsoDrawingGroupRecord(r);                if (drawingGroup == null)        {          drawingGroup = new DrawingGroup(DrawingGroup.READ);        }        drawingGroup.add(msoDrawingGroup);        Record nextrec = excelFile.peek();        while (nextrec.getType() == Type.CONTINUE)        {          drawingGroup.add(excelFile.next());          nextrec = excelFile.peek();        }      }      else if (r.getType() == Type.EOF)      {        bofs--;      }    }    bof = null;    if (excelFile.hasNext())    {      r = excelFile.next();      if (r.getType() == Type.BOF)      {        bof = new BOFRecord(r);      }    }    // Only get sheets for which there is a corresponding Boundsheet record    while (bof != null && getNumberOfSheets() < boundsheets.size())    {      if (!bof.isBiff8() && !bof.isBiff7())      {        throw new BiffException(BiffException.unrecognizedBiffVersion);      }      if (bof.isWorksheet())      {        // Read the sheet in        SheetImpl s = new SheetImpl(excelFile,                                    sharedStrings,                                    formattingRecords,                                    bof,                                    workbookBof,                                    nineteenFour,                                    this);        BoundsheetRecord br = (BoundsheetRecord) boundsheets.get          (getNumberOfSheets());        s.setName(br.getName());        s.setHidden(br.isHidden());        addSheet(s);      }      else if (bof.isChart())      {        // Read the sheet in        SheetImpl s = new SheetImpl(excelFile,                                    sharedStrings,                                    formattingRecords,                                    bof,                                    workbookBof,                                    nineteenFour,                                    this);        BoundsheetRecord br = (BoundsheetRecord) boundsheets.get          (getNumberOfSheets());        s.setName(br.getName());        s.setHidden(br.isHidden());        addSheet(s);      }      else      {        logger.warn("BOF is unrecognized");        while (excelFile.hasNext() && r.getType() != Type.EOF)        {          r = excelFile.next();        }      }      // The next record will normally be a BOF or empty padding until      // the end of the block is reached.  In exceptionally unlucky cases,      // the last EOF  will coincide with a block division, so we have to      // check there is more data to retrieve.      // Thanks to liamg for spotting this      bof = null;      if (excelFile.hasNext())      {        r = excelFile.next();        if (r.getType() == Type.BOF)        {          bof = new BOFRecord(r);        }      }    }  }  /**   * Accessor for the formattingRecords, used by the WritableWorkbook   * when creating a copy of this   *   * @return the formatting records   */  public FormattingRecords getFormattingRecords()  {    return formattingRecords;  }  /**   * Accessor for the externSheet, used by the WritableWorkbook   * when creating a copy of this   *   * @return the external sheet record   */  public ExternalSheetRecord getExternalSheetRecord()  {    return externSheet;  }  /**   * Accessor for the MsoDrawingGroup, used by the WritableWorkbook   * when creating a copy of this   *   * @return the Mso Drawing Group record   */  public MsoDrawingGroupRecord getMsoDrawingGroupRecord()  {    return msoDrawingGroup;  }  /**   * Accessor for the supbook records, used by the WritableWorkbook   * when creating a copy of this   *   * @return the supbook records   */  public SupbookRecord[] getSupbookRecords()  {    SupbookRecord[] sr = new SupbookRecord[supbooks.size()];    for (int i = 0; i < sr.length; i++)    {      sr[i] = (SupbookRecord) supbooks.get(i);    }    return sr;  }  /**   * Accessor for the name records.  Used by the WritableWorkbook when   * creating a copy of this   *   * @return the array of names   */  public NameRecord[] getNameRecords()  {    NameRecord[] na = new NameRecord[nameTable.size()];    for (int i = 0; i < nameTable.size(); i++)    {      na[i] = (NameRecord) nameTable.get(i);    }    return na;  }  /**   * Accessor for the fonts, used by the WritableWorkbook   * when creating a copy of this   * @return the fonts used in this workbook   */  public Fonts getFonts()  {    return fonts;  }  /**   * 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].getFirstSheet());    Cell cell = s.getCell(ranges[0].getFirstColumn(), ranges[0].getFirstRow());    return cell;  }  /**   * 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,                                    this,                                    ranges[i].getFirstSheet(),                                    ranges[i].getFirstColumn(),                                    ranges[i].getFirstRow(),                                    ranges[i].getLastSheet(),                                    ranges[i].getLastColumn(),                                    ranges[i].getLastRow());    }    return cellRanges;  }  /**   * Method used when parsing formulas to make sure we are trying   * to parse a supported biff version   *   * @return the BOF record   */  public BOFRecord getWorkbookBof()  {    return workbookBof;  }  /**   * Determines whether the sheet is protected   *   * @return whether or not the sheet is protected   */  public boolean isProtected()  {    return wbProtected;  }  /**   * Accessor for the settings   *   * @return the workbook settings   */  public WorkbookSettings getSettings()  {    return settings;  }  /**   * Accessor/implementation method for the external sheet reference   *   * @param sheetName the sheet name to look for   * @return the external sheet index   */  public int getExternalSheetIndex(String sheetName)  {    return 0;  }  /**   * Gets the name at the specified index   *   * @param index the index into the name table   * @return the name of the cell   */  public String getName(int index)  {    Assert.verify(index >= 0 && index < nameTable.size());    return ((NameRecord) nameTable.get(index)).getName();  }  /**   * Gets the index of the name record for the name   *   * @param name the name to search for   * @return the index in the name table   */  public int getNameIndex(String name)  {    NameRecord nr = (NameRecord) namedRecords.get(name);    return nr != null ? nr.getIndex() : 0;  }  /**   * Accessor for the drawing group   */  public DrawingGroup getDrawingGroup()  {    return drawingGroup;  }}

⌨️ 快捷键说明

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