예제 #1
0
        public void TestReadContinued()
        {
            //simulate a continues Drawing record
            MemoryStream out1 = new MemoryStream();
            //main part
            DrawingRecord dg = new DrawingRecord();

            byte[] data1 = new byte[8224];
            Arrays.Fill(data1, (byte)1);
            dg.Data = (/*setter*/ data1);
            byte[] dataX = dg.Serialize();
            out1.Write(dataX, 0, dataX.Length);

            //continued part
            byte[] data2 = new byte[4048];
            Arrays.Fill(data2, (byte)2);
            ContinueRecord cn = new ContinueRecord(data2);

            dataX = cn.Serialize();
            out1.Write(dataX, 0, dataX.Length);

            List <Record> rec = RecordFactory.CreateRecords(new MemoryStream(out1.ToArray()));

            Assert.AreEqual(2, rec.Count);
            Assert.IsTrue(rec[0] is DrawingRecord);
            Assert.IsTrue(rec[1] is ContinueRecord);

            Assert.IsTrue(Arrays.Equals(data1, ((DrawingRecord)rec[0]).Data));
            Assert.IsTrue(Arrays.Equals(data2, ((ContinueRecord)rec[1]).Data));
        }
예제 #2
0
        public void TestContinuedUnknownRecord()
        {
            byte[] data =
            {
                0,    unchecked ((byte)-1), 0, 0,          // an unknown record with 0 length
                0x3C,                    0, 3, 0, 1, 2, 3, // a continuation record with 3 bytes of data
                0x3C,                    0, 1, 0, 4        // one more continuation record with 1 byte of data
            };

            MemoryStream bois = new MemoryStream(data);

            Record[] records = (Record[])
                               RecordFactory.CreateRecords(bois).ToArray();
            Assert.AreEqual(3, records.Length, "Created record count");
            Assert.AreEqual(
                typeof(UnknownRecord).Name,
                records[0].GetType().Name, "1st record's type");
            Assert.AreEqual((short)-256, records[0].Sid, "1st record's sid");
            Assert.AreEqual(typeof(ContinueRecord).Name,
                            records[1].GetType().Name, "2nd record's type");
            ContinueRecord record = (ContinueRecord)records[1];

            Assert.AreEqual(0x3C, record.Sid, "2nd record's sid");
            Assert.AreEqual(1, record.Data[0], "1st data byte");
            Assert.AreEqual(2, record.Data[1], "2nd data byte");
            Assert.AreEqual(3, record.Data[2], "3rd data byte");
            Assert.AreEqual(
                typeof(ContinueRecord).Name,
                records[2].GetType().Name, "3rd record's type");
            record = (ContinueRecord)records[2];
            Assert.AreEqual(0x3C, record.Sid, "3nd record's sid");
            Assert.AreEqual(4, record.Data[0], "4th data byte");
        }
예제 #3
0
        /**
         * Writes out the additional comment records
         *
         * @param outputFile the output file
         * @exception IOException
         */
        public virtual void writeAdditionalRecords(File outputFile)
        {
            if (origin == Origin.READ)
            {
                outputFile.write(objRecord);

                if (mso != null)
                {
                    outputFile.write(mso);
                }
                outputFile.write(txo);
                outputFile.write(text);
                if (formatting != null)
                {
                    outputFile.write(formatting);
                }
                return;
            }

            // Create the obj record
            ObjRecord objrec = new ObjRecord(objectId, ObjRecord.EXCELNOTE);

            outputFile.write(objrec);

            // Create the mso data record.  Write the text box record again,
            // although it is already included in the SpContainer
            ClientTextBox    textBox = new ClientTextBox();
            MsoDrawingRecord msod    = new MsoDrawingRecord(textBox.getData());

            outputFile.write(msod);

            TextobjectRecord txorec = new TextobjectRecord(getText());

            outputFile.write(txorec);

            // Data for the first continue record
            byte[] textData = new byte[commentText.Length * 2 + 1];
            textData[0] = 0x1;             // unicode indicator
            StringHelper.getUnicodeBytes(commentText, textData, 1);
            //StringHelper.getBytes(commentText, textData, 1);
            ContinueRecord textContinue = new ContinueRecord(textData);

            outputFile.write(textContinue);

            // Data for the formatting runs

            byte[] frData = new byte[16];

            // First txo run (the user)
            IntegerHelper.getTwoBytes(0, frData, 0);           // index to the first character
            IntegerHelper.getTwoBytes(0, frData, 2);           // index to the font(default)
            // Mandatory last txo run
            IntegerHelper.getTwoBytes(commentText.Length, frData, 8);
            IntegerHelper.getTwoBytes(0, frData, 10);           // index to the font(default)

            ContinueRecord frContinue = new ContinueRecord(frData);

            outputFile.write(frContinue);
        }
