示例#1
0
        /// <summary>
        /// Retrieves selected shapes or text.
        /// </summary>
        private void SelectShapes()
        {
            try
            {
                PowerPoint.Selection selection = this.GetCurrentSelection();
                if (selection == null)
                {
                    return;
                }

                if (selection.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
                {
                    _selectedShapes = ShapeUtil.GetShapeRange(selection);
                }
                else if (selection.Type == PowerPoint.PpSelectionType.ppSelectionText)
                {
                    _selectedText = selection.TextRange;
                }
                else
                {
                    _selectedShapes = null;
                    _selectedText   = null;
                }
            }
            catch (Exception)
            {
                _selectedShapes = null;
                _selectedText   = null;
            }
        }
        /// <summary>
        /// Colors specified shape with color.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="rgb"></param>
        private void ColorShapeFontWithColor(PowerPoint.Shape s, int rgb)
        {
            if (s.HasTextFrame == MsoTriState.msoTrue)
            {
                PowerPoint.Selection selection = this.GetCurrentSelection();
                if (selection == null)
                {
                    return;
                }

                if (selection.ShapeRange.HasTextFrame == MsoTriState.msoTrue)
                {
                    if (selection.Type == PowerPoint.PpSelectionType.ppSelectionText)
                    {
                        PowerPoint.TextRange selectedText = selection.TextRange.TrimText();
                        if (selectedText.Text != "" && selectedText != null)
                        {
                            selectedText.Font.Color.RGB = rgb;
                        }
                        else
                        {
                            s.TextFrame.TextRange.TrimText().Font.Color.RGB = rgb;
                        }
                    }
                    else if (selection.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
                    {
                        s.TextFrame.TextRange.TrimText().Font.Color.RGB = rgb;
                    }
                }
            }
        }
示例#3
0
 private void WriteToLyricsTextbox(string text, PowerPoint.Shape textBox, int fontSize)
 {
     PowerPoint.TextFrame pptTextFrame = textBox.TextFrame;
     PowerPoint.TextRange pptTextRange = pptTextFrame.TextRange;
     pptTextRange.Text      = text;
     pptTextRange.Font.Size = fontSize;
     pptTextRange.ParagraphFormat.Alignment = PowerPoint.PpParagraphAlignment.ppAlignCenter;
 }
示例#4
0
        private StyleRange Highlight(PowerPoint.TextRange text)
        {
            Normalize(text);
            var style = Highlighter.Parse(text.Text, SelectedLanguage, SelectedTheme);

            ApplyStyle(text, style);
            return(style);
        }
示例#5
0
        private void Simpleanswerbutton_Click(object sender, RibbonControlEventArgs e)
        {
            //Microsoft.Office.Interop.PowerPoint.Slides slides = null;//PPT中所有的幻灯片
            Microsoft.Office.Interop.PowerPoint.Presentation MyPres = Globals.ThisAddIn.Application.ActivePresentation;                                                                    // 当前ppt应用实例
            //slides = Globals.ThisAddIn.Application.ActivePresentation.Slides;//获取当前PPT中的所有幻灯片
            Microsoft.Office.Interop.PowerPoint.Slide MySlide = Globals.ThisAddIn.Application.ActiveWindow.View.Slide;                                                                     //获取当前选中的幻灯片
            Microsoft.Office.Interop.PowerPoint.Slide NewSimpleQuestionSlide = MyPres.Slides.Add(MySlide.SlideIndex + 1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank); //插入新的幻灯片

            #region 插入简答题题目类型
            Microsoft.Office.Interop.PowerPoint.TextRange SATextRng = null;

            NewSimpleQuestionSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 21.5F, 40F, 100F, 30F).Name = "SimpleAnswerQuestion";
            NewSimpleQuestionSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name            = "questionType";
            NewSimpleQuestionSlide.Shapes["questionType"].TextFrame.TextRange.Text = "4";
            NewSimpleQuestionSlide.Shapes["questionType"].Visible = MsoTriState.msoFalse;

            NewSimpleQuestionSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name = "questionScore";
            NewSimpleQuestionSlide.Shapes["questionScore"].TextFrame.TextRange.Text = "0";
            NewSimpleQuestionSlide.Shapes["questionScore"].Visible = MsoTriState.msoFalse;
            NewSimpleQuestionSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name = "questionLimitTime";
            NewSimpleQuestionSlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text = "0";
            NewSimpleQuestionSlide.Shapes["questionLimitTime"].Visible = MsoTriState.msoFalse;
            NewSimpleQuestionSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name = "questionAnswer";
            NewSimpleQuestionSlide.Shapes["questionAnswer"].TextFrame.TextRange.Text = "0";
            NewSimpleQuestionSlide.Shapes["questionAnswer"].Visible = MsoTriState.msoFalse;

            SATextRng = NewSimpleQuestionSlide.Shapes[1].TextFrame.TextRange;                                           //请注意此处Shapes的索引,由于文本框是第一个添加的Shapes,所以此处索引是1。

            SATextRng.Font.NameFarEast          = "微软雅黑";                                                               //文本框中,中文的字体
            SATextRng.Font.NameAscii            = "Calibri";                                                            //文本框中,英文和数字的字体
            SATextRng.Text                      = "简答题";                                                                //显示的内容
            SATextRng.Font.Bold                 = MsoTriState.msoTrue;                                                  //是否加粗
            SATextRng.Font.Color.RGB            = 1 + 1 * 256 + 1 * 256 * 256;                                          //字体颜色,其中ABC直接用自定义颜色中的数字代替即可。
            SATextRng.Font.Size                 = 24;                                                                   //字体大小是24.
            SATextRng.ParagraphFormat.Alignment = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignLeft; //文本对齐方式(水平方向)
            NewSimpleQuestionSlide.Shapes[1].TextFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorMiddle;              //文本对齐方式(垂直方向)
            #endregion

            #region 插入简答题题目
            Microsoft.Office.Interop.PowerPoint.TextRange SQTextRng = null;

            NewSimpleQuestionSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 21.5F, 150F, 777F, 300F).Name = "questionDescribe";
            SQTextRng = NewSimpleQuestionSlide.Shapes["questionDescribe"].TextFrame.TextRange;;                         //请注意此处Shapes的索引,由于文本框是第二个添加的Shapes,所以此处索引是2。

            SQTextRng.Font.NameFarEast          = "微软雅黑";                                                               //文本框中,中文的字体
            SQTextRng.Font.NameAscii            = "Calibri";                                                            //文本框中,英文和数字的字体
            SQTextRng.Text                      = "请编写题干";                                                              //显示的内容
            SQTextRng.Font.Bold                 = MsoTriState.msoFalse;                                                 //是否加粗
            SQTextRng.Font.Color.RGB            = 1 + 1 * 256 + 1 * 256 * 256;                                          //字体颜色,其中ABC直接用自定义颜色中的数字代替即可。
            SQTextRng.Font.Size                 = 24;                                                                   //字体大小是24.
            SQTextRng.ParagraphFormat.Alignment = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignLeft; //文本对齐方式(水平方向)
            NewSimpleQuestionSlide.Shapes[2].TextFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorMiddle;              //文本对齐方式(垂直方向)
            #endregion

            AddSubmitOleForm(NewSimpleQuestionSlide, 822F, 466F, 89F, 46F, EnumExtend.GetDisplayText(ButtonNameEnum.SUMBIT), "sumbitButton"); //插入发布按钮
            AddSubmitOleForm(NewSimpleQuestionSlide, 727F, 466F, 80F, 46F, EnumExtend.GetDisplayText(ButtonNameEnum.GETANS), "answerButton"); //插入答案按钮
            NewSimpleQuestionSlide.Select();
        }
