Esempio n. 1
0
        /**
         * Gets the CellFormat object for this cell.  Used by the WritableWorkbook
         * API
         *
         * @return the CellFormat used for this cell
         */
        public CellFormat getCellFormat()
        {
            if (!initialized)
                {
                format = formattingRecords.getXFRecord(xfIndex);
                initialized = true;
                }

            return format;
        }
 /**
  * Sets the cell format.  Used when importing spreadsheets
  *
  * @param xfr the xf record
  */
 public void setCellFormat(XFRecord xfr)
 {
     style = xfr;
 }
 /**
  * Constructor used when setting column information from the user
  * API
  *
  * @param w the width of the column in characters
  * @param col the column to format
  * @param xf the style for the column
  */
 public ColumnInfoRecord(int col, int w, XFRecord xf)
     : base(Type.COLINFO)
 {
     column = col;
     width = w;
     style = xf;
     xfIndex = style.getXFIndex();
     hidden = false;
 }
 /**
  * Copy constructor used when copying from sheet to sheet within the
  * same workbook
  *
  * @param the record to copy
  */
 public ColumnInfoRecord(ColumnInfoRecord cir)
     : base(Type.COLINFO)
 {
     column = cir.column;
     width = cir.width;
     style = cir.style;
     xfIndex = cir.xfIndex;
     hidden = cir.hidden;
     outlineLevel = cir.outlineLevel;
     collapsed = cir.collapsed;
 }
 /**
  * Constructor used when copying an existing spreadsheet
  *
  * @param col the column number
  * @param cir the column info record read in
  * @param fr  the format records
  */
 public ColumnInfoRecord(CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord cir,int col,FormattingRecords fr)
     : base(Type.COLINFO)
 {
     column = col;
     width = cir.getWidth();
     xfIndex = cir.getXFIndex();
     style = fr.getXFRecord(xfIndex);
     outlineLevel = cir.getOutlineLevel();
     collapsed = cir.getCollapsed();
 }
 /**
  * Copy constructor.  Invoked when copying formats to handle cell merging
  *
  * @param fmt the format to copy
  */
 public CellXFRecord(XFRecord fmt)
     : base(fmt)
 {
     setXFDetails(XFRecord.cell, 0);
 }
        /**
         * Does the hard work of building up the object graph from the excel bytes
         *
         * @exception BiffException
         * @exception PasswordException if the workbook is password protected
         */
        protected override void parse()
        {
            Record r = null;

            BOFRecord bof = new BOFRecord(excelFile.next());
            workbookBof = bof;
            bofs++;

            if (!bof.isBiff8() && !bof.isBiff7())
                {
                throw new BiffException(BiffException.unrecognizedBiffVersion);
                }

            if (!bof.isWorkbookGlobals())
                {
                throw new BiffException(BiffException.expectedGlobals);
                }
            ArrayList continueRecords = new ArrayList();
            ArrayList localNames = new ArrayList();
            nameTable = new ArrayList();
            addInFunctions = new ArrayList();

            // Skip to the first worksheet
            while (bofs == 1)
                {
                r = excelFile.next();

                if (r.getType() == Type.SST)
                    {
                    continueRecords.Clear();
                    Record nextrec = excelFile.peek();
                    while (nextrec.getType() == Type.CONTINUE)
                        {
                        continueRecords.Add(excelFile.next());
                        nextrec = excelFile.peek();
                        }

                    // cast the array
                    Record[] records = new Record[continueRecords.Count];
                    int pos = 0;
                    foreach (Record record in continueRecords)
                        records[pos++] = record;

                    sharedStrings = new SSTRecord(r,records,settings);
                    }
                else if (r.getType() == Type.FILEPASS)
                    {
                    throw new PasswordException();
                    }
                else if (r.getType() == Type.NAME)
                    {
                    NameRecord nr = null;

                    if (bof.isBiff8())
                        {
                        nr = new NameRecord(r,settings,nameTable.Count);

                        }
                    else
                        {
                        nr = new NameRecord(r,settings,nameTable.Count,
                                            NameRecord.biff7);
                        }

                    // Add all local and global names to the name table in order to
                    // preserve the indexing
                    nameTable.Add(nr);

                    if (nr.isGlobal())
                        namedRecords.Add(nr.getName(),nr);
                    else
                        localNames.Add(nr);
                    }
                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)
                    {
                    CSharpJExcel.Jxl.Biff.PaletteRecord palette = new CSharpJExcel.Jxl.Biff.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.Message);
                        }
                    }
                else if (r.getType() == Type.XF)
                    {
                    XFRecord xfr = null;
                    if (bof.isBiff8())
                        xfr = new XFRecord(r,settings,XFRecord.biff8);
                    else
                        xfr = new XFRecord(r,settings,XFRecord.biff7);

                    try
                        {
                        formattingRecords.addStyle(xfr);
                        }
                    catch (NumFormatRecordsException e)
                        {
                        // This should not happen.  Bomb out
                        Assert.verify(false,e.Message);
                        }
                    }
                else if (r.getType() == Type.BOUNDSHEET)
                    {
                    BoundsheetRecord br = null;

                    if (bof.isBiff8())
                        br = new BoundsheetRecord(r,settings);
                    else
                        br = new BoundsheetRecord(r,BoundsheetRecord.biff7);

                    if (br.isSheet())
                        boundsheets.Add(br);
                    else if (br.isChart() && !settings.getDrawingsDisabled())
                        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.XCT)
                    {
                    XCTRecord xctr = new XCTRecord(r);
                    xctRecords.Add(xctr);
                    }
                else if (r.getType() == Type.CODEPAGE)
                    {
                    CodepageRecord cr = new CodepageRecord(r);
                    settings.setCharacterSet(cr.getCharacterSet());
                    }
                else if (r.getType() == Type.SUPBOOK)
                    {
                    Record nextrec = excelFile.peek();
                    while (nextrec.getType() == Type.CONTINUE)
                        {
                        r.addContinueRecord(excelFile.next());
                        nextrec = excelFile.peek();
                        }

                    SupbookRecord sr = new SupbookRecord(r,settings);
                    supbooks.Add(sr);
                    }
                else if (r.getType() == Type.EXTERNNAME)
                    {
                    ExternalNameRecord enr = new ExternalNameRecord(r,settings);

                    if (enr.isAddInFunction())
                        {
                        addInFunctions.Add(enr.getName());
                        }
                    }
                else if (r.getType() == Type.PROTECT)
                    {
                    ProtectRecord pr = new ProtectRecord(r);
                    wbProtected = pr.isProtected();
                    }
                else if (r.getType() == Type.OBJPROJ)
                    {
                    doesContainMacros = true;
                    }
                else if (r.getType() == Type.COUNTRY)
                    {
                    countryRecord = new CountryRecord(r);
                    }
                else if (r.getType() == Type.MSODRAWINGGROUP)
                    {
                    if (!settings.getDrawingsDisabled())
                        {
                        msoDrawingGroup = new MsoDrawingGroupRecord(r);

                        if (drawingGroup == null)
                            {
                            drawingGroup = new DrawingGroup(Origin.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.BUTTONPROPERTYSET)
                    buttonPropertySet = new ButtonPropertySetRecord(r);
                else if (r.getType() == Type.EOF)
                    bofs--;
                else if (r.getType() == Type.REFRESHALL)
                    {
                    RefreshAllRecord rfm = new RefreshAllRecord(r);
                    settings.setRefreshAll(rfm.getRefreshAll());
                    }
                else if (r.getType() == Type.TEMPLATE)
                    {
                    TemplateRecord rfm = new TemplateRecord(r);
                    settings.setTemplate(rfm.getTemplate());
                    }
                else if (r.getType() == Type.EXCEL9FILE)
                    {
                    Excel9FileRecord e9f = new Excel9FileRecord(r);
                    settings.setExcel9File(e9f.getExcel9File());
                    }
                else if (r.getType() == Type.WINDOWPROTECT)
                    {
                    WindowProtectedRecord winp = new WindowProtectedRecord(r);
                    settings.setWindowProtected(winp.getWindowProtected());
                    }
                else if (r.getType() == Type.HIDEOBJ)
                    {
                    HideobjRecord hobj = new HideobjRecord(r);
                    settings.setHideobj(hobj.getHideMode());
                    }
                else if (r.getType() == Type.WRITEACCESS)
                    {
                    WriteAccessRecord war = new WriteAccessRecord(r,bof.isBiff8(),settings);
                    settings.setWriteAccess(war.getWriteAccess());
                    }
                else
                    {
                    // logger.info("Unsupported record type: " +
                    //            Integer.toHexString(r.getCode())+"h");
                    }
                }

            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.Count)
                {
                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[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[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);
                    }
                }

            // Add all the local names to the specific sheets
            foreach (NameRecord nr in localNames)
                {
                if (nr.getBuiltInName() == null)
                    {
                    //logger.warn("Usage of a local non-builtin name");
                    }
                else if (nr.getBuiltInName() == BuiltInName.PRINT_AREA ||
                         nr.getBuiltInName() == BuiltInName.PRINT_TITLES)
                    {
                    // appears to use the internal tab number rather than the
                    // external sheet index
                    SheetImpl s = (SheetImpl)sheets[nr.getSheetRef() - 1];
                    s.addLocalName(nr);
                    }
                }
        }
