Ejemplo n.º 1
0
        /// <summary>
        /// Adds a picture to the workbook.
        /// </summary>
        /// <param name="pictureData">The bytes of the picture</param>
        /// <param name="format">The format of the picture.  One of 
        /// PictureType.</param>
        /// <returns>the index to this picture (1 based).</returns>
        public int AddPicture(byte[] pictureData, Zephyr.Utils.NPOI.SS.UserModel.PictureType format)
        {
            InitDrawings();

            byte[] uid;
            using (MD5 md5 = MD5.Create())
            {
                uid = md5.ComputeHash(pictureData);
            }
            EscherBitmapBlip blipRecord = new EscherBitmapBlip();
            blipRecord.RecordId = (short)(EscherBitmapBlip.RECORD_ID_START + format);
            
            switch (format)
            {
                case Zephyr.Utils.NPOI.SS.UserModel.PictureType.EMF:
                    blipRecord.Options = HSSFPictureData.MSOBI_EMF;
                    break;
                case Zephyr.Utils.NPOI.SS.UserModel.PictureType.WMF:
                    blipRecord.Options = HSSFPictureData.MSOBI_WMF;
                    break;
                case Zephyr.Utils.NPOI.SS.UserModel.PictureType.PICT:
                    blipRecord.Options = HSSFPictureData.MSOBI_PICT;
                    break;
                case Zephyr.Utils.NPOI.SS.UserModel.PictureType.PNG:
                    blipRecord.Options = HSSFPictureData.MSOBI_PNG;
                    break;
                case Zephyr.Utils.NPOI.SS.UserModel.PictureType.JPEG:
                    blipRecord.Options = HSSFPictureData.MSOBI_JPEG;
                    break;
                case Zephyr.Utils.NPOI.SS.UserModel.PictureType.DIB:
                    blipRecord.Options = HSSFPictureData.MSOBI_DIB;
                    break;
            }

            blipRecord.UID = uid;
            blipRecord.Marker = (byte)0xFF;
            blipRecord.PictureData = pictureData;

            EscherBSERecord r = new EscherBSERecord();
            r.RecordId = EscherBSERecord.RECORD_ID;
            r.Options = (short)(0x0002 | ((int)format << 4));
            r.BlipTypeMacOS = (byte)format;
            r.BlipTypeWin32 = (byte)format;
            r.UID = uid;
            r.Tag = (short)0xFF;
            r.Size = pictureData.Length + 25;
            r.Ref = 1;
            r.Offset = 0;
            r.BlipRecord = blipRecord;

            return workbook.AddBSERecord(r);
        }
Ejemplo n.º 2
0
        public int AddBSERecord(EscherBSERecord e)
        {
            CreateDrawingGroup();

            // maybe we don't need that as an instance variable anymore
            escherBSERecords.Add(e);

            int dgLoc = FindFirstRecordLocBySid(DrawingGroupRecord.sid);
            DrawingGroupRecord drawingGroup = (DrawingGroupRecord)Records[dgLoc];

            EscherContainerRecord dggContainer = (EscherContainerRecord)drawingGroup.GetEscherRecord(0);
            EscherContainerRecord bstoreContainer;
            if (dggContainer.GetChild(1).RecordId == EscherContainerRecord.BSTORE_CONTAINER)
            {
                bstoreContainer = (EscherContainerRecord)dggContainer.GetChild(1);
            }
            else
            {
                bstoreContainer = new EscherContainerRecord();
                bstoreContainer.RecordId=EscherContainerRecord.BSTORE_CONTAINER;

                //dggContainer.ChildRecords.Insert(1, bstoreContainer);
                List<EscherRecord> childRecords = dggContainer.ChildRecords;
                childRecords.Insert(1, bstoreContainer);
                dggContainer.ChildRecords = (childRecords);
                
            }
            bstoreContainer.Options=(short)((escherBSERecords.Count << 4) | 0xF);

            bstoreContainer.AddChildRecord(e);

            return escherBSERecords.Count;
        }