예제 #4
0
파일: CheckBox.cs 프로젝트: morninn/PetSof
        /**
         * Copy constructor used to copy drawings from read to write
         *
         * @param dgo the drawing group object
         * @param dg the drawing group
         * @param ws the workbook settings
         */
        public CheckBox(DrawingGroupObject dgo,
                        DrawingGroup dg,
                        WorkbookSettings ws)
        {
            CheckBox d = (CheckBox)dgo;

            Assert.verify(d.origin == Origin.READ);
            msoDrawingRecord = d.msoDrawingRecord;
            objRecord        = d.objRecord;
            initialized      = false;
            origin           = Origin.READ;
            drawingData      = d.drawingData;
            drawingGroup     = dg;
            drawingNumber    = d.drawingNumber;
            drawingGroup.addDrawing(this);
            mso              = d.mso;
            txo              = d.txo;
            text             = d.text;
            formatting       = d.formatting;
            workbookSettings = ws;
        }
예제 #5
0
        public void TestDuplicatePLS_bug47415()
        {
            NPOI.HSSF.Record.Record   plsA   = ur(UnknownRecord.PLS_004D, "BA AD F0 0D");
            NPOI.HSSF.Record.Record   plsB   = ur(UnknownRecord.PLS_004D, "DE AD BE EF");
            NPOI.HSSF.Record.Record   contB1 = new ContinueRecord(HexRead.ReadFromString("FE ED"));
            NPOI.HSSF.Record.Record   contB2 = new ContinueRecord(HexRead.ReadFromString("FA CE"));
            NPOI.HSSF.Record.Record[] recs   =
            {
                new HeaderRecord("&LSales Figures"),
                new FooterRecord("&LInventory"),
                new HCenterRecord(),
                new VCenterRecord(),
                plsA,
                plsB,                               contB1, contB2, // make sure continuing PLS is still OK
            };
            RecordStream      rs = new RecordStream(Arrays.AsList(recs), 0);
            PageSettingsBlock psb;

            try
            {
                psb = new PageSettingsBlock(rs);
            }
            catch (RecordFormatException e)
            {
                if ("Duplicate PageSettingsBlock record (sid=0x4d)".Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 47415");
                }
                throw e;
            }

            // serialize the PSB to see what records come out
            RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector();
            psb.VisitContainedRecords(rc);
            NPOI.HSSF.Record.Record[] outRecs = rc.Records;

            // records were assembled in standard order, so this simple check is OK
            Assert.IsTrue(Arrays.Equals(recs, outRecs));
        }
예제 #6
0
        public void TestReadContinued()
        {
            //simulate a continues Drawing record
            MemoryStream out1 = new MemoryStream();
            //main part
            DrawingRecord dg = new DrawingRecord();

            byte[] data1 = new byte[8224];
            Arrays.Fill(data1, (byte)1);
            dg.Data = (/*setter*/ data1);
            byte[] dataX = dg.Serialize();
            out1.Write(dataX, 0, dataX.Length);

            //continued part
            byte[] data2 = new byte[4048];
            Arrays.Fill(data2, (byte)2);
            ContinueRecord cn = new ContinueRecord(data2);

            dataX = cn.Serialize();
            out1.Write(dataX, 0, dataX.Length);

            List <Record> rec = RecordFactory.CreateRecords(new MemoryStream(out1.ToArray()));

            Assert.AreEqual(1, rec.Count);
            Assert.IsTrue(rec[0] is DrawingRecord);

            //DrawingRecord.Data should return concatenated data1 and data2
            byte[] tmp = new byte[data1.Length + data2.Length];
            Array.Copy(data1, 0, tmp, 0, data1.Length);
            Array.Copy(data2, 0, tmp, data1.Length, data2.Length);

            DrawingRecord dg2 = (DrawingRecord)rec[(0)];

            Assert.AreEqual(data1.Length + data2.Length, dg2.Data.Length);
            Assert.IsTrue(Arrays.Equals(tmp, dg2.Data));
        }
