Пример #1
0
 /// <summary> Sets the RGB value for the specified colour for this workbook
 ///
 /// </summary>
 /// <param name="c">the colour whose RGB value is to be overwritten
 /// </param>
 /// <param name="r">the red portion to set (0-255)
 /// </param>
 /// <param name="g">the green portion to set (0-255)
 /// </param>
 /// <param name="b">the blue portion to set (0-255)
 /// </param>
 public virtual void  setColourRGB(Colour c, int r, int g, int b)
 {
     if (palette == null)
     {
         palette = new PaletteRecord();
     }
     palette.setColourRGB(c, r, g, b);
 }
Пример #2
0
        /// <summary> Does the hard work of building up the object graph from the excel bytes
        ///
        /// </summary>
        /// <exception cref=""> BiffException
        /// </exception>
        /// <exception cref=""> PasswordException if the workbook is password protected
        /// </exception>
        protected internal 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();

            nameTable = new ArrayList();

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

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

                    // cast the array
                    System.Object[] rec     = continueRecords.ToArray();
                    Record[]        records = new Record[rec.Length];
                    Array.Copy(rec, 0, records, 0, rec.Length);

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

                    if (bof.isBiff8())
                    {
                        nr = new NameRecord(r, settings, namedRecords.Count);
                    }
                    else
                    {
                        nr = new NameRecord(r, settings, namedRecords.Count, NameRecord.biff7);
                    }

                    namedRecords[nr.Name] = nr;
                    nameTable.Add(nr);
                }
                else if (r.Type == NExcel.Biff.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.Type == NExcel.Biff.Type.PALETTE)
                {
                    NExcel.Biff.PaletteRecord palette = new NExcel.Biff.PaletteRecord(r);
                    formattingRecords.Palette = palette;
                }
                else if (r.Type == NExcel.Biff.Type.NINETEENFOUR)
                {
                    NineteenFourRecord nr = new NineteenFourRecord(r);
                    nineteenFour = nr.is1904();
                }
                else if (r.Type == NExcel.Biff.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());
                        Assert.verify(false, "This should not happen. 64");
                    }
                }
                else if (r.Type == NExcel.Biff.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());
                        Assert.verify(false, "This should not happen. 59");
                    }
                }
                else if (r.Type == NExcel.Biff.Type.BOUNDSHEET)
                {
                    BoundsheetRecord br = null;

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

                    if (br.isSheet() || br.Chart)
                    {
                        boundsheets.Add(br);
                    }
                }
                else if (r.Type == NExcel.Biff.Type.EXTERNSHEET)
                {
                    if (bof.isBiff8())
                    {
                        externSheet = new ExternalSheetRecord(r, settings);
                    }
                    else
                    {
                        externSheet = new ExternalSheetRecord(r, settings, ExternalSheetRecord.biff7);
                    }
                }
                else if (r.Type == NExcel.Biff.Type.CODEPAGE)
                {
                    CodepageRecord cr = new CodepageRecord(r);
                    settings.CharacterSet = cr.CharacterSet;
                }
                else if (r.Type == NExcel.Biff.Type.SUPBOOK)
                {
                    SupbookRecord sr = new SupbookRecord(r, settings);
                    supbooks.Add(sr);
                }
                else if (r.Type == NExcel.Biff.Type.PROTECT)
                {
                    ProtectRecord pr = new ProtectRecord(r);
                    wbProtected = pr.IsProtected();
                }
                else if (r.Type == NExcel.Biff.Type.MSODRAWINGGROUP)
                {
                    msoDrawingGroup = new MsoDrawingGroupRecord(r);

                    if (drawingGroup == null)
                    {
                        drawingGroup = new DrawingGroup(DrawingGroup.READ);
                    }

                    drawingGroup.add(msoDrawingGroup);

                    Record nextrec = excelFile.peek();
                    while (nextrec.Type == NExcel.Biff.Type.CONTINUE)
                    {
                        drawingGroup.add(excelFile.next());
                        nextrec = excelFile.peek();
                    }
                }
                else if (r.Type == NExcel.Biff.Type.EOF)
                {
                    bofs--;
                }
            }

            bof = null;
            if (excelFile.hasNext())
            {
                r = excelFile.next();

                if (r.Type == NExcel.Biff.Type.BOF)
                {
                    bof = new BOFRecord(r);
                }
            }

            // Only get sheets for which there is a corresponding Boundsheet record
            while (bof != null && NumberOfSheets < 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[NumberOfSheets];
                    s.setName(br.Name);
                    s.Hidden = 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[NumberOfSheets];
                    s.setName(br.Name);
                    s.Hidden = br.isHidden();
                    addSheet(s);
                }
                else
                {
                    logger.warn("BOF is unrecognized");


                    while (excelFile.hasNext() && r.Type != NExcel.Biff.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.Type == NExcel.Biff.Type.BOF)
                    {
                        bof = new BOFRecord(r);
                    }
                }
            }
        }