예제 #1
0
        protected override EscherContainerRecord CreateSpContainer()
        {
            EscherContainerRecord  spContainer = new EscherContainerRecord();
            EscherSpRecord         sp          = new EscherSpRecord();
            EscherOptRecord        opt         = new EscherOptRecord();
            EscherClientDataRecord clientData  = new EscherClientDataRecord();

            spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer.Options  = ((short)0x000F);
            sp.RecordId          = (EscherSpRecord.RECORD_ID);
            sp.Options           = ((short)((EscherAggregate.ST_HOSTCONTROL << 4) | 0x2));

            sp.Flags     = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
            opt.RecordId = (EscherOptRecord.RECORD_ID);
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 17039620));
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x00080008));
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000));

            HSSFClientAnchor userAnchor = (HSSFClientAnchor)Anchor;

            userAnchor.AnchorType = (AnchorType)(1);
            EscherRecord anchor = userAnchor.GetEscherAnchor();

            clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
            clientData.Options  = ((short)0x0000);

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return(spContainer);
        }
예제 #2
0
        /// <summary>
        /// Creates a new Group record stored Under this patriarch.
        /// </summary>
        /// <param name="anchor">the client anchor describes how this Group is attached
        /// to the sheet.</param>
        /// <returns>the newly created Group.</returns>
        public HSSFShapeGroup CreateGroup(HSSFClientAnchor anchor)
        {
            HSSFShapeGroup group = new HSSFShapeGroup(null, anchor);

            AddShape(group);
            OnCreate(group);
            return(group);
        }
예제 #3
0
        /// <summary>
        /// Creates a simple shape.  This includes such shapes as lines, rectangles,
        /// and ovals.
        /// Note: Microsoft Excel seems to sometimes disallow
        /// higher y1 than y2 or higher x1 than x2 in the anchor, you might need to
        /// reverse them and draw shapes vertically or horizontally flipped!
        /// </summary>
        /// <param name="anchor">the client anchor describes how this Group is attached
        /// to the sheet.</param>
        /// <returns>the newly created shape.</returns>
        public HSSFSimpleShape CreateSimpleShape(HSSFClientAnchor anchor)
        {
            HSSFSimpleShape shape = new HSSFSimpleShape(null, anchor);

            AddShape(shape);
            //open existing file
            OnCreate(shape);
            return(shape);
        }
예제 #4
0
        /// <summary>
        /// Creates a picture.
        /// </summary>
        /// <param name="anchor">the client anchor describes how this Group is attached
        /// to the sheet.</param>
        /// <param name="pictureIndex">Index of the picture.</param>
        /// <returns>the newly created shape.</returns>
        public IPicture CreatePicture(HSSFClientAnchor anchor, int pictureIndex)
        {
            HSSFPicture shape = new HSSFPicture(null, (HSSFClientAnchor)anchor);

            shape.PictureIndex = pictureIndex;
            AddShape(shape);

            //open existing file
            OnCreate(shape);
            return(shape);
        }
예제 #5
0
        /**
         * Resize the image
         * <p>
         * Please note, that this method works correctly only for workbooks
         * with default font size (Arial 10pt for .xls).
         * If the default font is changed the resized image can be streched vertically or horizontally.
         * </p>
         * <p>
         * <code>resize(1.0,1.0)</code> keeps the original size,<br/>
         * <code>resize(0.5,0.5)</code> resize to 50% of the original,<br/>
         * <code>resize(2.0,2.0)</code> resizes to 200% of the original.<br/>
         * <code>resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE})</code> resizes to the dimension of the embedded image.
         * </p>
         *
         * @param scaleX the amount by which the image width is multiplied relative to the original width.
         * @param scaleY the amount by which the image height is multiplied relative to the original height.
         */
        public void Resize(double scaleX, double scaleY)
        {
            HSSFClientAnchor anchor = (HSSFClientAnchor)ClientAnchor;

            anchor.AnchorType = AnchorType.MoveDontResize;

            HSSFClientAnchor pref = GetPreferredSize(scaleX, scaleY) as HSSFClientAnchor;

            int row2 = anchor.Row1 + (pref.Row2 - pref.Row1);
            int col2 = anchor.Col1 + (pref.Col2 - pref.Col1);

            anchor.Col2 = ((short)col2);
            // anchor.setDx1(0);
            anchor.Dx2 = (pref.Dx2);

            anchor.Row2 = (row2);
            // anchor.setDy1(0);
            anchor.Dy2 = (pref.Dy2);
        }
예제 #6
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (obj == this)
            {
                return(true);
            }
            if (obj.GetType() != GetType())
            {
                return(false);
            }
            HSSFClientAnchor anchor = (HSSFClientAnchor)obj;

            return(anchor.Col1 == Col1 && anchor.Col2 == Col2 && anchor.Dx1 == Dx1 &&
                   anchor.Dx2 == Dx2 && anchor.Dy1 == Dy1 && anchor.Dy2 == Dy2 &&
                   anchor.Row1 == Row1 && anchor.Row2 == Row2 && anchor.AnchorType == AnchorType);
        }