예제 #7
0
        /**
         * Copy constructor used to copy drawings from read to write
         *
         * @param dgo the drawing group object
         * @param dg the drawing group
         * @param ws the workbook settings
         */
        /*protected*/
        public Comment(DrawingGroupObject dgo,
                       DrawingGroup dg,
                       WorkbookSettings ws)
        {
            Comment d = (Comment)dgo;

            Assert.verify(d.origin == Origin.READ);
            msoDrawingRecord = d.msoDrawingRecord;
            objRecord        = d.objRecord;
            initialized      = false;
            origin           = Origin.READ;
            drawingData      = d.drawingData;
            drawingGroup     = dg;
            drawingNumber    = d.drawingNumber;
            drawingGroup.addDrawing(this);
            mso              = d.mso;
            txo              = d.txo;
            text             = d.text;
            formatting       = d.formatting;
            note             = d.note;
            width            = d.width;
            height           = d.height;
            workbookSettings = ws;
        }
예제 #8
0
파일: CheckBox.cs 프로젝트: morninn/PetSof
 /**
  * Sets the formatting
  *
  * @param t continue record
  */
 public virtual void setFormatting(ContinueRecord t)
 {
     formatting = t;
 }
예제 #9
0
파일: CheckBox.cs 프로젝트: morninn/PetSof
 /**
  * Sets the text data
  *
  * @param t continuation record
  */
 public virtual void setText(ContinueRecord t)
 {
     text = t;
 }
예제 #10
0
        /// <summary>
        /// Returns the next available record, or null if
        /// this pass didn't return a record that's
        /// suitable for returning (eg was a continue record).
        /// </summary>
        /// <returns></returns>
        private Record GetNextRecord()
        {
            Record toReturn = null;

            if (in1.HasNextRecord)
            {
                // Grab our next record
                in1.NextRecord();
                short sid = in1.Sid;

                //
                // for some reasons we have to make the workbook to be at least 4096 bytes
                // but if we have such workbook we Fill the end of it with zeros (many zeros)
                //
                // it Is not good:
                // if the Length( all zero records ) % 4 = 1
                // e.g.: any zero record would be Readed as  4 bytes at once ( 2 - id and 2 - size ).
                // And the last 1 byte will be Readed WRONG ( the id must be 2 bytes )
                //
                // So we should better to Check if the sid Is zero and not to Read more data
                // The zero sid shows us that rest of the stream data Is a fake to make workbook
                // certain size
                //
                if (sid == 0)
                {
                    return(null);
                }


                // If we had a last record, and this one
                //  Isn't a continue record, then pass
                //  it on to the listener
                if ((rec != null) && (sid != ContinueRecord.sid))
                {
                    // This last record ought to be returned
                    toReturn = rec;
                }

                // If this record Isn't a continue record,
                //  then build it up
                if (sid != ContinueRecord.sid)
                {
                    //Console.WriteLine("creating "+sid);
                    Record[] recs = RecordFactory.CreateRecord(in1);

                    // We know that the multiple record situations
                    //  don't contain continue records, so just
                    //  pass those on to the listener now
                    if (recs.Length > 1)
                    {
                        bonusRecords = new ArrayList(recs.Length - 1);
                        for (int k = 0; k < (recs.Length - 1); k++)
                        {
                            bonusRecords.Add(recs[k]);
                        }
                    }

                    // Regardless of the number we Created, always hold
                    //  onto the last record to be Processed on the next
                    //  loop, in case it has any continue records
                    rec = recs[recs.Length - 1];
                    // Don't return it just yet though, as we probably have
                    //  a record from the last round to return
                }
                else
                {
                    // Normally, ContinueRecords are handled internally
                    // However, in a few cases, there Is a gap between a record at
                    //  its Continue, so we have to handle them specially
                    // This logic Is much like in RecordFactory.CreateRecords()
                    Record[]       recs = RecordFactory.CreateRecord(in1);
                    ContinueRecord crec = (ContinueRecord)recs[0];
                    if ((lastRec is ObjRecord) || (lastRec is TextObjectRecord))
                    {
                        // You can have Obj records between a DrawingRecord
                        //  and its continue!
                        lastDrawingRecord.ProcessContinueRecord(crec.Data);
                        // Trigger them on the drawing record, now it's complete
                        rec = lastDrawingRecord;
                    }
                    else if ((lastRec is DrawingGroupRecord))
                    {
                        ((DrawingGroupRecord)lastRec).ProcessContinueRecord(crec.Data);
                        // Trigger them on the drawing record, now it's complete
                        rec = lastRec;
                    }
                    else
                    {
                        if (rec is UnknownRecord)
                        {
                            ;//silently skip records we don't know about
                        }
                        else
                        {
                            throw new RecordFormatException("Records should handle ContinueRecord internally. Should not see this exception");
                        }
                    }
                }

                // Update our tracking of the last record
                lastRec = rec;
                if (rec is DrawingRecord)
                {
                    lastDrawingRecord = (DrawingRecord)rec;
                }
            }
            else
            {
                // No more records
                hitEOS = true;
            }

            // If we've hit the end-of-stream, then
            //  finish off the last record and be done
            if (hitEOS)
            {
                complete = true;

                // Return the last record if there was
                //  one, otherwise null
                if (rec != null)
                {
                    toReturn = rec;
                    rec      = null;
                }
            }

            return(toReturn);
        }
