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

📄 sheetreader.java

📁 实现JAVA界面的代码GWT
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SheetReader.java

package jxl.read.biff;

import common.Assert;
import common.Logger;
import java.util.*;
import jxl.*;
import jxl.biff.*;
import jxl.biff.drawing.*;
import jxl.biff.formula.FormulaException;
import jxl.format.PageOrientation;
import jxl.format.PaperSize;

// Referenced classes of package jxl.read.biff:
//            DimensionRecord, LabelSSTRecord, RKRecord, DateRecord, 
//            HyperlinkRecord, MergedCellsRecord, MulRKRecord, NumberValue, 
//            NumberRecord, BooleanRecord, ErrorRecord, PrintGridLinesRecord, 
//            PrintHeadersRecord, Window2Record, PaneRecord, ProtectRecord, 
//            SharedFormulaRecord, FormulaRecord, BaseSharedFormulaRecord, NumberFormulaRecord, 
//            DateFormulaRecord, LabelRecord, RStringRecord, PasswordRecord, 
//            RowRecord, BlankCell, MulBlankRecord, MulBlankCell, 
//            SCLRecord, ColumnInfoRecord, HeaderRecord, FooterRecord, 
//            SetupRecord, DefaultColumnWidthRecord, DefaultRowHeightRecord, LeftMarginRecord, 
//            RightMarginRecord, TopMarginRecord, BottomMarginRecord, HorizontalPageBreaksRecord, 
//            VerticalPageBreaksRecord, PLSRecord, CentreRecord, ButtonPropertySetRecord, 
//            CalcModeRecord, SaveRecalcRecord, BOFRecord, CellFeaturesAccessor, 
//            WorkbookParser, File, Record, RKHelper, 
//            CellValue, MarginRecord, SheetImpl, SSTRecord

final class SheetReader
{

    private static Logger logger;
    private File excelFile;
    private SSTRecord sharedStrings;
    private BOFRecord sheetBof;
    private BOFRecord workbookBof;
    private FormattingRecords formattingRecords;
    private int numRows;
    private int numCols;
    private Cell cells[][];
    private ArrayList outOfBoundsCells;
    private int startPosition;
    private ArrayList rowProperties;
    private ArrayList columnInfosArray;
    private ArrayList sharedFormulas;
    private ArrayList hyperlinks;
    private Range mergedCells[];
    private DataValidation dataValidation;
    private ArrayList charts;
    private ArrayList drawings;
    private DrawingData drawingData;
    private boolean nineteenFour;
    private PLSRecord plsRecord;
    private ButtonPropertySetRecord buttonPropertySet;
    private WorkspaceInformationRecord workspaceOptions;
    private int rowBreaks[];
    private int columnBreaks[];
    private SheetSettings settings;
    private WorkbookSettings workbookSettings;
    private WorkbookParser workbook;
    private SheetImpl sheet;
    static Class class$jxl$read$biff$SheetReader; /* synthetic field */

    SheetReader(File f, SSTRecord sst, FormattingRecords fr, BOFRecord sb, BOFRecord wb, boolean nf, WorkbookParser wp, 
            int sp, SheetImpl sh)
    {
        excelFile = f;
        sharedStrings = sst;
        formattingRecords = fr;
        sheetBof = sb;
        workbookBof = wb;
        columnInfosArray = new ArrayList();
        sharedFormulas = new ArrayList();
        hyperlinks = new ArrayList();
        rowProperties = new ArrayList(10);
        charts = new ArrayList();
        drawings = new ArrayList();
        outOfBoundsCells = new ArrayList();
        nineteenFour = nf;
        workbook = wp;
        startPosition = sp;
        sheet = sh;
        settings = new SheetSettings();
        workbookSettings = workbook.getSettings();
    }