示例#6
0
 private void ColorShapeWithColor(PowerPoint.TextRange text, int rgb, MODE mode)
 {
     PowerPoint.TextFrame frame         = text.Parent as PowerPoint.TextFrame;
     PowerPoint.Shape     selectedShape = frame.Parent as PowerPoint.Shape;
     if (mode != MODE.NONE)
     {
         ColorShapeWithColor(selectedShape, rgb, mode);
     }
 }
示例#7
0
 public void AddText(String text, PowerPoint._Slide slide, float left, float top, float width, float height)
 {
     PowerPoint.Shape     shape   = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, left, top, width, height);
     PowerPoint.TextRange textRng = shape.TextFrame.TextRange;
     textRng.Font.Name = "微软雅黑";
     textRng.Font.Size = 24;
     textRng.Font.Bold = MsoTriState.msoCTrue;
     textRng.Text      = text;
 }
示例#8
0
 /// <summary>
 /// 往正在播放的幻灯片后面插入一个Slide
 /// </summary>
 /// <param name="fileAddress"></正在播放幻灯片的地址>
 /// <param name="fileName"></正在播放幻灯片的名字>
 private void InsertAPage(string fileAddress, string fileName)
 {
     objSlide             = objSlides.Add(CURRENTPAGE + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
     objTextRng           = objSlide.Shapes[1].TextFrame.TextRange;
     objTextRng.Text      = "From " + fileName.Substring(0, fileName.Length - 4);
     objTextRng.Font.Name = "Comic Sans MS";
     objTextRng.Font.Size = 48;
     objSlide.Shapes.AddPicture(@fileAddress, MsoTriState.msoFalse, MsoTriState.msoTrue,
                                150, 150, 500, 350);
 }
示例#9
0
        public void ConveRtf(Ppt.TextRange ppt_range)
        {
            MemoryStream stream = new MemoryStream(/*Encoding.UTF8.GetBytes(rtf)*/);
            //System.Windows.Documents.TextRange text = new System.Windows.Documents.TextRange(ppt_range., );

            //if (stream.Length != 0)
            //	text.Load(stream, DataFormats.Rtf);

            //text.ClearAllProperties();
        }
示例#10
0
        public Generate_PPT(string Title, string text, string FullOutputPath, string[] imageLinks)
        {
            //Initialize variables
            Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Slides      slides;
            Microsoft.Office.Interop.PowerPoint._Slide      slide;
            Microsoft.Office.Interop.PowerPoint.TextRange   objText;

            // Create the Presentation File - msoFalse to hide presentation
            Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoFalse);

            Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

            // Create new Slide
            slides = pptPresentation.Slides;
            slide  = slides.AddSlide(1, customLayout);

            // Add title
            objText           = slide.Shapes[1].TextFrame.TextRange;
            objText.Text      = Title;
            objText.Font.Name = "Arial";
            objText.Font.Size = 32;

            // Add text
            Clipboard.SetData(DataFormats.Rtf, text);
            Microsoft.Office.Interop.PowerPoint.TextFrame tf = slide.Shapes[2].TextFrame;
            Microsoft.Office.Interop.PowerPoint.TextRange tr = tf.TextRange;
            tr.PasteSpecial(PpPasteDataType.ppPasteRTF);

            //Add images
            Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
            int i = 1;

            foreach (string image in imageLinks)
            {
                if (i == 1)
                {
                    slide.Shapes.AddPicture(image, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left + (shape.Width / 2), shape.Top, shape.Width / 2, shape.Height / 2);
                }
                else if (i == 2)
                {
                    slide.Shapes.AddPicture(image, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top + (shape.Height / 2), shape.Width / 2, shape.Height / 2);
                }
                else if (i == 3)
                {
                    slide.Shapes.AddPicture(image, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left + (shape.Width / 2), shape.Top + (shape.Height / 2), shape.Width / 2, shape.Height / 2);
                }
                i++;
            }

            //save PPT and close
            pptPresentation.SaveAs(FullOutputPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
            pptPresentation.Close();
            pptApplication.Quit();
        }
示例#11
0
        public void CreateNewPPT()
        {
            application        = new PowerPoint.Application();
            pptPresentationSet = application.Presentations;
            pptPresentation    = pptPresentationSet.Open(_fileName, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            //customLayout = pptPresentationSet.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
            pptSlides = pptPresentation.Slides;
            pptSlide  = pptSlides.AddSlide(1, customLayout);

            textRng           = pptSlide.Shapes[1].TextFrame.TextRange;
            textRng.Font.Name = textDefaultFontName;
            textRng.Font.Size = textDefaultFontSize;
        }
示例#12
0
 /// <summary>
 /// Add text to the slide, change the font
 /// </summary>
 /// <param name="Text"></param>
 /// <param name="fontName"></param>
 /// <param name="fontSize"></param>
 /// <param name="left"></param>
 /// <param name="top"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 public void AddText(String Text, String fontName, float fontSize, MsoTriState isBold, MsoTriState isItalic, MsoTriState isUnderlined, float left, float top,
                     float width, float height)
 {
     //Add text to the slide, change the font
     objSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, left, top, width, height);
     objTextRng                = objSlide.Shapes[oCount++].TextFrame.TextRange;
     objTextRng.Text           = Text;
     objTextRng.Font.Name      = fontName;
     objTextRng.Font.Size      = fontSize;
     objTextRng.Font.Bold      = isBold;
     objTextRng.Font.Italic    = isItalic;
     objTextRng.Font.Underline = isUnderlined;
 }