예제 #11
0
        /**
         * Writes out the additional comment records
         *
         * @param outputFile the output file
         * @exception IOException
         */
        public virtual void writeAdditionalRecords(File outputFile)
        {
            if (origin == Origin.READ)
                {
                outputFile.write(objRecord);

                if (mso != null)
                    outputFile.write(mso);
                outputFile.write(txo);
                outputFile.write(text);
                if (formatting != null)
                    outputFile.write(formatting);
                return;
                }

            // Create the obj record
            ObjRecord objrec = new ObjRecord(objectId,ObjRecord.EXCELNOTE);

            outputFile.write(objrec);

            // Create the mso data record.  Write the text box record again,
            // although it is already included in the SpContainer
            ClientTextBox textBox = new ClientTextBox();
            MsoDrawingRecord msod = new MsoDrawingRecord(textBox.getData());
            outputFile.write(msod);

            TextobjectRecord txorec = new TextobjectRecord(getText());
            outputFile.write(txorec);

            // Data for the first continue record
            byte[] textData = new byte[commentText.Length * 2 + 1];
            textData[0] = 0x1; // unicode indicator
            StringHelper.getUnicodeBytes(commentText,textData,1);
            //StringHelper.getBytes(commentText, textData, 1);
            ContinueRecord textContinue = new ContinueRecord(textData);
            outputFile.write(textContinue);

            // Data for the formatting runs

            byte[] frData = new byte[16];

            // First txo run (the user)
            IntegerHelper.getTwoBytes(0,frData,0); // index to the first character
            IntegerHelper.getTwoBytes(0,frData,2); // index to the font(default)
            // Mandatory last txo run
            IntegerHelper.getTwoBytes(commentText.Length,frData,8);
            IntegerHelper.getTwoBytes(0,frData,10); // index to the font(default)

            ContinueRecord frContinue = new ContinueRecord(frData);
            outputFile.write(frContinue);
        }
예제 #12
0
 /**
  * Sets the text data
  *
  * @param t the text data
  */
 public virtual void setText(ContinueRecord t)
 {
     text = t;
 }
예제 #13
0
 /**
  * Sets the formatting
  *
  * @param t the formatting record
  */
 public virtual void setFormatting(ContinueRecord t)
 {
     formatting = t;
 }
예제 #14
0
 /**
  * Copy constructor used to copy drawings from read to write
  *
  * @param dgo the drawing group object
  * @param dg the drawing group
  * @param ws the workbook settings
  */
 /*protected*/
 public Comment(DrawingGroupObject dgo,
     DrawingGroup dg,
     WorkbookSettings ws)
 {
     Comment d = (Comment)dgo;
     Assert.verify(d.origin == Origin.READ);
     msoDrawingRecord = d.msoDrawingRecord;
     objRecord = d.objRecord;
     initialized = false;
     origin = Origin.READ;
     drawingData = d.drawingData;
     drawingGroup = dg;
     drawingNumber = d.drawingNumber;
     drawingGroup.addDrawing(this);
     mso = d.mso;
     txo = d.txo;
     text = d.text;
     formatting = d.formatting;
     note = d.note;
     width = d.width;
     height = d.height;
     workbookSettings = ws;
 }
