Exemplo n.º 1
0
        /// <summary>
        /// Creates the low-level records for a comment.
        /// </summary>
        /// <param name="hssfShape">The highlevel shape.</param>
        /// <param name="shapeId">The shape id to use for this shape.</param>
        public CommentShape(HSSFComment hssfShape, int shapeId)
            : base(hssfShape, shapeId)
        {


            note = CreateNoteRecord(hssfShape, shapeId);

            ObjRecord obj = ObjRecord;
            List<SubRecord> records = obj.SubRecords;
            int cmoIdx = 0;
            for (int i = 0; i < records.Count; i++)
            {
                Object r = records[i];

                if (r is CommonObjectDataSubRecord)
                {
                    //modify autoFill attribute inherited from <c>TextObjectRecord</c>
                    CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)r;
                    cmo.IsAutoFill=(false);
                    cmoIdx = i;
                }
            }
            //Add NoteStructure sub record
            //we don't know it's format, for now the record data Is empty
            NoteStructureSubRecord u = new NoteStructureSubRecord();
            obj.AddSubRecord(cmoIdx + 1, u);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates the low level NoteRecord
 /// which holds the comment attributes.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="shapeId">The shape id.</param>
 /// <returns></returns>
 private NoteRecord CreateNoteRecord(HSSFComment shape, int shapeId)
 {
     NoteRecord note = new NoteRecord();
     note.Column = shape.Column;
     note.Row = shape.Row;
     note.Flags = (shape.Visible ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
     note.ShapeId = shapeId;
     note.Author = (shape.Author == null ? "" : shape.Author);
     return note;
 }
Exemplo n.º 3
0
        public override Object Clone()
        {
            NoteRecord rec = new NoteRecord();

            rec.field_1_row     = field_1_row;
            rec.field_2_col     = field_2_col;
            rec.field_3_flags   = field_3_flags;
            rec.field_4_shapeid = field_4_shapeid;
            rec.field_6_author  = field_6_author;
            return(rec);
        }
Exemplo n.º 4
0
        public void TestWrite()
        {
            NoteRecord record = new NoteRecord();
            Assert.AreEqual(NoteRecord.sid, record.Sid);

            record.Row = ((short)6);
            record.Column = ((short)1);
            record.Flags = (NoteRecord.NOTE_VISIBLE);
            record.ShapeId = ((short)1026);
            record.Author = ("Apache Software Foundation");

            byte[] ser = record.Serialize();
            TestcaseRecordInputStream.ConfirmRecordEncoding(NoteRecord.sid, testData, ser);
        }
Exemplo n.º 5
0
        public void TestRead()
        {

            NoteRecord record = new NoteRecord(TestcaseRecordInputStream.Create(NoteRecord.sid, testData));

            Assert.AreEqual(NoteRecord.sid, record.Sid);

            Assert.AreEqual(6, record.Row);
            Assert.AreEqual(1, record.Column);
            Assert.AreEqual(NoteRecord.NOTE_VISIBLE, record.Flags);
            Assert.AreEqual(1026, record.ShapeId);
            Assert.AreEqual("Apache Software Foundation", record.Author);

        }
Exemplo n.º 6
0
        /// <summary>
        /// Construct a new comment with the given parent and anchor.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="anchor">defines position of this anchor in the sheet</param>
        public HSSFComment(HSSFShape parent, HSSFAnchor anchor)
            : base(parent, anchor)
        {
            _note = CreateNoteRecord();

            //default color for comments
            this.FillColor = 0x08000050;

            //by default comments are hidden
            Visible = false;

            Author = "";
            CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord)GetObjRecord().SubRecords[0];
            cod.ObjectType = CommonObjectType.COMMENT; 
        }