Esempio n. 8
0
        /**
         * Adds the format information to the shared records.  Performs the necessary
         * checks (and clones) to ensure that the formats are not shared.
         * Called from setCellDetails and setCellFormat
         */
        private void addCellFormat()
        {
            // Check to see if the format is one of the shared Workbook defaults.  If
            // so, then get hold of the Workbook's specific instance
            Styles styles = sheet.getWorkbook().getStyles();
            format = styles.getFormat(format);

            try
                {
                if (!format.isInitialized())
                    {
                    formattingRecords.addStyle(format);
                    }
                }
            catch (NumFormatRecordsException e)
                {
                //logger.warn("Maximum number of format records exceeded.  Using default format.");
                format = styles.getNormalStyle();
                }
        }
Esempio n. 9
0
        /**
         * Sets the row details based upon the readable row record passed in
         * Called when copying spreadsheets
         *
         * @param height the height of the row record in 1/20ths of a point
         * @param mdfh matches the default font height
         * @param col the collapsed status of the row
         * @param ol the outline level
         * @param gs the group start
         * @param xf the xfrecord for the row (NULL if no default is set)
         */
        public void setRowDetails(int height,
            bool mdfh,
            bool col,
            int ol,
            bool gs,
            XFRecord xfr)
        {
            rowHeight = height;
            collapsed = col;
            matchesDefFontHeight = mdfh;
            outlineLevel = ol;
            groupStart = gs;

            if (xfr != null)
                {
                defaultFormat = true;
                style = xfr;
                xfIndex = style.getXFIndex();
                }
        }
