public void AddWords(string tittle, string[] words)
        {
            POWERPOINT.TextRange myTextRng = null;

            if (m_CurSlide == null)
            {
                AddSlide(POWERPOINT.PpSlideLayout.ppLayoutTitleOnly);
            }
            POWERPOINT.Shape ts = m_CurSlide.Shapes.Title;
            if (ts != null && ts.Type == MsoShapeType.msoTextBox)
            {
                myTextRng = ts.TextFrame.TextRange;
                myTextRng.Font.NameFarEast            = "微软雅黑";
                myTextRng.Font.NameAscii              = "Calibri";
                myTextRng.Text                        = tittle;
                myTextRng.Font.Bold                   = MsoTriState.msoCTrue;
                myTextRng.Font.Color.RGB              = 0 + 0 * 256 + 0 * 256 * 256;
                myTextRng.Characters(1, 30).Font.Size = 48;
                myTextRng.ParagraphFormat.Alignment   = POWERPOINT.PpParagraphAlignment.ppAlignCenter;
                ts.TextFrame.VerticalAnchor           = MsoVerticalAnchor.msoAnchorMiddle;
            }
            for (int i = 0; i < words.Length; ++i)
            {
                POWERPOINT.Shape s = m_CurSlide.Shapes.AddTextbox(OFFICECORE.MsoTextOrientation.msoTextOrientationHorizontal, 20f, 120f + i * 50f, 500f, 50f);
                if (s != null && s.Type == MsoShapeType.msoTextBox)
                {
                    myTextRng = s.TextFrame.TextRange;
                    myTextRng.Font.NameFarEast            = "微软雅黑";
                    myTextRng.Font.NameAscii              = "Calibri";
                    myTextRng.Text                        = words[i];
                    myTextRng.Font.Bold                   = MsoTriState.msoCTrue;
                    myTextRng.Font.Color.RGB              = 100 + 0 * 256 + 0 * 256 * 256;
                    myTextRng.Characters(1, 30).Font.Size = 24;
                    myTextRng.ParagraphFormat.Alignment   = POWERPOINT.PpParagraphAlignment.ppAlignLeft;
                    s.TextFrame.VerticalAnchor            = MsoVerticalAnchor.msoAnchorMiddle;
                }
            }
        }
示例#2
0
        private void Normalize(PowerPoint.TextRange text)
        {
            for (int i = 1; i <= text.Length; ++i)
            {
                var c = text.Characters(i);
                switch (c.Text[0])
                {
                case '“': c.Text = "\""; break;

                case '”': c.Text = "\""; break;

                case '‘': c.Text = "'"; break;

                case '’': c.Text = "'"; break;

                default: break;
                }
            }
        }
示例#3
0
        private static void ApplyStyle(PowerPoint.TextRange selection, StyleRange style)
        {
            var range = selection.Characters(style.Begin + 1, style.Length);

            if (style.Color is Color color)
            {
                range.Font.Color.RGB = color.ToOle();
            }
            if (style.Bold is bool bold)
            {
                range.Font.Bold = bold.ToTryState();
            }
            if (style.Italic is bool italic)
            {
                range.Font.Italic = italic.ToTryState();
            }

            ApplyStyle(selection, style.Children);
        }
示例#4
0
 private void button3_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         for (int j = 1; j <= sel.ShapeRange.Count; j++)
         {
             PowerPoint.Shape txt = sel.ShapeRange[j];
             if (txt.HasTextFrame == Office.MsoTriState.msoFalse || txt.TextFrame2.HasText == Office.MsoTriState.msoFalse)
             {
                 MessageBox.Show("文本框中应包含字符");
             }
             else
             {
                 int cn = txt.TextFrame2.TextRange.Text.Length;
                 if (txt.TextFrame2.TextRange.Text.Contains("\r") || txt.TextFrame2.TextRange.Text.Contains("\v") || txt.TextFrame2.TextRange.Text.Contains("\n"))
                 {
                     String[] arr   = txt.TextFrame2.TextRange.Text.Split(char.Parse("\r"), char.Parse("\v"), char.Parse("\n")).ToArray();
                     int      count = arr.Count();
                     for (int i = 0; i < count; i++)
                     {
                         if (i == 0)
                         {
                             txt.TextFrame2.TextRange.Text = arr[i];
                         }
                         else
                         {
                             txt.TextFrame2.TextRange.Text = txt.TextFrame2.TextRange.Text + arr[i];
                         }
                     }
                 }
                 else
                 {
                     char[] arr = txt.TextFrame2.TextRange.Text.ToCharArray();
                     for (int i = 0; i < cn; i++)
                     {
                         if (i == 0)
                         {
                             txt.TextFrame2.TextRange.Text = arr[i] + Environment.NewLine;
                         }
                         else if (i == cn - 1)
                         {
                             txt.TextFrame2.TextRange.Text = txt.TextFrame2.TextRange.Text + arr[i];
                         }
                         else
                         {
                             txt.TextFrame2.TextRange.Text = txt.TextFrame2.TextRange.Text + arr[i] + Environment.NewLine;
                         }
                     }
                 }
             }
         }
     }
     else if (sel.Type == PowerPoint.PpSelectionType.ppSelectionText)
     {
         PowerPoint.TextRange tr = sel.TextRange;
         if (tr.Text.Contains("\r") || tr.Text.Contains("\n") || tr.Text.Contains("\v"))
         {
             for (int i = tr.Text.Length; i >= 1; i--)
             {
                 if (tr.Characters(i).Text == "\r" || tr.Characters(i).Text == "\n" || tr.Characters(i).Text == "\v")
                 {
                     tr.Characters(i).Delete();
                 }
             }
         }
         else
         {
             for (int i = 1; i <= tr.Text.Length; i += 2)
             {
                 tr.Characters(i).Text = tr.Characters(i).Text + Environment.NewLine;
             }
         }
     }
     else
     {
         MessageBox.Show("请选中要分段的文本框");
     }
 }