예제 #15
0
파일: Workbook.cs 프로젝트: zhoujit/koogra
        private Biff GetCorrectRecord(GenericBiff record, Stream stream, SstRecord sst)
        {
            Biff ret = record;

            switch (record.Id)
            {
            case (ushort)RecordType.Bof:
                BofRecord bof = new BofRecord(record);
                if (bof.Version < 0x0600)
                {
                    throw new Exception("Versions below Excel 97/2000 are currently not supported.");
                }

                ret = bof;
                break;

            case (ushort)RecordType.Boundsheet:
                ret = new BoundSheetRecord(record);
                break;

            case (ushort)RecordType.Index:
                ret = new IndexRecord(record);
                break;

            case (ushort)RecordType.DbCell:
                ret = new DbCellRecord(record);
                break;

            case (ushort)RecordType.Row:
                ret = new RowRecord(record);
                break;

            case (ushort)RecordType.Continue:
                ret = new ContinueRecord(record);
                break;

            case (ushort)RecordType.Blank:
                ret = new BlankRecord(record);
                break;

            case (ushort)RecordType.BoolErr:
                ret = new BoolErrRecord(record);
                break;

            case (ushort)RecordType.Formula:
                ret = new FormulaRecord(record, stream);
                break;

            case (ushort)RecordType.Label:
                ret = new LabelRecord(record);
                break;

            case (ushort)RecordType.LabelSst:
                ret = new LabelSstRecord(record, sst);
                break;

            case (ushort)RecordType.MulBlank:
                ret = new MulBlankRecord(record);
                break;

            case (ushort)RecordType.MulRk:
                ret = new MulRkRecord(record);
                break;

            case (ushort)RecordType.String:
                ret = new StringValueRecord(record);
                break;

            case (ushort)RecordType.Xf:
                ret = new XfRecord(record);
                break;

            case (ushort)RecordType.Rk:
                ret = new RkRecord(record);
                break;

            case (ushort)RecordType.Number:
                ret = new NumberRecord(record);
                break;

            case (ushort)RecordType.Array:
                ret = new ArrayRecord(record);
                break;

            case (ushort)RecordType.ShrFmla:
                ret = new SharedFormulaRecord(record);
                break;

            case (ushort)RecordType.Table:
                ret = new TableRecord(record);
                break;

            case (ushort)RecordType.Sst:
                ret = new SstRecord(record, stream);
                break;

            case (ushort)RecordType.Eof:
                ret = new EofRecord(record);
                break;

            case (ushort)RecordType.Font:
                ret = new FontRecord(record);
                break;

            case (ushort)RecordType.Format:
                ret = new Net.SourceForge.Koogra.Excel.Records.FormatRecord(record);
                break;

            case (ushort)RecordType.Palette:
                ret = new PaletteRecord(record);
                break;

            case (ushort)RecordType.Hyperlink:
                ret = new HyperLinkRecord(record);
                break;
            }

            return(ret);
        }
예제 #16
0
 /**
  * Copy constructor used to copy drawings from read to write
  *
  * @param dgo the drawing group object
  * @param dg the drawing group
  * @param ws the workbook settings
  */
 public Button(DrawingGroupObject dgo,
     DrawingGroup dg,
     WorkbookSettings ws)
 {
     Button d = (Button)dgo;
     Assert.verify(d.origin == Origin.READ);
     msoDrawingRecord = d.msoDrawingRecord;
     objRecord = d.objRecord;
     initialized = false;
     origin = Origin.READ;
     drawingData = d.drawingData;
     drawingGroup = dg;
     drawingNumber = d.drawingNumber;
     drawingGroup.addDrawing(this);
     mso = d.mso;
     txo = d.txo;
     text = d.text;
     formatting = d.formatting;
     workbookSettings = ws;
 }