📄 sheetreader.java~
字号:
if (workbookBof.isBiff8()) { dr = new HorizontalPageBreaksRecord(r); } else { dr = new HorizontalPageBreaksRecord (r, HorizontalPageBreaksRecord.biff7); } rowBreaks = dr.getRowBreaks(); } else if (type == Type.VERTICALPAGEBREAKS) { VerticalPageBreaksRecord dr = null; if (workbookBof.isBiff8()) { dr = new VerticalPageBreaksRecord(r); } else { dr = new VerticalPageBreaksRecord (r, VerticalPageBreaksRecord.biff7); } columnBreaks = dr.getColumnBreaks(); } else if (type == Type.PLS) { plsRecord = new PLSRecord(r); } else if (type == Type.DVAL) { if (!workbookSettings.getCellValidationDisabled()) { DataValidityListRecord dvlr = new DataValidityListRecord(r); if (dvlr.getObjectId() == -1) { if (msoRecord != null && objRecord == null) { // there is a drop down associated with this data validation if (drawingData == null) { drawingData = new DrawingData(); } Drawing2 d2 = new Drawing2(msoRecord, drawingData, workbook.getDrawingGroup()); drawings.add(d2); msoRecord = null; dataValidation = new DataValidation(dvlr); } else { // no drop down dataValidation = new DataValidation(dvlr); } } else if (objectIds.contains(new Integer(dvlr.getObjectId()))) { dataValidation = new DataValidation(dvlr); } else { logger.warn("object id " + dvlr.getObjectId() + " referenced " + " by data validity list record not found - ignoring"); } } } else if (type == Type.HCENTER) { CentreRecord hr = new CentreRecord(r); settings.setHorizontalCentre(hr.isCentre()); } else if (type == Type.VCENTER) { CentreRecord vc = new CentreRecord(r); settings.setVerticalCentre(vc.isCentre()); } else if (type == Type.DV) { if (!workbookSettings.getCellValidationDisabled()) { DataValiditySettingsRecord dvsr = new DataValiditySettingsRecord(r, workbook, workbook, workbook.getSettings()); if (dataValidation != null) { dataValidation.add(dvsr); addCellValidation(dvsr.getFirstColumn(), dvsr.getFirstRow(), dvsr.getLastColumn(), dvsr.getLastRow(), dvsr); } else { logger.warn("cannot add data validity settings"); } } } else if (type == Type.OBJ) { objRecord = new ObjRecord(r); if (!workbookSettings.getDrawingsDisabled()) { // sometimes excel writes out continue records instead of drawing // records, so forcibly hack the stashed continue record into // a drawing record if (msoRecord == null && continueRecord != null) { logger.warn("Cannot find drawing record - using continue record"); msoRecord = new MsoDrawingRecord(continueRecord.getRecord()); continueRecord = null; } handleObjectRecord(objRecord, msoRecord, comments); objectIds.add(new Integer(objRecord.getObjectId())); } // Save chart handling until the chart BOF record appears if (objRecord.getType() != ObjRecord.CHART) { objRecord = null; msoRecord = null; } } else if (type == Type.MSODRAWING) { if (!workbookSettings.getDrawingsDisabled()) { if (msoRecord != null) { // For form controls, a rogue MSODRAWING record can crop up // after the main one. Add these into the drawing data drawingData.addRawData(msoRecord.getData()); } msoRecord = new MsoDrawingRecord(r); if (firstMsoRecord) { msoRecord.setFirst(); firstMsoRecord = false; } } } else if (type == Type.BUTTONPROPERTYSET) { buttonPropertySet = new ButtonPropertySetRecord(r); } else if (type == Type.CALCMODE) { CalcModeRecord cmr = new CalcModeRecord(r); settings.setAutomaticFormulaCalculation(cmr.isAutomatic()); } else if (type == Type.SAVERECALC) { SaveRecalcRecord cmr = new SaveRecalcRecord(r); settings.setRecalculateFormulasBeforeSave(cmr.getRecalculateOnSave()); } else if (type == Type.GUTS) { GuttersRecord gr = new GuttersRecord(r); maxRowOutlineLevel = gr.getRowOutlineLevel(); maxColumnOutlineLevel = gr.getColumnOutlineLevel(); } else if (type == 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 (br.isChart()) { if (!workbook.getWorkbookBof().isBiff8()) { logger.warn("only biff8 charts are supported"); } else { if (drawingData == null) { drawingData = new DrawingData(); } if (!workbookSettings.getDrawingsDisabled()) { Chart chart = new Chart(msoRecord, objRecord, drawingData, startpos, excelFile.getPos(), excelFile, workbookSettings); charts.add(chart); if (workbook.getDrawingGroup() != null) { workbook.getDrawingGroup().add(chart); } } } // Reset the drawing records msoRecord = null; objRecord = null; } // If this worksheet is just a chart, then the EOF reached // represents the end of the sheet as well as the end of the chart if (sheetBof.isChart()) { cont = false; } } else if (type == Type.EOF) { cont = false; } } // Restore the file to its accurate position excelFile.restorePos(); // Add any out of bounds cells if (outOfBoundsCells.size() > 0) { handleOutOfBoundsCells(); } // 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)); } // If there is a stray msoDrawing record, then flag to the drawing group // that one has been omitted if (msoRecord != null && workbook.getDrawingGroup() != null) { workbook.getDrawingGroup().setDrawingsOmitted(msoRecord, objRecord); } // Check that the comments hash is empty if (!comments.isEmpty()) { logger.warn("Not all comments have a corresponding Note record"); } } /** * Sees if the shared formula belongs to any of the shared formula * groups * * @param fr the candidate shared formula * @return TRUE if the formula was added, FALSE otherwise */ private boolean addToSharedFormulas(BaseSharedFormulaRecord fr) { boolean added = false; SharedFormulaRecord sfr = null; for (int i=0, size=sharedFormulas.size(); i<size && !added; ++i) { sfr = (SharedFormulaRecord ) sharedFormulas.get(i); added = sfr.add(fr); } return added; } /** * Reverts the shared formula passed in to an ordinary formula and adds * it to the list * * @param f the formula * @return the new formula * @exception FormulaException */ private Cell revertSharedFormula(BaseSharedFormulaRecord f) { // String formulas look for a STRING record soon after the formula // occurred. Temporarily the position in the excel file back // to the point immediately after the formula record int pos = excelFile.getPos(); excelFile.setPos(f.getFilePos()); FormulaRecord fr = new FormulaRecord(f.getRecord(), excelFile, formattingRecords, workbook, workbook, FormulaRecord.ignoreSharedFormula, sheet, workbookSettings); try { 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, workbook, nineteenFour, sheet); } } excelFile.setPos(pos); return cell; } catch (FormulaException e) { // Something has gone wrong trying to read the formula data eg. it // might be unsupported biff7 data logger.warn (CellReferenceHelper.getCellReference(fr.getColumn(), fr.getRow()) + " " + e.getMessage()); return null; } } /** * Accessor * * @return the number of rows */ final int getNumRows() { return numRows; } /** * Accessor * * @return the number of columns */ final int getNumCols() { return numCols; } /** * Accessor * * @return the cells */ final Cell[][] getCells() { return cells; } /** * Accessor * * @return the row properties */ final ArrayList getRowProperties() { return rowProperties; } /** * Accessor * * @return the column information */ final ArrayList getColumnInfosArray() { return columnInfosArray; } /** * Accessor * * @return the hyperlinks */ final ArrayList getHyperlinks() { return hyperlinks; } /** * Accessor * * @return the conditional formatting */ final ArrayList getConditionalFormats() { return conditionalFormats; } /** * Accessor * * @return the autofilter */ final AutoFilter getAutoFilter() { return autoFilter; } /** * Accessor * * @return the charts */ final ArrayList getCharts() { return charts; } /** * Accessor * * @return the drawings */ final ArrayList getDrawings() { return drawings; } /** * Accessor *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -