Beispiel #1
0
        private static PowerPoint.ShapeRange MakeCopyForShapeRange(PowerPoint.ShapeRange rangeOriginal)
        {
            //Change shape's name in rangeOriginal, so that shape's name in rangeCopy is the same.
            //This is a naming mechanism in office:
            //When shape's name is the default one, its copy's name will be different (e.g. index got changed).
            //When shape's name is not the default one, its copy's name will be the same as the original shape's
            //use Guid here to ensure that name is unique
            var appendString = Guid.NewGuid().ToString() + "temp";

            ModifyNameForShapeRange(rangeOriginal, appendString);

            rangeOriginal.Copy();
            var rangeCopy = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.Paste();

            AdjustSamePositionForShapeRange(rangeOriginal, rangeCopy);

            appendString = "_Copy";
            ModifyNameForShapeRange(rangeCopy, appendString);
            return(rangeCopy);
        }
Beispiel #2
0
        /// <summary>
        /// Copies the shaperange into this slide, without the usual position offset when pasting over an existing shape.
        /// If you are having difficulty getting a shaperange, use the ToShapeRange method.
        /// TODO: Test this method more thoroughly in more cases other than Graphics.SquashSlides
        /// </summary>
        public ShapeRange CopyShapesToSlide(ShapeRange shapes)
        {
            // First Index all the shapes by name, so they can be identified later.
            int index          = 0;
            var originalShapes = new Dictionary <string, Shape>();
            var originalNames  = new Dictionary <string, string>();

            foreach (Shape shape in shapes)
            {
                var tempName = index.ToString();
                index++;

                originalNames.Add(tempName, shape.Name);
                originalShapes.Add(tempName, shape);
                // temporarily set the name before copy, so we can locate it again in the new slide.
                shape.Name = tempName;
            }

            // Copy all the shapes over.
            shapes.Copy();
            var newShapes = _slide.Shapes.Paste();

            // Now use the indexed names to set back the names and positions to the original shapes'
            foreach (Shape shape in newShapes)
            {
                var key           = shape.Name;
                var originalName  = originalNames[key];
                var originalShape = originalShapes[key];

                originalShape.Name = originalName;
                shape.Name         = originalName;
                shape.Left         = originalShape.Left;
                shape.Top          = originalShape.Top;
            }

            return(newShapes);
        }
        /// <summary>
        /// Copies the shaperange into this slide, without the usual position offset when pasting over an existing shape.
        /// If you are having difficulty getting a shaperange, use the ToShapeRange method.
        /// TODO: Test this method more thoroughly in more cases other than Graphics.SquashSlides
        /// </summary>
        public ShapeRange CopyShapesToSlide(ShapeRange shapes)
        {
            // First Index all the shapes by name, so they can be identified later.
            int index = 0;
            var originalShapes = new Dictionary<string, Shape>();
            var originalNames = new Dictionary<string, string>();
            foreach (Shape shape in shapes)
            {
                var tempName = index.ToString();
                index++;

                originalNames.Add(tempName, shape.Name);
                originalShapes.Add(tempName, shape);
                // temporarily set the name before copy, so we can locate it again in the new slide.
                shape.Name = tempName;
            }

            // Copy all the shapes over.
            shapes.Copy();
            var newShapes = _slide.Shapes.Paste();

            // Now use the indexed names to set back the names and positions to the original shapes'
            foreach (Shape shape in newShapes)
            {
                var key = shape.Name;
                var originalName = originalNames[key];
                var originalShape = originalShapes[key];

                originalShape.Name = originalName;
                shape.Name = originalName;
                shape.Left = originalShape.Left;
                shape.Top = originalShape.Top;
            }

            return newShapes;
        }