Exemplo n.º 7
0
        public void TestClone()
        {
            NoteRecord record = new NoteRecord();

            record.Row = ((short)1);
            record.Column = ((short)2);
            record.Flags = (NoteRecord.NOTE_VISIBLE);
            record.ShapeId = ((short)1026);
            record.Author = ("Apache Software Foundation");

            NoteRecord cloned = (NoteRecord)record.Clone();
            Assert.AreEqual(record.Row, cloned.Row);
            Assert.AreEqual(record.Column, cloned.Column);
            Assert.AreEqual(record.Flags, cloned.Flags);
            Assert.AreEqual(record.ShapeId, cloned.ShapeId);
            Assert.AreEqual(record.Author, cloned.Author);

            //finally check that the Serialized data is1 the same
            byte[] src = record.Serialize();
            byte[] cln = cloned.Serialize();
            Assert.IsTrue(NPOI.Util.Arrays.Equals(src, cln));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HSSFComment"/> class.
 /// </summary>
 /// <param name="note">The note.</param>
 /// <param name="txo">The txo.</param>
 public HSSFComment(NoteRecord note, TextObjectRecord txo)
     : this((HSSFShape)null, new HSSFClientAnchor())
 {
     this._note = note;
 }
Exemplo n.º 9
0
        //private TextObjectRecord txo = null;
        public HSSFComment(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord, NoteRecord _note)
            : base(spContainer, objRecord, textObjectRecord)
        {

            this._note = _note;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HSSFComment"/> class.
 /// </summary>
 /// <param name="note">The note.</param>
 /// <param name="txo">The txo.</param>
 public HSSFComment(NoteRecord note, TextObjectRecord txo)
     : this((HSSFShape)null, (HSSFAnchor)null)
 {
     this.txo = txo;
     this.note = note;
 }
Exemplo n.º 11
0
 public override Object Clone()
 {
     NoteRecord rec = new NoteRecord();
     rec.field_1_row = field_1_row;
     rec.field_2_col = field_2_col;
     rec.field_3_flags = field_3_flags;
     rec.field_4_shapeid = field_4_shapeid;
     rec.field_5_author = field_5_author;
     return rec;
 }
Exemplo n.º 12
0
 internal void AddTailRecord(NoteRecord note)
 {
     if (tailRec.ContainsKey(note.ShapeId))
         tailRec.Add(note.ShapeId, note);
     else
         tailRec[note.ShapeId] = note;
 }
Exemplo n.º 13
0
 public void RemoveTailRecord(NoteRecord note)
 {
     tailRec.Remove(note.ShapeId);
 }
Exemplo n.º 14
0
        /**
 * Get the {@link NoteRecord}s (related to cell comments) for this sheet
 * @return never <code>null</code>, typically empty array
 */
        public NoteRecord[] GetNoteRecords()
        {
            List<NoteRecord> temp = new List<NoteRecord>();
            for (int i = records.Count - 1; i >= 0; i--)
            {
                RecordBase rec = records[i];
                if (rec is NoteRecord)
                {
                    temp.Add((NoteRecord)rec);
                }
            }
            if (temp.Count < 1)
            {
                return NoteRecord.EMPTY_ARRAY;
            }
            NoteRecord[] result = new NoteRecord[temp.Count];
            result = temp.ToArray();
            return result;
        }
Exemplo n.º 15
0
        public void TestUnicodeAuthor()
        {
            // This sample data was created by setting the 'user name' field in the 'Personalize' 
            // section of Excel's options to \u30A2\u30D1\u30C3\u30C1\u65CF, and then 
            // creating a cell comment.
            byte[] data = HexRead.ReadFromString("01 00 01 00 00 00 03 00 " +
                    "05 00 01 " + // len=5, 16bit
                    "A2 30 D1 30 C3 30 C1 30 CF 65 " + // character data 
                    "00 " // padding byte
                    );
            RecordInputStream in1 = TestcaseRecordInputStream.Create(NoteRecord.sid, data);
            NoteRecord nr = new NoteRecord(in1);
            if ("\u00A2\u0030\u00D1\u0030\u00C3".Equals(nr.Author))
            {
                throw new AssertionException("Identified bug in reading note with unicode author");
            }
            Assert.AreEqual("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.Author);
            Assert.IsTrue(nr.AuthorIsMultibyte);

            byte[] ser = nr.Serialize();
            TestcaseRecordInputStream.ConfirmRecordEncoding(NoteRecord.sid, data, ser);

            // Re-check
            in1 = TestcaseRecordInputStream.Create(ser);
            nr = new NoteRecord(in1);
            Assert.AreEqual("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.Author);
            Assert.IsTrue(nr.AuthorIsMultibyte);


            // Change to a non unicode author, will stop being unicode
            nr.Author = ("Simple");
            ser = nr.Serialize();
            in1 = TestcaseRecordInputStream.Create(ser);
            nr = new NoteRecord(in1);

            Assert.AreEqual("Simple", nr.Author);
            Assert.IsFalse(nr.AuthorIsMultibyte);

            // Now set it back again
            nr.Author = ("Unicode\u1234");
            ser = nr.Serialize();
            in1 = TestcaseRecordInputStream.Create(ser);
            nr = new NoteRecord(in1);

            Assert.AreEqual("Unicode\u1234", nr.Author);
            Assert.IsTrue(nr.AuthorIsMultibyte);
        }
Exemplo n.º 16
0
        public void TestCreateAggregate()
        {
            String msoDrawingRecord1 =
                    "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" +
                    "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" +
                    "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 \n" +
                    "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n" +
                    "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 \n" +
                    "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 \n" +
                    "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 \n" +
                    "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 \n" +
                    "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 \n" +
                    "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 \n" +
                    "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 \n" +
                    "05 00 94 00 00 00 11 F0 00 00 00 00";

            String msoDrawingRecord2 =
                    "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " +
                    "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " +
                    "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " +
                    "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " +
                    "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " +
                    "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " +
                    "0B 00 0C 00 00 00 11 F0 00 00 00 00";

            DrawingRecord d1 = new DrawingRecord();
            d1.Data = HexRead.ReadFromString(msoDrawingRecord1);

            ObjRecord r1 = new ObjRecord();

            DrawingRecord d2 = new DrawingRecord();
            d2.Data = (HexRead.ReadFromString(msoDrawingRecord2));

            TextObjectRecord r2 = new TextObjectRecord();
            r2.Str = (new HSSFRichTextString("Aggregated"));
            NoteRecord n2 = new NoteRecord();

            List<RecordBase> recordStream = new List<RecordBase>();
            recordStream.Add(InternalSheet.CreateBOF());
            recordStream.Add(d1);
            recordStream.Add(r1);
            recordStream.Add(CreateWindow2Record());
            recordStream.Add(EOFRecord.instance);

            ConfirmAggregatedRecords(recordStream);


            recordStream = new List<RecordBase>();
            recordStream.Add(InternalSheet.CreateBOF());
            recordStream.Add(d1);
            recordStream.Add(r1);
            recordStream.Add(d2);
            recordStream.Add(r2);
            recordStream.Add(CreateWindow2Record());
            recordStream.Add(EOFRecord.instance);

            ConfirmAggregatedRecords(recordStream);

            recordStream = new List<RecordBase>();
            recordStream.Add(InternalSheet.CreateBOF());
            recordStream.Add(d1);
            recordStream.Add(r1);
            recordStream.Add(d2);
            recordStream.Add(r2);
            recordStream.Add(n2);
            recordStream.Add(CreateWindow2Record());
            recordStream.Add(EOFRecord.instance);

            ConfirmAggregatedRecords(recordStream);
        }
Exemplo n.º 17
0
 private NoteRecord CreateNoteRecord()
 {
     NoteRecord note = new NoteRecord();
     note.Flags = (NoteRecord.NOTE_HIDDEN);
     note.Author = ("");
     return note;
 }