示例#1
0
        public static void SyncShape(Shape refShape, Shape candidateShape,
                                     bool pickupShapeBasic  = true, bool pickupShapeFormat = true,
                                     bool pickupTextContent = true, bool pickupTextFormat  = true)
        {
            if (pickupShapeBasic)
            {
                SyncShapeRotation(refShape, candidateShape);
                SyncShapeSize(refShape, candidateShape);
                SyncShapeLocation(refShape, candidateShape);
            }


            if (pickupShapeFormat)
            {
                refShape.PickUp();
                candidateShape.Apply();
            }

            if ((pickupTextContent || pickupTextFormat) &&
                refShape.HasTextFrame == MsoTriState.msoTrue &&
                candidateShape.HasTextFrame == MsoTriState.msoTrue)
            {
                TextRange2 refTextRange       = refShape.TextFrame2.TextRange;
                TextRange2 candidateTextRange = candidateShape.TextFrame2.TextRange;

                if (pickupTextContent)
                {
                    candidateTextRange.Text = refTextRange.Text;
                }

                int refParagraphCount       = refShape.TextFrame2.TextRange.Paragraphs.Count;
                int candidateParagraphCount = candidateShape.TextFrame2.TextRange.Paragraphs.Count;

                if (refParagraphCount > 0)
                {
                    string originalText = candidateTextRange.Text;
                    SyncTextRange(refTextRange.Paragraphs[refParagraphCount], candidateTextRange);
                    candidateTextRange.Text = originalText;
                }

                for (int i = 1; i <= candidateParagraphCount; i++)
                {
                    TextRange2 refParagraph       = refTextRange.Paragraphs[i <= refParagraphCount ? i : refParagraphCount];
                    TextRange2 candidateParagraph = candidateTextRange.Paragraphs[i];

                    SyncTextRange(refParagraph, candidateParagraph, pickupTextContent, pickupTextFormat);
                }
            }
        }
示例#2
0
 private void button1_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type != PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         MessageBox.Show("请选中要拆分的文本框");
     }
     else
     {
         PowerPoint.Slide slide = app.ActiveWindow.View.Slide;
         PowerPoint.Shape shape = sel.ShapeRange[1];
         if (shape.HasTextFrame == Office.MsoTriState.msoTrue && shape.TextEffect.Text != "")
         {
             string sp  = textBox1.Text.Trim();
             string txt = shape.TextEffect.Text;
             if (txt.Contains(sp))
             {
                 String[] arr    = txt.Split(char.Parse(sp)).ToArray();
                 int      tcount = arr.Count();
                 shape.PickUp();
                 for (int i = 1; i <= tcount; i++)
                 {
                     PowerPoint.Shape text = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, shape.Left + shape.Width, shape.Top + shape.Height * (i - 1) / tcount, shape.Width, shape.Height);
                     text.TextFrame.TextRange.Text = arr[i - 1].Trim();
                     text.Apply();
                     text.TextFrame.AutoSize = PowerPoint.PpAutoSize.ppAutoSizeShapeToFitText;
                 }
             }
             else
             {
                 MessageBox.Show("找不到指定的分隔符");
             }
         }
         else
         {
             MessageBox.Show("所选文本框中无文字");
         }
     }
 }
示例#3
0
        public static void AddDrillDownAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide,
                                                 out PowerPointDrillDownSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true)
        {
            try
            {
                if (currentSlide == null || currentSlide.Index == PowerPointPresentation.Current.SlideCount)
                {
                    System.Windows.Forms.MessageBox.Show("No next slide is found. Please select the correct slide", "Unable to Add Animations");
                    addedSlide = null;
                    return;
                }

                //Pick up the border and shadow style, to be applied to zoomed shape
                selectedShape.PickUp();
                PrepareZoomShape(currentSlide, ref selectedShape);
                PowerPointSlide nextSlide = GetNextSlide(currentSlide, deletePreviouslyAdded);

                PowerPoint.Shape nextSlidePicture = null, shapeToZoom = null;

                currentSlide.HideIndicator();
                if (ZoomLabSettings.BackgroundZoomChecked)
                {
                    nextSlidePicture = GetNextSlidePictureWithBackground(currentSlide, nextSlide);
                    nextSlidePicture.Apply();
                    PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture);

                    addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide();
                    addedSlide.DeleteAllShapes();

                    nextSlidePicture.Copy();
                    shapeToZoom = addedSlide.Shapes.Paste()[1];
                    addedSlide.DeleteShapeAnimations(shapeToZoom);

                    currentSlide.Copy();
                    var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                    backgroundShape.Apply();
                    ShapeUtil.FitShapeToSlide(ref backgroundShape);
                    backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                    backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                    addedSlide.PrepareForDrillDown();
                    addedSlide.AddDrillDownAnimationBackground(backgroundShape, shapeToZoom, nextSlidePicture);
                }
                else
                {
                    PowerPoint.Shape pictureOnNextSlide = null;
                    nextSlidePicture = GetNextSlidePictureWithoutBackground(currentSlide, nextSlide, out pictureOnNextSlide);
                    nextSlidePicture.Apply();
                    PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture);

                    addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide();
                    addedSlide.DeleteAllShapes();

                    nextSlidePicture.Copy();
                    shapeToZoom = addedSlide.Shapes.Paste()[1];
                    addedSlide.DeleteShapeAnimations(shapeToZoom);

                    currentSlide.Copy();
                    var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                    backgroundShape.Apply();
                    ShapeUtil.FitShapeToSlide(ref backgroundShape);
                    backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                    backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                    addedSlide.PrepareForDrillDown();
                    addedSlide.AddDrillDownAnimationNoBackground(backgroundShape, shapeToZoom, pictureOnNextSlide);
                    pictureOnNextSlide.Delete();
                }
                currentSlide.ShowIndicator();

                Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);
                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                if (includeAckSlide)
                {
                    PowerPointPresentation.Current.AddAckSlide();
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddDrillDownAnimation");
                ErrorDialogBox.ShowDialog("Error when adding drill down animation", "An error occurred when adding drill down animation.", e);
                throw;
            }
        }
示例#4
0
        public static void AddStepBackAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide,
                                                out PowerPointStepBackSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true)
        {
            try
            {
                if (currentSlide == null || currentSlide.Index == 1)
                {
                    System.Windows.Forms.MessageBox.Show("No previous slide is found. Please select the correct slide", "Unable to Add Animations");
                    addedSlide = null;
                    return;
                }

                //Pick up the border and shadow style, to be applied to zoomed shape
                selectedShape.PickUp();
                PrepareZoomShape(currentSlide, ref selectedShape);
                PowerPointSlide previousSlide = GetPreviousSlide(currentSlide, deletePreviouslyAdded);

                PowerPoint.Shape previousSlidePicture = null, shapeToZoom = null;

                currentSlide.HideIndicator();
                if (ZoomLabSettings.BackgroundZoomChecked)
                {
                    previousSlidePicture = GetPreviousSlidePictureWithBackground(currentSlide, previousSlide);
                    previousSlidePicture.Apply();
                    PreparePreviousSlidePicture(selectedShape, ref previousSlidePicture);

                    addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide();
                    addedSlide.DeleteAllShapes();

                    PowerPoint.Shape backgroundShape = null;
                    shapeToZoom = GetStepBackWithBackgroundShapeToZoom(currentSlide, addedSlide, previousSlidePicture, out backgroundShape);
                    shapeToZoom.Apply();

                    addedSlide.PrepareForStepBack();
                    addedSlide.AddStepBackAnimationBackground(shapeToZoom, backgroundShape, previousSlidePicture);
                }
                else
                {
                    addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide();
                    addedSlide.DeleteAllShapes();

                    shapeToZoom = GetStepBackWithoutBackgroundShapeToZoom(addedSlide, previousSlide);
                    shapeToZoom.Apply();
                    shapeToZoom.Copy();
                    previousSlidePicture = currentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                    previousSlidePicture.Apply();
                    PreparePreviousSlidePicture(selectedShape, ref previousSlidePicture);

                    addedSlide.PrepareForStepBack();
                    addedSlide.AddStepBackAnimationNonBackground(shapeToZoom, previousSlidePicture);
                }
                currentSlide.ShowIndicator();

                currentSlide.Transition.EntryEffect = PowerPoint.PpEntryEffect.ppEffectFadeSmoothly;
                currentSlide.Transition.Duration    = 0.25f;
                Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);
                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                if (includeAckSlide)
                {
                    PowerPointPresentation.Current.AddAckSlide();
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddStepBackAnimation");
                ErrorDialogBox.ShowDialog("Error when adding step back animation", "An error occurred when adding step back animation.", e);
                throw;
            }
        }
示例#5
0
        public static void SyncShape(Shape refShape, Shape candidateShape,
                                     bool pickupShapeBasic = true, bool pickupShapeFormat = true,
                                     bool pickupTextContent = true, bool pickupTextFormat = true)
        {
            if (pickupShapeBasic)
            {
                SyncShapeRotation(refShape, candidateShape);
                SyncShapeSize(refShape, candidateShape);
                SyncShapeLocation(refShape, candidateShape);
            }


            if (pickupShapeFormat)
            {
                refShape.PickUp();
                candidateShape.Apply();
            }

            if ((pickupTextContent || pickupTextFormat) &&
                refShape.HasTextFrame == MsoTriState.msoTrue &&
                candidateShape.HasTextFrame == MsoTriState.msoTrue)
            {
                var refTextRange = refShape.TextFrame2.TextRange;
                var candidateTextRange = candidateShape.TextFrame2.TextRange;

                if (pickupTextContent)
                {
                    candidateTextRange.Text = refTextRange.Text;
                }

                var refParagraphCount = refShape.TextFrame2.TextRange.Paragraphs.Count;
                var candidateParagraphCount = candidateShape.TextFrame2.TextRange.Paragraphs.Count;

                if (refParagraphCount > 0)
                {
                    string originalText = candidateTextRange.Text;
                    SyncTextRange(refTextRange.Paragraphs[refParagraphCount], candidateTextRange);
                    candidateTextRange.Text = originalText;
                }

                for (var i = 1; i <= candidateParagraphCount; i++)
                {
                    var refParagraph = refTextRange.Paragraphs[i <= refParagraphCount ? i : refParagraphCount];
                    var candidateParagraph = candidateTextRange.Paragraphs[i];

                    SyncTextRange(refParagraph, candidateParagraph, pickupTextContent, pickupTextFormat);
                }
            }
        }
示例#6
0
        public static void AddDrillDownAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide,
                                                 out PowerPointDrillDownSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true)
        {
            try
            {
                //SlideCount - 1 due to #RestoreClipboardAfterAction creating a temporary slide to store clipboard
                if (currentSlide == null || currentSlide.Index == PowerPointPresentation.Current.SlideCount - 1)
                {
                    System.Windows.Forms.MessageBox.Show(TextCollection.ZoomLabText.ErrorInvalidNextSlide, TextCollection.ZoomLabText.ErrorUnableToAddAnimationsCaption);
                    addedSlide = null;
                    return;
                }

                //Pick up the border and shadow style, to be applied to zoomed shape
                selectedShape.PickUp();
                PrepareZoomShape(currentSlide, ref selectedShape);
                PowerPointSlide nextSlide = GetNextSlide(currentSlide, deletePreviouslyAdded);

                PowerPoint.Shape nextSlidePicture = null, shapeToZoom = null;

                currentSlide.HideIndicator();
                if (ZoomLabSettings.BackgroundZoomChecked)
                {
                    nextSlidePicture = GetNextSlidePictureWithBackground(currentSlide, nextSlide);
                    nextSlidePicture.Apply();
                    PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture);

                    addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide();
                    addedSlide.DeleteAllShapes();

                    shapeToZoom = addedSlide.Shapes.SafeCopyPlaceholder(nextSlidePicture);
                    addedSlide.DeleteShapeAnimations(shapeToZoom);

                    PowerPoint.Shape backgroundShape = GraphicsUtil.AddSlideAsShape(currentSlide, addedSlide);
                    backgroundShape.Apply();
                    ShapeUtil.FitShapeToSlide(ref backgroundShape);
                    backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                    backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                    addedSlide.PrepareForDrillDown();
                    addedSlide.AddDrillDownAnimationBackground(backgroundShape, shapeToZoom, nextSlidePicture);
                }
                else
                {
                    PowerPoint.Shape pictureOnNextSlide = null;
                    nextSlidePicture = GetNextSlidePictureWithoutBackground(currentSlide, nextSlide, out pictureOnNextSlide);
                    nextSlidePicture.Apply();
                    PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture);

                    addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide();
                    addedSlide.DeleteAllShapes();

                    shapeToZoom = addedSlide.Shapes.SafeCopyPlaceholder(nextSlidePicture);
                    addedSlide.DeleteShapeAnimations(shapeToZoom);

                    PowerPoint.Shape backgroundShape = GraphicsUtil.AddSlideAsShape(currentSlide, addedSlide);
                    backgroundShape.Apply();
                    ShapeUtil.FitShapeToSlide(ref backgroundShape);
                    backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                    backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                    addedSlide.PrepareForDrillDown();
                    addedSlide.AddDrillDownAnimationNoBackground(backgroundShape, shapeToZoom, pictureOnNextSlide);
                    pictureOnNextSlide.SafeDelete();
                }
                currentSlide.ShowIndicator();

                Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);
                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                if (includeAckSlide)
                {
                    PowerPointPresentation.Current.AddAckSlide();
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddDrillDownAnimation");
                ErrorDialogBox.ShowDialog("Error when adding drill down animation", "An error occurred when adding drill down animation.", e);
                throw;
            }
        }