示例#13
0
        internal static void DrawTextBox()
        {
            int slideIdx = Globals.ThisAddIn.Application.ActiveWindow.Selection.SlideRange.SlideIndex;

            PowerPoint.Slide     currSlide    = Globals.ThisAddIn.Application.ActivePresentation.Slides[slideIdx];
            PowerPoint.TextRange newTextRange = currSlide.Shapes.AddTextbox(
                Office.MsoTextOrientation.msoTextOrientationHorizontal, 100, 100, 200, 50).TextFrame.TextRange;
            newTextRange.Text = "New TextBox";
            //newTextRange.Text = "";
            newTextRange.Font.Size = 18;
            //newTextRange.Font.Color.RGB = Color.Purple.ToArgb();
            newTextRange.Font.Color.RGB = 9109675;
        }
示例#14
0
        public void setBulletTypeNone(int sldNum, string shpname)
        {
            PowerPoint.TextRange txtRng = ppApp.ActiveWindow.Selection.ShapeRange[1].TextFrame.TextRange;
            //PowerPoint.TextRange txtRng = ActivePPT.Slides[sldNum].Shapes[shpname].TextFrame.TextRange;

            //var paragraphs = txtRng.Paragraphs(-1, -1);

            for (int index = 1; index <= txtRng.Paragraphs().Count; index++)
            {
                txtRng.Paragraphs(index).ParagraphFormat.Bullet.Type = PowerPoint.PpBulletType.ppBulletNone;
                txtRng.Paragraphs(index).IndentLevel = 1;
            }
        }
示例#15
0
 private bool IsHavingUnderLine(PPT.Shape shape)
 {
     PPT.TextRange Textrange = shape.TextFrame.TextRange;
     for (int index = 0; index < Textrange.Text.Count(); index++)
     {
         PPT.TextRange text = Textrange.Find(Textrange.Text[index].ToString(), index);
         if (text.Font.Underline == MsoTriState.msoTrue)
         {
             return(true);
         }
     }
     return(false);
 }
示例#16
0
        private void votebutton_Click(object sender, RibbonControlEventArgs e)
        {
            Presentation MyPres      = Globals.ThisAddIn.Application.ActivePresentation;
            Slide        activeSlide = (Slide)Globals.ThisAddIn.Application.ActiveWindow.View.Slide;

            int   nowIndex  = activeSlide.SlideIndex;
            Slide voteSlide = MyPres.Slides.Add(nowIndex + 1, PpSlideLayout.ppLayoutBlank);

            voteSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 21.5F, 40F, 100F, 30F).Name = "VoteQuestion";
            voteSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name            = "questionType";
            voteSlide.Shapes["questionType"].TextFrame.TextRange.Text = "5";
            voteSlide.Shapes["questionType"].Visible = MsoTriState.msoFalse;
            voteSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name = "questionLimitTime";
            voteSlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text = "0";
            voteSlide.Shapes["questionLimitTime"].Visible = MsoTriState.msoFalse;
            voteSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name = "questionAnswer";
            voteSlide.Shapes["questionAnswer"].TextFrame.TextRange.Text = "A;";
            voteSlide.Shapes["questionAnswer"].Visible = MsoTriState.msoFalse;

            TextRange questionDescribe = null;

            voteSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 91F, 50F, 777F, 60F).Name = "questionDescribe";
            questionDescribe                  = voteSlide.Shapes["questionDescribe"].TextFrame.TextRange;
            questionDescribe.Text             = "此处填写投票内容";
            questionDescribe.Font.NameFarEast = "微软雅黑";
            questionDescribe.Font.NameAscii   = "Calibri";
            questionDescribe.Font.Size        = 24;
            questionDescribe.Font.Bold        = MsoTriState.msoFalse;


            Microsoft.Office.Interop.PowerPoint.TextRange VoteTextRng = null;                                             //设置第一个文本框
            VoteTextRng = voteSlide.Shapes["VoteQuestion"].TextFrame.TextRange;                                           //请注意此处Shapes的索引,由于文本框是第一个添加的Shapes,所以此处索引是1。

            VoteTextRng.Font.NameFarEast          = "微软雅黑";                                                               //文本框中,中文的字体
            VoteTextRng.Font.NameAscii            = "Calibri";                                                            //文本框中,英文和数字的字体
            VoteTextRng.Text                      = "投票";                                                                 //显示的内容
            VoteTextRng.Font.Bold                 = MsoTriState.msoTrue;                                                  //是否加粗
            VoteTextRng.Font.Color.RGB            = 1 + 1 * 256 + 1 * 256 * 256;                                          //字体颜色,其中ABC直接用自定义颜色中的数字代替即可。
            VoteTextRng.Font.Size                 = 24;                                                                   //字体大小是24.
            VoteTextRng.ParagraphFormat.Alignment = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignLeft; //文本对齐方式(水平方向)

            addVoteChoice(voteSlide, "A", 91F, 138F, 152F, 143F);
            addVoteChoice(voteSlide, "B", 91F, 197F, 152F, 203F);
            addVoteChoice(voteSlide, "C", 91F, 257F, 152F, 262F);
            //AddSubmitOleForm(voteSlide, 727F, 466F, 80F, 46F, EnumExtend.GetDisplayText(ButtonNameEnum.GETANS), "answerButton");
            AddSubmitOleForm(voteSlide, 822F, 466F, 80F, 46F, EnumExtend.GetDisplayText(ButtonNameEnum.SUMBIT), "sumbitButton");

            voteSlide.Select();
        }
示例#17
0
            public void Title(string Text, string Name, int Size, int index)
            {
                PPT.CustomLayout customLayout =
                    pptPresentation.SlideMaster.CustomLayouts[PPT.PpSlideLayout.ppLayoutTextAndClipart];

                slide = pptPresentation.Slides.AddSlide(1, customLayout);


                objTex = slide.Shapes[1].TextFrame.TextRange;
                // objTex = pptPresentation.Slides[0].Shapes[1].TextFrame.TextRange;

                objTex.Text = Text;
                //  objTex.Font.Name = "Gulim";
                objTex.Font.Size = Size;
            }