예제 #7
0
        public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord)
            : base(spgrContainer, objRecord)
        {
            // read internal and external coordinates from spgrContainer
            EscherContainerRecord spContainer = spgrContainer.ChildContainers[0];

            _spgrRecord = (EscherSpgrRecord)spContainer.GetChild(0);
            foreach (EscherRecord ch in spContainer.ChildRecords)
            {
                switch (ch.RecordId)
                {
                case EscherSpgrRecord.RECORD_ID:
                    break;

                case EscherClientAnchorRecord.RECORD_ID:
                    anchor = new HSSFClientAnchor((EscherClientAnchorRecord)ch);
                    break;

                case EscherChildAnchorRecord.RECORD_ID:
                    anchor = new HSSFChildAnchor((EscherChildAnchorRecord)ch);
                    break;
                }
            }
        }
예제 #8
0
        /**
         * Adds a new OLE Package Shape
         *
         * @param anchor       the client anchor describes how this picture is
         *                     attached to the sheet.
         * @param storageId    the storageId returned by {@Link HSSFWorkbook.AddOlePackage}
         * @param pictureIndex the index of the picture (used as preview image) in the
         *                     workbook collection of pictures.
         *
         * @return newly Created shape
         */

        public HSSFObjectData CreateObjectData(HSSFClientAnchor anchor, int storageId, int pictureIndex)
        {
            ObjRecord obj = new ObjRecord();

            CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord();

            ftCmo.ObjectType = (/*setter*/ CommonObjectType.Picture);
            // ftCmo.ObjectId=(/*setter*/oleShape.ShapeId); ... will be Set by onCreate(...)
            ftCmo.IsLocked    = (/*setter*/ true);
            ftCmo.IsPrintable = (/*setter*/ true);
            ftCmo.IsAutoFill  = (/*setter*/ true);
            ftCmo.IsAutoline  = (/*setter*/ true);
            ftCmo.Reserved1   = (/*setter*/ 0);
            ftCmo.Reserved2   = (/*setter*/ 0);
            ftCmo.Reserved3   = (/*setter*/ 0);
            obj.AddSubRecord(ftCmo);

            // FtCf (pictFormat)
            FtCfSubRecord   ftCf     = new FtCfSubRecord();
            HSSFPictureData pictData = Sheet.Workbook.GetAllPictures()[(pictureIndex - 1)] as HSSFPictureData;

            switch ((PictureType)pictData.Format)
            {
            case PictureType.WMF:
            case PictureType.EMF:
                // this needs patch #49658 to be applied to actually work
                ftCf.Flags = (/*setter*/ FtCfSubRecord.METAFILE_BIT);
                break;

            case PictureType.DIB:
            case PictureType.PNG:
            case PictureType.JPEG:
            case PictureType.PICT:
                ftCf.Flags = (/*setter*/ FtCfSubRecord.BITMAP_BIT);
                break;
            }
            obj.AddSubRecord(ftCf);
            // FtPioGrbit (pictFlags)
            FtPioGrbitSubRecord ftPioGrbit = new FtPioGrbitSubRecord();

            ftPioGrbit.SetFlagByBit(FtPioGrbitSubRecord.AUTO_PICT_BIT, true);
            obj.AddSubRecord(ftPioGrbit);

            EmbeddedObjectRefSubRecord ftPictFmla = new EmbeddedObjectRefSubRecord();

            ftPictFmla.SetUnknownFormulaData(new byte[] { 2, 0, 0, 0, 0 });
            ftPictFmla.OLEClassName = (/*setter*/ "Paket");
            ftPictFmla.SetStorageId(storageId);

            obj.AddSubRecord(ftPictFmla);
            obj.AddSubRecord(new EndSubRecord());

            string         entryName = "MBD" + HexDump.ToHex(storageId);
            DirectoryEntry oleRoot;

            try
            {
                DirectoryNode dn = (_sheet.Workbook as HSSFWorkbook).RootDirectory;
                if (dn == null)
                {
                    throw new FileNotFoundException();
                }
                oleRoot = (DirectoryEntry)dn.GetEntry(entryName);
            }
            catch (FileNotFoundException e)
            {
                throw new InvalidOperationException("trying to add ole shape without actually Adding data first - use HSSFWorkbook.AddOlePackage first", e);
            }

            // create picture shape, which need to be minimal modified for oleshapes
            HSSFPicture shape = new HSSFPicture(null, anchor);

            shape.PictureIndex = (/*setter*/ pictureIndex);
            EscherContainerRecord spContainer = shape.GetEscherContainer();
            EscherSpRecord        spRecord    = spContainer.GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord;

            spRecord.Flags = (/*setter*/ spRecord.Flags | EscherSpRecord.FLAG_OLESHAPE);

            HSSFObjectData oleShape = new HSSFObjectData(spContainer, obj, oleRoot);

            AddShape(oleShape);
            OnCreate(oleShape);

            return(oleShape);
        }