    private void addCell(Cell cell)
    {
        if(cell.getRow() < numRows && cell.getColumn() < numCols)
        {
            if(cells[cell.getRow()][cell.getColumn()] != null)
            {
                StringBuffer sb = new StringBuffer();
                CellReferenceHelper.getCellReference(cell.getColumn(), cell.getRow(), sb);
                logger.warn("Cell " + sb.toString() + " already contains data");
            }
            cells[cell.getRow()][cell.getColumn()] = cell;
        } else
        {
            outOfBoundsCells.add(cell);
        }
    }

    final void read()
    {
        Record r = null;
        BaseSharedFormulaRecord sharedFormula = null;
        boolean sharedFormulaAdded = false;
        boolean cont = true;
        excelFile.setPos(startPosition);
        MsoDrawingRecord msoRecord = null;
        ObjRecord objRecord = null;
        boolean firstMsoRecord = true;
        Window2Record window2Record = null;
        PrintGridLinesRecord printGridLinesRecord = null;
        PrintHeadersRecord printHeadersRecord = null;
        HashMap comments = new HashMap();
        ArrayList objectIds = new ArrayList();
        do
        {
            if(!cont)
                break;
            r = excelFile.next();
            Type type = r.getType();
            if(type == Type.UNKNOWN && r.getCode() == 0)
            {
                logger.warn("Biff code zero found");
                if(r.getLength() == 10)
                {
                    logger.warn("Biff code zero found - trying a dimension record.");
                    r.setType(Type.DIMENSION);
                } else
                {
                    logger.warn("Biff code zero found - Ignoring.");
                }
            }
            if(type == 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];
            } else
            if(type == Type.LABELSST)
            {
                LabelSSTRecord label = new LabelSSTRecord(r, sharedStrings, formattingRecords, sheet);
                addCell(label);
            } else
            if(type == Type.RK || type == Type.RK2)
            {
                RKRecord rkr = new RKRecord(r, formattingRecords, sheet);
                if(formattingRecords.isDate(rkr.getXFIndex()))
                {
                    jxl.DateCell dc = new DateRecord(rkr, rkr.getXFIndex(), formattingRecords, nineteenFour, sheet);
                    addCell(dc);
                } else
                {
                    addCell(rkr);
                }
            } else
            if(type == Type.HLINK)
            {
                HyperlinkRecord hr = new HyperlinkRecord(r, sheet, workbookSettings);
                hyperlinks.add(hr);
            } else
            if(type == Type.MERGEDCELLS)
            {
                MergedCellsRecord mc = new MergedCellsRecord(r, sheet);
                if(mergedCells == null)
                {
                    mergedCells = mc.getRanges();
                } else
                {
                    Range newMergedCells[] = new Range[mergedCells.length + mc.getRanges().length];
                    System.arraycopy(mergedCells, 0, newMergedCells, 0, mergedCells.length);
                    System.arraycopy(mc.getRanges(), 0, newMergedCells, mergedCells.length, mc.getRanges().length);
                    mergedCells = newMergedCells;
                }
            } else
            if(type == Type.MULRK)
            {
                MulRKRecord mulrk = new MulRKRecord(r);
                int num = mulrk.getNumberOfColumns();
                int ixf = 0;
                int i = 0;
                while(i < num) 
                {
                    ixf = mulrk.getXFIndex(i);
                    NumberValue nv = new NumberValue(mulrk.getRow(), mulrk.getFirstColumn() + i, RKHelper.getDouble(mulrk.getRKNumber(i)), ixf, formattingRecords, sheet);
                    if(formattingRecords.isDate(ixf))
                    {
                        jxl.DateCell dc = new DateRecord(nv, ixf, formattingRecords, nineteenFour, sheet);
                        addCell(dc);
                    } else
                    {
                        nv.setNumberFormat(formattingRecords.getNumberFormat(ixf));
                        addCell(nv);
                    }
                    i++;
                }
            } else
            if(type == Type.NUMBER)
            {
                NumberRecord nr = new NumberRecord(r, formattingRecords, sheet);
                if(formattingRecords.isDate(nr.getXFIndex()))
                {
                    jxl.DateCell dc = new DateRecord(nr, nr.getXFIndex(), formattingRecords, nineteenFour, sheet);
                    addCell(dc);
                } else
                {
                    addCell(nr);
                }
            } else
            if(type == Type.BOOLERR)
            {
                BooleanRecord br = new BooleanRecord(r, formattingRecords, sheet);
                if(br.isError())
                {
                    ErrorRecord er = new ErrorRecord(br.getRecord(), formattingRecords, sheet);
                    addCell(er);
                } else
                {
                    addCell(br);
                }
            } else
            if(type == Type.PRINTGRIDLINES)
            {
                printGridLinesRecord = new PrintGridLinesRecord(r);
                settings.setPrintGridLines(printGridLinesRecord.getPrintGridLines());
            } else
            if(type == Type.PRINTHEADERS)
            {
                printHeadersRecord = new PrintHeadersRecord(r);
                settings.setPrintHeaders(printHeadersRecord.getPrintHeaders());
            } else
            if(type == Type.WINDOW2)
            {
                window2Record = new Window2Record(r);
                settings.setShowGridLines(window2Record.getShowGridLines());
                settings.setDisplayZeroValues(window2Record.getDisplayZeroValues());
                settings.setSelected(true);
                settings.setPageBreakPreviewMode(window2Record.isPageBreakPreview());
            } else
            if(type == Type.PANE)
            {
                PaneRecord pr = new PaneRecord(r);
                if(window2Record != null && window2Record.getFrozen())
                {
                    settings.setVerticalFreeze(pr.getRowsVisible());
                    settings.setHorizontalFreeze(pr.getColumnsVisible());
                }
            } else
            if(type != Type.CONTINUE)
                if(type == Type.NOTE)
                {
                    if(!workbookSettings.getDrawingsDisabled())
                    {
                        NoteRecord nr = new NoteRecord(r);
                        Comment comment = (Comment)comments.remove(new Integer(nr.getObjectId()));
                        if(comment == null)
                        {
                            logger.warn(" cannot find comment for note id " + nr.getObjectId() + "...ignoring");
                        } else
                        {
                            comment.setNote(nr);
                            drawings.add(comment);
                            addCellComment(comment.getColumn(), comment.getRow(), comment.getText(), comment.getWidth(), comment.getHeight());
                        }
                    }
                } else
                if(type != Type.ARRAY)
                    if(type == Type.PROTECT)
                    {
                        ProtectRecord pr = new ProtectRecord(r);
                        settings.setProtected(pr.isProtected());
                    } else
                    if(type == Type.SHAREDFORMULA)
                    {
                        if(sharedFormula == null)
                        {
                            logger.warn("Shared template formula is null - trying most recent formula template");
                            SharedFormulaRecord lastSharedFormula = (SharedFormulaRecord)sharedFormulas.get(sharedFormulas.size() - 1);
                            if(lastSharedFormula != null)
                                sharedFormula = lastSharedFormula.getTemplateFormula();
                        }
                        SharedFormulaRecord sfr = new SharedFormulaRecord(r, sharedFormula, workbook, workbook, sheet);
                        sharedFormulas.add(sfr);
                        sharedFormula = null;
                    } else
                    if(type == Type.FORMULA || type == Type.FORMULA2)
                    {
                        FormulaRecord fr = new FormulaRecord(r, excelFile, formattingRecords, workbook, workbook, sheet, workbookSettings);
                        if(fr.isShared())
                        {
                            BaseSharedFormulaRecord prevSharedFormula = sharedFormula;
                            sharedFormula = (BaseSharedFormulaRecord)fr.getFormula();
                            sharedFormulaAdded = addToSharedFormulas(sharedFormula);
                            if(sharedFormulaAdded)
                                sharedFormula = prevSharedFormula;
                            if(!sharedFormulaAdded && prevSharedFormula != null)
                                addCell(revertSharedFormula(prevSharedFormula));
                        } else
                        {
                            Cell cell = fr.getFormula();
                            try
                            {
                                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);
                            }

⌨️ 快捷键说明

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