Esempio n. 10
0
        /**
         * An API function which sets the format to apply to this cell
         *
         * @param cf the format to apply to this cell
         */
        public void setCellFormat(CellFormat cf)
        {
            format = (XFRecord)cf;

            // If the referenced flag has not been set, this cell has not
            // been added to the spreadsheet, so we don't need to perform
            // any further logic
            if (!referenced)
                {
                return;
                }

            // The cell has already been added to the spreadsheet, so the
            // formattingRecords reference must be initialized
            Assert.verify(formattingRecords != null);

            addCellFormat();
        }
Esempio n. 11
0
        /**
         * Copy constructor
         *
         * @param c the column
         * @param t the cell type
         * @param r the row
         * @param cv the value to copy
         */
        protected CellValue(Type t, int c, int r, CellValue cv)
            : base(t)
        {
            row = r;
            column = c;
            format = cv.format;
            referenced = false;
            copied = false; // used during a deep copy, so the cell features need
            // to be added again

            if (cv.features != null)
                {
                features = new WritableCellFeatures(cv.features);
                features.setWritableCell(this);
                }
        }
Esempio n. 12
0
 /**
  * Overloaded constructor used when building writable cells from the
  * Java API which also takes a format
  *
  * @param c the column
  * @param t the cell type
  * @param r the row
  * @param st the format to apply to this cell
  */
 protected CellValue(Type t, int c, int r, CellFormat st)
     : base(t)
 {
     row = r;
     column = c;
     format = (XFRecord)st;
     referenced = false;
     copied = false;
 }
Esempio n. 13
0
        /**
         * Constructor used when creating a writable cell from a read-only cell
         * (when copying a workbook)
         *
         * @param c the cell to clone
         * @param t the type of this cell
         */
        protected CellValue(Type t, Cell c)
            : this(t, c.getColumn(), c.getRow())
        {
            copied = true;

            format = (XFRecord)c.getCellFormat();

            if (c.getCellFeatures() != null)
                {
                features = new WritableCellFeatures(c.getCellFeatures());
                features.setWritableCell(this);
                }
        }
Esempio n. 14
0
        /**
         * Copy constructor.  Used for copying writable formats, typically
         * when duplicating formats to handle merged cells
         *
         * @param fmt XFRecord
         */
        protected XFRecord(XFRecord fmt)
            : base(Type.XF)
        {
            initialized = false;
            locked = fmt.locked;
            hidden = fmt.hidden;
            align = fmt.align;
            valign = fmt.valign;
            orientation = fmt.orientation;
            wrap = fmt.wrap;
            leftBorder = fmt.leftBorder;
            rightBorder = fmt.rightBorder;
            topBorder = fmt.topBorder;
            bottomBorder = fmt.bottomBorder;
            leftBorderColour = fmt.leftBorderColour;
            rightBorderColour = fmt.rightBorderColour;
            topBorderColour = fmt.topBorderColour;
            bottomBorderColour = fmt.bottomBorderColour;
            pattern = fmt.pattern;
            xfFormatType = fmt.xfFormatType;
            indentation = fmt.indentation;
            shrinkToFit = fmt.shrinkToFit;
            parentFormat = fmt.parentFormat;
            backgroundColour = fmt.backgroundColour;

            // Shallow copy is sufficient for these purposes
            font = fmt.font;
            format = fmt.format;

            fontIndex = fmt.fontIndex;
            formatIndex = fmt.formatIndex;

            formatInfoInitialized = fmt.formatInfoInitialized;

            biffType = biff8;
            read = false;
            copied = true;
        }