示例#18
0
        private void cxFlatButton1_Click(object sender, EventArgs e)
        {
            //Microsoft.Office.Interop.PowerPoint.Presentation MyPres = null;//ppt实例
            Microsoft.Office.Interop.PowerPoint.Slides AllSlides = null;         //PPT中所有的幻灯片
            Microsoft.Office.Interop.PowerPoint.Slide  MySlide   = null;         //当前幻灯片
            //Microsoft.Office.Interop.PowerPoint.Slide NewSlide = null;//新插入的幻灯片
            AllSlides = Globals.ThisAddIn.Application.ActivePresentation.Slides; //获取当前PPT中的所有幻灯片
            MySlide   = Globals.ThisAddIn.Application.ActiveWindow.View.Slide;   //获取选中幻灯片

            Microsoft.Office.Interop.PowerPoint.TextRange FQTextRng = null;
            Microsoft.Office.Interop.PowerPoint.TextRange score     = null;
            Microsoft.Office.Interop.PowerPoint.TextRange limitime  = null;
            Microsoft.Office.Interop.PowerPoint.TextRange answer    = null;
            FQTextRng = MySlide.Shapes["questionDescribe"].TextFrame.TextRange;
            score     = MySlide.Shapes["questionScore"].TextFrame.TextRange;
            limitime  = MySlide.Shapes["questionLimitTime"].TextFrame.TextRange;
            answer    = MySlide.Shapes["questionAnswer"].TextFrame.TextRange;
            FQTextRng.Font.NameFarEast = "微软雅黑";    //文本框中,中文的字体
            FQTextRng.Font.NameAscii   = "Calibri"; //文本框中,英文和数字的字体

            FQTextRng.Text = JudegeQuestText.Text;  //cxFlatTextArea1.Text;//显示的内容
            score.Text     = scoreBox2.Text;
            limitime.Text  = limitBox1.Text;

            MySlide.Shapes["questionScore"].TextFrame.TextRange.Text     = scoreBox2.Text;
            MySlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text = limitBox1.Text;

            if (cxFlatCheckBox1.Checked == true)
            {
                answer.Text = "True;";
                MySlide.Shapes["questionAnswer"].TextFrame.TextRange.Text = "True;";
            }
            else
            {
                answer.Text = "False;";
                MySlide.Shapes["questionAnswer"].TextFrame.TextRange.Text = "False;";
            }
            System.Diagnostics.Debug.WriteLine(MySlide.Shapes["questionScore"].TextFrame.TextRange.Text + "xixixix");
            System.Diagnostics.Debug.WriteLine(MySlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text + "xixixix");



            FQTextRng.Font.Bold                        = MsoTriState.msoFalse;                                                 //是否加粗
            FQTextRng.Font.Color.RGB                   = 1 + 1 * 256 + 1 * 256 * 256;                                          //字体颜色,其中ABC直接用自定义颜色中的数字代替即可。
            FQTextRng.Font.Size                        = 24;                                                                   //字体大小是24.
            FQTextRng.ParagraphFormat.Alignment        = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignLeft; //文本对齐方式(水平方向)
            MySlide.Shapes[2].TextFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorMiddle;                                    //文本对齐方式(垂直方向)
        }
示例#19
0
 public void InsertText(string textToBeInserted, int textPos)
 {
     if (textToBeInserted != "")
     {
         if (oShapes[textPos] != null)
         {
             PowerPoint.Shape     oShape    = oShapes[textPos];
             PowerPoint.TextFrame oTxtFrame = oShape.TextFrame;
             PowerPoint.TextRange oTxtRange = oTxtFrame.TextRange;
             oTxtRange.Text = textToBeInserted;
         }
         else
         {
             RobotMessageBox.Show("There is no element to add your text to. Have you selected appropriate slide layout?");
         }
     }
 }
示例#20
0
        public void AddOrUpdateTextShape(SlideItemType type, String text, int loopOid, PowerPoint.Shape shape = null)
        {
            PowerPoint.Slide activeSlide = (PowerPoint.Slide)GetActiveSlide();
            if (activeSlide == null)
            {
                return;
            }
            if (shape == null)
            {
                shape = GetActiveShape();
            }
            String value = type == SlideItemType.INCREMENTAL ? text : "" + loopOid;
            bool   added = false;

            if (shape == null)
            {
                shapeShiftPosition += 5F;
                float left = 15F + shapeShiftPosition + 2F;
                float top  = 25F + shapeShiftPosition + 5F;
                shape = activeSlide.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, left, top, 150F, 50F);
                added = true;
            }
            try
            {
                PowerPoint.TextRange range = shape.TextFrame.TextRange;
                range.Text = text;
                if (added && ShapeAdded != null)
                {
                    ShapeAdded(activeSlide.SlideNumber, activeSlide.Name, shape.Id, value, type, text);
                }
                if (!added && ShapeUpdated != null)
                {
                    ShapeUpdated(activeSlide.SlideNumber, activeSlide.Name, shape.Id, value, type, text);
                }
            }
            catch (Exception)  {
                shapeShiftPosition += 5F;
                float left = 15F + shapeShiftPosition + 2F;
                float top  = 25F + shapeShiftPosition + 5F;
                shape = activeSlide.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, left, top, 150F, 50F);
                if (ShapeAdded != null)
                {
                    ShapeAdded(activeSlide.SlideNumber, activeSlide.Name, shape.Id, value, type, text);
                }
            }
        }
示例#21
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);
        }
示例#22
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;
                }
            }
        }
示例#23
0
        public void setBulletImage(int sldNum, string shpname)
        {
            PowerPoint.TextRange txtRng = ppApp.ActiveWindow.Selection.ShapeRange[1].TextFrame.TextRange;
            //PowerPoint.TextRange txtRng = ActivePPT.Slides[sldNum].Shapes[shpname].TextFrame.TextRange;

            //var paragraphs = txtRng.Paragraphs(-1, -1);
            char myCharacter = (char)132;

            for (int index = 1; index <= txtRng.Paragraphs().Count; index++)
            {
                if (txtRng.Paragraphs(index).IndentLevel == 1)
                {
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Character      = myCharacter;
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Color.RGB = System.Drawing.Color.FromArgb(78, 204, 124).ToArgb();
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Size      = (float)10.84;
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Name      = "Wingdings 3";
                    txtRng.Paragraphs(index).Font.Color.RGB = System.Drawing.Color.FromArgb(57, 42, 30).ToArgb();
                    txtRng.Paragraphs(index).Font.Size      = 12;
                    txtRng.Paragraphs(index).Font.Name      = "Corbel";
                }
                else if (txtRng.Paragraphs(index).IndentLevel == 2)
                {
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Character      = 167;
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Color.RGB = System.Drawing.Color.FromArgb(78, 204, 124).ToArgb();
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Size      = (float)11;
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Name      = "Wingdings";
                    txtRng.Paragraphs(index).Font.Color.RGB = System.Drawing.Color.FromArgb(57, 42, 30).ToArgb();
                    txtRng.Paragraphs(index).Font.Size      = 11;
                    txtRng.Paragraphs(index).Font.Name      = "Corbel";
                }
                else if (txtRng.Paragraphs(index).IndentLevel == 3)
                {
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Character      = 2013;
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Color.RGB = System.Drawing.Color.FromArgb(78, 204, 124).ToArgb();
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Size      = (float)11;
                    txtRng.Paragraphs(index).ParagraphFormat.Bullet.Font.Name      = "Corbel";
                    txtRng.Paragraphs(index).Font.Color.RGB = System.Drawing.Color.FromArgb(57, 42, 30).ToArgb();
                    txtRng.Paragraphs(index).Font.Size      = 11;
                    txtRng.Paragraphs(index).Font.Name      = "Corbel";
                }
            }
        }
示例#24
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            PowerPoint.Presentation pres = null;

            //Open the presentation
            pres = Globals.ThisAddIn.Application.Presentations.Open("source.ppt",
                                                                    Microsoft.Office.Core.MsoTriState.msoFalse,
                                                                    Microsoft.Office.Core.MsoTriState.msoFalse,
                                                                    Microsoft.Office.Core.MsoTriState.msoTrue);

            //Access the first slide
            PowerPoint.Slide slide = pres.Slides[1];

            //Access the third shape
            PowerPoint.Shape shp = slide.Shapes[3];

            //Change its text's font to Verdana and height to 32
            PowerPoint.TextRange txtRange = shp.TextFrame.TextRange;
            txtRange.Font.Name = "Verdana";
            txtRange.Font.Size = 32;

            //Bolden it
            txtRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue;

            //Italicize it
            txtRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoCTrue;

            //Change text color
            txtRange.Font.Color.RGB = 0x00CC3333;

            //Change shape background color
            shp.Fill.ForeColor.RGB = 0x00FFCCCC;

            //Reposition it horizontally
            shp.Left -= 70;

            //Write the output to disk
            pres.SaveAs("outVSTO.ppt",
                        PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
                        Microsoft.Office.Core.MsoTriState.msoFalse);
        }
        /// <summary>
        /// Retrieves color of the selected shape.
        /// </summary>
        /// <param name="selectedShape"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        private Color GetSelectedShapeColor(PowerPoint.Shape selectedShape, MODE mode)
        {
            switch (mode)
            {
            case MODE.FILL:
                return(Color.FromArgb(ColorHelper.ReverseRGBToArgb(selectedShape.Fill.ForeColor.RGB)));

            case MODE.LINE:
                return(Color.FromArgb(ColorHelper.ReverseRGBToArgb(selectedShape.Line.ForeColor.RGB)));

            case MODE.FONT:
                if (selectedShape.HasTextFrame == MsoTriState.msoTrue &&
                    this.GetApplication().ActiveWindow.Selection.ShapeRange.HasTextFrame
                    == MsoTriState.msoTrue)
                {
                    if (this.GetCurrentSelection().Type == PowerPoint.PpSelectionType.ppSelectionText)
                    {
                        PowerPoint.TextRange selectedText
                            = this.GetApplication().ActiveWindow.Selection.TextRange.TrimText();
                        if (selectedText != null && selectedText.Text != "")
                        {
                            return(Color.FromArgb(ColorHelper.ReverseRGBToArgb(selectedText.Font.Color.RGB)));
                        }
                        else
                        {
                            return
                                (Color.FromArgb(
                                     ColorHelper.ReverseRGBToArgb(selectedShape.TextFrame.TextRange.Font.Color.RGB)));
                        }
                    }
                    else if (this.GetCurrentSelection().Type == PowerPoint.PpSelectionType.ppSelectionShapes)
                    {
                        return
                            (Color.FromArgb(
                                 ColorHelper.ReverseRGBToArgb(selectedShape.TextFrame.TextRange.Font.Color.RGB)));
                    }
                }
                break;
            }
            return(dataSource.SelectedColor);
        }
示例#26
0
 private void getCharacterStyles(PPT.TextRange str)
 {
     for (int index = 0; index < str.Text.Count(); index++)
     {
         try
         {
             PPT.TextRange text  = str.Find(str.Text[index].ToString(), index);
             float         sz    = text.Font.Size;
             TextStyle     style = new TextStyle();
             style.Size      = sz;
             style.Character = str.Text[index];
             style.Color     = text.Font.Color.RGB;
             style.FontName  = text.Font.Name;
             TextStlyeList.Add(style);
         }
         catch (Exception ex)
         {
             Log("Exception occurred. " + ex.Message);
         }
     }
 }
示例#27
0
        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;
                }
            }
        }
示例#28
0
 /// <summary>
 /// 修改对应页面标题
 /// </summary>
 /// <param name="sindex">页面索引</param>
 /// <param name="word">要设置的标题内容</param>
 /// <returns>设置成功与否</returns>
 public bool ChangeTittle(int sindex, string word)
 {
     if (sindex <= 0)
     {
         return(false);
     }
     if (GoToSlide(sindex))
     {
         try
         {
             if (m_CurSlide.Shapes.Title.Type == MsoShapeType.msoTextBox)
             {
                 POWERPOINT.TextRange myTextRng = m_CurSlide.Shapes.Title.TextFrame.TextRange;
                 myTextRng.Text = word;
                 return(true);
             }
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
     return(false);
 }
        private void createSlide(ArrayList selectedUrls)
        {
            // Create new Slide
            slides = pptPresentation.Slides;
            slide  = slides.AddSlide(slideNumber, customLayout);
            //increment slide number
            slideNumber++;
            // Add title
            objText           = slide.Shapes[1].TextFrame.TextRange;
            objText.Text      = this.MainWindowTitleText.Text;
            objText.Font.Name = "Arial";
            objText.Font.Size = 32;

            System.Windows.Documents.TextRange textRange = new System.Windows.Documents.TextRange(this.MainWindowSlideText.Document.ContentStart, this.MainWindowSlideText.Document.ContentEnd);

            objText      = slide.Shapes[2].TextFrame.TextRange;
            objText.Text = textRange.Text;

            Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
            foreach (string url in selectedUrls)
            {
                slide.Shapes.AddPicture(url, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
            }
        }
        public static void IncludeOthers(string path)
        {
            //Build Slide #2:
            //Add text to the slide title, format the text. Also add a chart to the
            //slide and change the chart type to a 3D pie chart.
            objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
            objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
            objTextRng.Text = "My Chart";
            objTextRng.Font.Name = "Comic Sans MS";
            objTextRng.Font.Size = 48;
            objChart = (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320,
              "MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "",
              MsoTriState.msoFalse).OLEFormat.Object;
            objChart.ChartType = Graph.XlChartType.xl3DPie;
            objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom;
            objChart.HasTitle = true;
            objChart.ChartTitle.Text = "Here it is...";

            //Build Slide #3:
            //Change the background color of this slide only. Add a text effect to the slide
            //and apply various color schemes and shadows to the text effect.
            objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank);
            objSlide.FollowMasterBackground = MsoTriState.msoFalse;
            objShapes = objSlide.Shapes;
            objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27,
              "The End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200);

            //Save the presentation to disk
            objPres.SaveAs(path,
                  PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
                  Microsoft.Office.Core.MsoTriState.msoFalse);
            //Modify the slide show transition settings for all 3 slides in
            //the presentation.
            int[] SlideIdx = new int[3];
            for (int k = 0; k < 3; k++) SlideIdx[k] = k + 1;
            objSldRng = objSlides.Range(SlideIdx);
            objSST = objSldRng.SlideShowTransition;
            objSST.AdvanceOnTime = MsoTriState.msoTrue;
            objSST.AdvanceTime = 3;
            objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut;

            //Prevent Office Assistant from displaying alert messages:
            // bAssistantOn = objApp.Assistant.On;
            // objApp.Assistant.On = false;

            //Run the Slide show from slides 1 thru 3.
            objSSS = objPres.SlideShowSettings;
            objSSS.StartingSlide = 1;
            objSSS.EndingSlide = 3;
            objSSS.Run();

            //Wait for the slide show to end.
            objSSWs = objApp.SlideShowWindows;
            while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);

            ////Reenable Office Assisant, if it was on:
            //if (bAssistantOn)
            //{
            //    objApp.Assistant.On = true;
            //    objApp.Assistant.Visible = false;
            //}

            //Close the presentation without saving changes and quit PowerPoint.
            //  objPres.Close();
            //  objApp.Quit();
        }
 public static void IncludeImage(string path)
 {
     //Build Slide #1:
     //Add text to the slide, change the font and insert/position a
     //picture on the first slide.
     objSlide = objSlides.Add(objSlides.Count+1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
     objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
     objTextRng.Text = "Summary Report";
     objTextRng.Font.Name = "Comic Sans MS";
     objTextRng.Font.Size = 48;
     objSlide.Shapes.AddPicture(path, MsoTriState.msoFalse, MsoTriState.msoTrue,
       0, 50, 700, 450);
 }
示例#32
0
        private void SelectShapes()
        {
            try
            {
                var selection = PowerPointCurrentPresentationInfo.CurrentSelection;
                if (selection == null) return;

                if (selection.Type == PpSelectionType.ppSelectionShapes &&
                    selection.HasChildShapeRange)
                {
                    _selectedShapes = selection.ChildShapeRange;
                }
                else if (selection.Type == PpSelectionType.ppSelectionShapes)
                {
                    _selectedShapes = selection.ShapeRange;
                }
                else if (selection.Type == PpSelectionType.ppSelectionText)
                {
                    _selectedText = selection.TextRange;
                }
                else
                {
                    _selectedShapes = null;
                    _selectedText = null;
                }
            }
            catch (Exception)
            {
                _selectedShapes = null;
                _selectedText = null;
            }
        }
示例#33
0
 //评分核心函数
 public int check_Kernel(List<OfficeElement> ls)
 {
     int points = 0, i;
     int curPart = -1;               //当前正在分析哪一部分的考点
     for (i = 0; i < ls.Count; i++)
     {
         OfficeElement oe = ls[i];
         #region 具体考点对象定位
         if (oe.AttribName == "Root")
             continue;
         if (oe.AttribName == "Presentations")
             continue;
         if (oe.AttribName == "Slide")
         {
             #region 幻灯片定位
             try
             {
                 int slideId = int.Parse(oe.AttribValue);
                 stuSld = stuPpt.Slides[slideId];
                 ansSld = ansPpt.Slides[slideId];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_SLIDE;
             continue;
         }
         if (oe.AttribName == "Background")
         {
             #region 幻灯片背景定位
             try
             {
                 stuBg = stuSld.Background;
                 ansBg = ansSld.Background;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_BACKGROUND;
             continue;
         }
         if (oe.AttribName == "Transition")
         {
             #region 过渡动画定位
             try
             {
                 stuTrans = stuSld.SlideShowTransition;
                 ansTrans = ansSld.SlideShowTransition;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TRANSITION;
             continue;
         }
         if (oe.AttribName == "Effects")
         {
             continue;
         }
         if (oe.AttribName == "Effect")
         {
             #region 幻灯片动画定位
             try
             {
                 int effId = int.Parse(oe.AttribValue);
                 stuEffect = stuSld.TimeLine.MainSequence[effId];
                 ansEffect = ansSld.TimeLine.MainSequence[effId];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_EFFECT;
             continue;
         }
         if (oe.AttribName == "Shape")
         {
             #region Shape定位
             try
             {
                 int shapeId = int.Parse(oe.AttribValue);
                 stuShape = stuSld.Shapes[shapeId];
                 ansShape = ansSld.Shapes[shapeId];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_SHAPE;
             continue;
         }
         if (oe.AttribName == "Location")
         {
             curPart = PART_LOCATION;
             continue;
         }
         if (oe.AttribName == "Picture")
         {
             #region 图片属性定位
             try
             {
                 stuPf = stuShape.PictureFormat;
                 ansPf = ansShape.PictureFormat;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_PICTURE;
             continue;
         }
         if (oe.AttribName == "Run")
         {
             #region 文字部分定位
             try
             {
                 int runId = int.Parse(oe.AttribValue);
                 stuTr = stuShape.TextFrame.TextRange.Runs(0, 100);
                 ansTr = ansShape.TextFrame.TextRange.Runs(0, 100);
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TEXTRANGE;
             continue;
         }
         if (oe.AttribName == "WordArt")
         {
             #region 艺术字定位
             try
             {
                 stuTf = stuShape.TextEffect;
                 ansTf = ansShape.TextEffect;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_WORDART;
             continue;
         }
         if (oe.AttribName == "ThreeD")
         {
             #region 三维属性定位
             try
             {
                 stu3d = stuShape.ThreeD;
                 ans3d = ansShape.ThreeD;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_3D;
             continue;
         }
         if (oe.AttribName == "Animation")
         {
             #region 自定义动画定位
             try
             {
                 stuAm = stuShape.AnimationSettings;
                 ansAm = ansShape.AnimationSettings;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_ANIMATION;
             continue;
         }
         if (oe.AttribName == "ClickAction")
         {
             #region 单击动作定位
             try
             {
                 stuAcs = stuShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick];
                 ansAcs = ansShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_ACTION;
             continue;
         }
         if (oe.AttribName == "MoveAction")
         {
             #region 鼠标移动动作定位
             try
             {
                 stuAcs = stuShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseOver];
                 ansAcs = ansShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseOver];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_ACTION;
             continue;
         }
         #endregion
         #region 幻灯片判分
         if (curPart == PART_SLIDE)
         {
             switch (oe.AttribName)
             {
                 case "SlideName":
                     if (stuSld.Name == ansSld.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "SlideIndex":
                     if (stuSld.SlideIndex == ansSld.SlideIndex)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Layout":
                     if (stuSld.Layout == ansSld.Layout)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片背景判分
         if (curPart == PART_BACKGROUND)
         {
             switch (oe.AttribName)
             {
                 case "Fill":
                     if (stuBg.Fill.Type.Equals(ansBg.Fill.Type))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "GradientType":
                     if (stuBg.Fill.PresetGradientType == ansBg.Fill.PresetGradientType)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "GradientStyle":
                     if (stuBg.Fill.GradientStyle == ansBg.Fill.GradientStyle)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片过渡动画判分
         if (curPart == PART_TRANSITION)
         {
             switch (oe.AttribName)
             {
                 case "AdvanceOnClick":
                     if (stuTrans.AdvanceOnClick.Equals(ansTrans.AdvanceOnClick))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceOnTime":
                     if (stuTrans.AdvanceOnTime.Equals(ansTrans.AdvanceOnTime))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceTime":
                     if (stuTrans.AdvanceTime == ansTrans.AdvanceTime)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "EntryEffect":
                     if (stuTrans.EntryEffect.Equals(ansTrans.EntryEffect))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Speed":
                     if (stuTrans.Speed.Equals(ansTrans.Speed))
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片动画判分
         if (curPart == PART_EFFECT)
         {
             switch (oe.AttribName)
             {
                 case "DisplayName":
                     if (stuEffect.DisplayName == ansEffect.DisplayName)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "EffectType":
                     if (stuEffect.EffectType.Equals(ansEffect.EffectType))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Exit":
                     if (stuEffect.Exit.Equals(ansEffect.Exit))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Index":
                     if (stuEffect.Index == ansEffect.Index)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ShapeName":
                     if (stuEffect.Shape.Name == ansEffect.Shape.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Duration":
                     if (stuEffect.Timing.Duration == ansEffect.Timing.Duration)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Paragraph":
                     try
                     {
                         if (stuEffect.Paragraph == ansEffect.Paragraph)
                             points = int.Parse(oe.AttribValue);
                     }
                     catch { points = 0; }
                     break;
                 case "TextRangeStart":
                     try
                     {
                         if (stuEffect.TextRangeStart == ansEffect.TextRangeStart)
                             points = int.Parse(oe.AttribValue);
                     }
                     catch { points = 0; }
                     break;
                 case "TextRangeLength":
                     try
                     {
                         if (stuEffect.TextRangeLength == ansEffect.TextRangeLength)
                             points = int.Parse(oe.AttribValue);
                     }
                     catch { points = 0; }
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片对象判分
         if (curPart == PART_SHAPE)
         {
             continue;
         }
         #endregion
         #region 对象类型、定位判分
         if (curPart == PART_LOCATION)
         {
             switch (oe.AttribName)
             {
                 case "ShapeName":
                     if (stuShape.Name == ansShape.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Type":
                     if (stuShape.Type == ansShape.Type)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Top":
                     if (stuShape.Top == ansShape.Top)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Left":
                     if (stuShape.Left == ansShape.Left)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Height":
                     if (stuShape.Height == ansShape.Height)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Width":
                     if (stuShape.Width == ansShape.Width)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 图片属性判分
         if (curPart == PART_PICTURE)
         {
             switch (oe.AttribName)
             {
                 case "CropLeft":
                     if (stuPf.CropLeft == ansPf.CropLeft)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CropTop":
                     if (stuPf.CropTop == ansPf.CropTop)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CropRight":
                     if (stuPf.CropRight == ansPf.CropRight)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CropBottom":
                     if (stuPf.CropBottom == ansPf.CropBottom)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 文本属性判分
         if (curPart == PART_TEXTRANGE)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuTr.Text == ansTr.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Bold":
                     if (stuTr.Font.Bold == ansTr.Font.Bold)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Italic":
                     if (stuTr.Font.Italic == ansTr.Font.Italic)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Underline":
                     if (stuTr.Font.Underline == ansTr.Font.Underline)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuTr.Font.Name == ansTr.Font.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuTr.Font.Size == ansTr.Font.Size)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Shadow":
                     if (stuTr.Font.Shadow == ansTr.Font.Shadow)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Superscript":
                     if (stuTr.Font.Superscript == ansTr.Font.Superscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Subscript":
                     if (stuTr.Font.Subscript == ansTr.Font.Subscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ForeColor":
                     if (stuTr.Font.Color.RGB == ansTr.Font.Color.RGB)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 艺术字属性判分
         if (curPart == PART_WORDART)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuTf.Text == ansTf.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Bold":
                     if (stuTf.FontBold == ansTf.FontBold)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Italic":
                     if (stuTf.FontItalic == ansTf.FontItalic)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuTf.FontName == ansTf.FontName)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuTf.FontSize == ansTf.FontSize)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Alignment":
                     if (stuTf.Alignment.ToString() == ansTf.Alignment.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "PresetShape":
                     if (stuTf.PresetShape.ToString() == ansTf.PresetShape.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "RotatedChars":
                     if (stuTf.RotatedChars.ToString() == ansTf.RotatedChars.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Tracking":
                     if (stuTf.Tracking.ToString() == ansTf.Tracking.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 三维属性判分
         if (curPart == PART_3D)
         {
             switch (oe.AttribName)
             {
                 case "ThreeDFormat":
                     if (stu3d.PresetThreeDFormat == ans3d.PresetThreeDFormat)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LightingDirection":
                     if (stu3d.PresetLightingDirection == ans3d.PresetLightingDirection)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LightingSoftness":
                     if (stu3d.PresetLightingSoftness == ans3d.PresetLightingSoftness)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Material":
                     if (stu3d.PresetMaterial == ans3d.PresetMaterial)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Depth":
                     if (stu3d.Depth == ans3d.Depth)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ExtrusionDirection":
                     if (stu3d.PresetExtrusionDirection == ans3d.PresetExtrusionDirection)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 自定义动画判分
         if (curPart == PART_ANIMATION)
         {
             switch (oe.AttribName)
             {
                 case "AnimationOrder":
                     if (stuAm.AnimationOrder == ansAm.AnimationOrder)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "EntryEffect":
                     if (stuAm.EntryEffect == ansAm.EntryEffect)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceMode":
                     if (stuAm.AdvanceMode == ansAm.AdvanceMode)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceTime":
                     if (stuAm.AdvanceTime == ansAm.AdvanceTime)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 对象动作判分
         if (curPart == PART_ACTION)
         {
             switch (oe.AttribName)
             {
                 case "Action":
                     if (stuAcs.Action == ansAcs.Action)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HyperlinkAddr":
                     if (stuAcs.Hyperlink.Address == ansAcs.Hyperlink.Address)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HyperlinkSubAddr":
                     if (stuAcs.Hyperlink.SubAddress == ansAcs.Hyperlink.SubAddress)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
     }
     return points;
 }
        public static void AutomatePowerPoint()
        {
            PowerPoint.Application   oPowerPoint = null;
            PowerPoint.Presentations oPres       = null;
            PowerPoint.Presentation  oPre        = null;
            PowerPoint.Slides        oSlides     = null;
            PowerPoint.Slide         oSlide      = null;
            PowerPoint.Shapes        oShapes     = null;
            PowerPoint.Shape         oShape      = null;
            PowerPoint.TextFrame     oTxtFrame   = null;
            PowerPoint.TextRange     oTxtRange   = null;

            try
            {
                // Create an instance of Microsoft PowerPoint and make it
                // invisible.
                oPowerPoint = new PowerPoint.Application();

                // By default PowerPoint is invisible, till you make it visible.
                // oPowerPoint.Visible = Office.MsoTriState.msoFalse;



                // Create a new Presentation.

                oPres = oPowerPoint.Presentations;
                oPre  = oPres.Add(Office.MsoTriState.msoTrue);
                Console.WriteLine("A new presentation is created");

                // Insert a new Slide and add some text to it.

                Console.WriteLine("Insert a slide");
                oSlides = oPre.Slides;
                oSlide  = oSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutText);

                Console.WriteLine("Add some texts");
                oShapes        = oSlide.Shapes;
                oShape         = oShapes[1];
                oTxtFrame      = oShape.TextFrame;
                oTxtRange      = oTxtFrame.TextRange;
                oTxtRange.Text = "All-In-One Code Framework";

                // Save the presentation as a pptx file and close it.

                Console.WriteLine("Save and close the presentation");

                string fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample1.pptx";
                oPre.SaveAs(fileName,
                            PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,
                            Office.MsoTriState.msoTriStateMixed);
                oPre.Close();

                // Quit the PowerPoint application.

                Console.WriteLine("Quit the PowerPoint application");
                oPowerPoint.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution1.AutomatePowerPoint throws the error: {0}",
                                  ex.Message);
            }
            finally
            {
                // Clean up the unmanaged PowerPoint COM resources by explicitly
                // calling Marshal.FinalReleaseComObject on all accessor objects.
                // See http://support.microsoft.com/kb/317109.

                if (oTxtRange != null)
                {
                    Marshal.FinalReleaseComObject(oTxtRange);
                    oTxtRange = null;
                }
                if (oTxtFrame != null)
                {
                    Marshal.FinalReleaseComObject(oTxtFrame);
                    oTxtFrame = null;
                }
                if (oShape != null)
                {
                    Marshal.FinalReleaseComObject(oShape);
                    oShape = null;
                }
                if (oShapes != null)
                {
                    Marshal.FinalReleaseComObject(oShapes);
                    oShapes = null;
                }
                if (oSlide != null)
                {
                    Marshal.FinalReleaseComObject(oSlide);
                    oSlide = null;
                }
                if (oSlides != null)
                {
                    Marshal.FinalReleaseComObject(oSlides);
                    oSlides = null;
                }
                if (oPre != null)
                {
                    Marshal.FinalReleaseComObject(oPre);
                    oPre = null;
                }
                if (oPres != null)
                {
                    Marshal.FinalReleaseComObject(oPres);
                    oPres = null;
                }
                if (oPowerPoint != null)
                {
                    Marshal.FinalReleaseComObject(oPowerPoint);
                    oPowerPoint = null;
                }
            }
        }
示例#35
0
        public void add_title(ref List<question> questions, ref int question_no)
        {
            if (questions[question_no].show_title == true)
            {
                objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
                objTextRng.Text = questions[question_no].title;
                objTextRng.Font.Name = questions[question_no].title_font.Name;
                objTextRng.Font.Color.RGB = ColorTranslator.ToOle(questions[question_no].Title_color);
                objTextRng.Font.Size = questions[question_no].title_font.Size;
                //if (questions[question_no].title_font.Bold == true)
                //    objTextRng.Font.Bold = MsoTriState.msoTrue;
                //else if (questions[question_no].title_font.Bold == false)
                //    objTextRng.Font.Bold = MsoTriState.msoFalse;

                //if (questions[question_no].title_font.Underline == true)
                //    objTextRng.Font.Underline = MsoTriState.msoTrue;
                //else if (questions[question_no].title_font.Underline == false)
                //    objTextRng.Font.Underline = MsoTriState.msoFalse;
                //if (questions[question_no].title_font.Italic == true)
                //    objTextRng.Font.Italic = MsoTriState.msoTrue;
                //else if (questions[question_no].title_font.Italic == false)
                //    objTextRng.Font.Italic = MsoTriState.msoFalse;

            }
        }
示例#36
0
 /// <summary>
 /// Add text to the slide, change the font
 /// </summary>
 /// <param name="Text"></param>
 /// <param name="fontName"></param>
 /// <param name="fontSize"></param>
 /// <param name="left"></param>
 /// <param name="top"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 public void AddText(String Text, String fontName, float fontSize, MsoTriState isBold, MsoTriState isItalic, MsoTriState isUnderlined, float left, float top,
     float width, float height)
 {
     //Add text to the slide, change the font
     objSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, left, top, width, height);
     objTextRng = objSlide.Shapes[oCount++].TextFrame.TextRange;
     objTextRng.Text = Text;
     objTextRng.Font.Name = fontName;
     objTextRng.Font.Size = fontSize;
     objTextRng.Font.Bold = isBold;
     objTextRng.Font.Italic = isItalic;
     objTextRng.Font.Underline = isUnderlined;
 }
示例#37
0
 /// <summary>
 /// 往正在播放的幻灯片后面插入一个Slide
 /// </summary>
 /// <param name="fileAddress"></正在播放幻灯片的地址>
 /// <param name="fileName"></正在播放幻灯片的名字>
 private void InsertAPage(string fileAddress, string fileName)
 {
     objSlide = objSlides.Add(CURRENTPAGE + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
     objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
     objTextRng.Text = "From " + fileName.Substring(0, fileName.Length - 4);
     objTextRng.Font.Name = "Comic Sans MS";
     objTextRng.Font.Size = 48;
     objSlide.Shapes.AddPicture(@fileAddress, MsoTriState.msoFalse, MsoTriState.msoTrue,
         150, 150, 500, 350);
 }