📄 sheetreader.java
字号:
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, workbook, nineteenFour, sheet); } } addCell(cell); } } else if (r.getType() == Type.LABEL) { LabelRecord lr = null; if (workbookBof.isBiff8()) { lr = new LabelRecord(r, formattingRecords, sheet, workbookSettings); } else { lr = new LabelRecord(r, formattingRecords, sheet, workbookSettings, LabelRecord.biff7); } addCell(lr); } else if (r.getType() == Type.RSTRING) { RStringRecord lr = null; // RString records are obsolete in biff 8 Assert.verify(!workbookBof.isBiff8()); lr = new RStringRecord(r, formattingRecords, sheet, workbookSettings, RStringRecord.biff7); addCell(lr); } else if (r.getType() == Type.NAME) { ; } else if (r.getType() == Type.PASSWORD) { PasswordRecord pr = new PasswordRecord(r); settings.setPasswordHash(pr.getPasswordHash()); } else 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); } } else if (r.getType() == Type.BLANK) { BlankCell bc = new BlankCell(r, formattingRecords, sheet); addCell(bc); } else if (r.getType() == Type.MULBLANK) { MulBlankRecord mulblank = new MulBlankRecord(r); // Get the individual cell records from the multiple record int num = mulblank.getNumberOfColumns(); for (int i = 0; i < num; i++) { int ixf = mulblank.getXFIndex(i); MulBlankCell mbc = new MulBlankCell (mulblank.getRow(), mulblank.getFirstColumn() + i, ixf, formattingRecords, sheet); addCell(mbc); } } else if (r.getType() == Type.SCL) { SCLRecord scl = new SCLRecord(r); settings.setZoomFactor(scl.getZoomFactor()); } else if (r.getType() == Type.COLINFO) { ColumnInfoRecord cir = new ColumnInfoRecord(r); columnInfosArray.add(cir); } else if (r.getType() == Type.HEADER) { if (workbookBof.isBiff8()) { header = new HeaderRecord(r, workbookSettings); } else { header = new HeaderRecord(r, workbookSettings, HeaderRecord.biff7); } } else if (r.getType() == Type.FOOTER) { if (workbookBof.isBiff8()) { footer = new FooterRecord(r, workbookSettings); } else { footer = new FooterRecord(r, workbookSettings, FooterRecord.biff7); } } else if (r.getType() == Type.SETUP) { SetupRecord sr = new SetupRecord(r); if (sr.isPortrait()) { settings.setOrientation(PageOrientation.PORTRAIT); } else { settings.setOrientation(PageOrientation.LANDSCAPE); } settings.setPaperSize(PaperSize.getPaperSize(sr.getPaperSize())); settings.setHeaderMargin(sr.getHeaderMargin()); settings.setFooterMargin(sr.getFooterMargin()); settings.setScaleFactor(sr.getScaleFactor()); settings.setPageStart(sr.getPageStart()); settings.setFitWidth(sr.getFitWidth()); settings.setFitHeight(sr.getFitHeight()); settings.setHorizontalPrintResolution (sr.getHorizontalPrintResolution()); settings.setVerticalPrintResolution(sr.getVerticalPrintResolution()); settings.setCopies(sr.getCopies()); if (workspaceOptions != null) { settings.setFitToPages(workspaceOptions.getFitToPages()); } } else if (r.getType() == Type.WSBOOL) { workspaceOptions = new WorkspaceInformationRecord(r); } else if (r.getType() == Type.DEFCOLWIDTH) { DefaultColumnWidthRecord dcwr = new DefaultColumnWidthRecord(r); settings.setDefaultColumnWidth(dcwr.getWidth()); } else if (r.getType() == Type.DEFAULTROWHEIGHT) { DefaultRowHeightRecord drhr = new DefaultRowHeightRecord(r); if (drhr.getHeight() != 0) { settings.setDefaultRowHeight(drhr.getHeight()); } } else if (r.getType() == Type.LEFTMARGIN) { MarginRecord m = new LeftMarginRecord(r); settings.setLeftMargin(m.getMargin()); } else if (r.getType() == Type.RIGHTMARGIN) { MarginRecord m = new RightMarginRecord(r); settings.setRightMargin(m.getMargin()); } else if (r.getType() == Type.TOPMARGIN) { MarginRecord m = new TopMarginRecord(r); settings.setTopMargin(m.getMargin()); } else if (r.getType() == Type.BOTTOMMARGIN) { MarginRecord m = new BottomMarginRecord(r); settings.setBottomMargin(m.getMargin()); } else 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(); } else if (r.getType() == Type.PLS) { plsRecord = new PLSRecord(r); } else if (r.getType() == Type.OBJ) { objRecord = new ObjRecord(r); if (objRecord.getType() == ObjRecord.PICTURE) { Drawing drawing = new Drawing(msoRecord, objRecord, workbook.getDrawingGroup()); drawings.add(drawing); msoRecord = null; objRecord = null; } } else if (r.getType() == Type.MSODRAWING) { msoRecord = new MsoDrawingRecord(r); } else 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 (br.isChart()) { Chart chart = new Chart(msoRecord, objRecord, startpos, excelFile.getPos(), excelFile, workbookSettings); charts.add(chart); 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 (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)); } } /** * 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) { 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 * * @param f the formula * @return the new formula */ 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); 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; } /** * 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 charts */ final ArrayList getCharts() { return charts; } /** * Accessor * * @return the drawings */ final ArrayList getDrawings() { return drawings; } /** * Accessor * * @return the ranges */ final Range[] getMergedCells() { return mergedCells; } /** * Accessor * * @return the page header */ final HeaderRecord getHeader() { return header; } /** * Accessor * * @return the page footer */ final FooterRecord getFooter() { return footer; } /** * Accessor * * @return the sheet settings */ final SheetSettings getSettings() { return settings; } /** * Accessor * * @return the row breaks */ final int[] getRowBreaks() { return rowBreaks; } /** * Accessor * * @return the workspace options */ final WorkspaceInformationRecord getWorkspaceOptions() { return workspaceOptions; } /** * Accessor * * @return the environment specific print record */ final PLSRecord getPLS() { return plsRecord; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -