Esempio n. 1
0
        public void CreateSlide(string slideTitle, string slideBody)
        {
            if (slideBody.Contains("\r\n\r\n") || String.IsNullOrEmpty(slideBody) || slideBody == "\r\n")
            {
                return;
            }
            float slideWidth       = m_pptPres.PageSetup.SlideWidth;
            float lyricsShapeWidth = 900;
            float lyricsShapeLeft  = slideWidth * 0.5f - lyricsShapeWidth * 0.5f;
            int   textBoxHeight    = 0;

            PowerPoint.Slide pptSlide = m_pptSlides.Add(m_pptSlides.Count + 1,
                                                        PowerPoint.PpSlideLayout.ppLayoutBlank);
            PowerPoint.Shapes pptShapes = pptSlide.Shapes;

            pptShapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal,
                                 /*left*/ 50, /*top*/ 50, /*width*/ 700, /*height*/ textBoxHeight);

            PowerPoint.Shape titleTextbox = pptShapes[1];
            WriteToTextbox(slideTitle, titleTextbox, 50);

            pptShapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal,
                                 lyricsShapeLeft, 150, lyricsShapeWidth, textBoxHeight);

            PowerPoint.Shape lyricsTextbox = pptShapes[2];
            WriteToLyricsTextbox(slideBody, lyricsTextbox, 35);
        }
Esempio n. 2
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);
 }
Esempio n. 3
0
        public List <IFileItem> AppendShapes(List <PPT.Shape> srcShapes)
        {
            PPT.Application   ppt             = null;
            PPT.Presentations pres            = null;
            PPT.Presentation  pptPresentation = null;
            try
            {
                ppt  = new PPT.Application();
                pres = ppt.Presentations;

                pptPresentation = pres.Open(FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);

                PPT.DocumentWindow wnd = pptPresentation.Windows[1];
                //wnd.Height = 200;
                //wnd.Top = -200;
                wnd.WindowState = PPT.PpWindowState.ppWindowMinimized;
                wnd             = null;

                PPT.Slides gSlides    = pptPresentation.Slides;
                int        startIndex = gSlides.Count + 1;
                int        count      = 0;
                foreach (PPT.Shape shape in srcShapes)
                {
                    PPT.Slide slide = gSlides.Add(startIndex + count++, PPT.PpSlideLayout.ppLayoutBlank);
                    shape.Copy();
                    slide.Shapes.Paste();
                    slide.Tags.Add(ShapeTag.Tag, ShapeTag.Value);

                    slide.ReleaseCOM();
                    slide = null;
                }
                List <IFileItem> newItems = new List <IFileItem>();
                newItems = fileIndex.UpdateIndex(pptPresentation, startIndex);

                return(newItems);
            }
            finally
            {
                if (pptPresentation != null)
                {
                    pptPresentation.Save();
                    pptPresentation.Close();
                }
                pptPresentation.ReleaseCOM();
                pptPresentation = null;

                pres.ReleaseCOM();
                pres = null;

                ppt.ReleaseCOM();
                ppt = null;
            }
        }
        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;
                }
            }
        }
Esempio n. 5
0
        private void Judgquesbtn_Click(object sender, RibbonControlEventArgs e)
        {
            //if (Globals.ThisAddIn._JudgeTaskPane != null)
            //{
            //    Globals.ThisAddIn._JudgeTaskPane.Visible = true;
            //}
            //SetQuestForm setQuestForm = new SetQuestForm();
            //setQuestForm.Show();
            //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;   //获取选中幻灯片

            #region 插入判断题 题目类型
            NewSlide = AllSlides.Add(MySlide.SlideIndex + 1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank); //插入幻灯片

            Microsoft.Office.Interop.PowerPoint.TextRange FillTextRng = null;                                                  //设置第一个文本框
            NewSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 21.5F, 40F, 100F, 30F).Name = "JudgeQuestion";
            NewSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 0, 0, 0, 0).Name            = "questionType";
            NewSlide.Shapes["questionType"].TextFrame.TextRange.Text = "2";
            NewSlide.Shapes["questionType"].Visible = MsoTriState.msoFalse;



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


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

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

            NewSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 21.5F, 150F, 400F, 300F).Name = "questionDescribe";

            //添加True & False图片 从网上获取
            NewSlide.Shapes.AddPicture("http://pic.616pic.com/ys_b_img/00/57/95/CLa3kvD1Kw.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 21, 400, 70, 50).Name  = "answerisTrue";
            NewSlide.Shapes.AddPicture("http://pic.616pic.com/ys_b_img/00/11/88/mktrxpmh8r.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 200, 400, 70, 50).Name = "answerisFalse";
            NewSlide.Shapes["answerisTrue"].Visible  = MsoTriState.msoTrue;
            NewSlide.Shapes["answerisFalse"].Visible = MsoTriState.msoTrue;
            FQTextRng = NewSlide.Shapes["questionDescribe"].TextFrame.TextRange;                                                //请注意此处Shapes的索引,由于文本框是第二个添加的Shapes,所以此处索引是2。

            FQTextRng.Font.NameFarEast                  = "微软雅黑";                                                               //文本框中,中文的字体
            FQTextRng.Font.NameAscii                    = "Calibri";                                                            //文本框中,英文和数字的字体
            FQTextRng.Text                              = "请编写题干";                                                              //cxFlatTextArea1.Text;//显示的内容
            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; //文本对齐方式(水平方向)
            NewSlide.Shapes[2].TextFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorMiddle;                                    //文本对齐方式(垂直方向)
            #endregion
            #region 添加对错按钮
            //AddOleForm1(NewSlide, 21.5F, 400F, 70F, 50F, "True", 1);
            //AddOleForm1(NewSlide, 200F, 400F, 70F, 50F, "False", 2);

            //Image image1 = Properties.Resources.Oke_true;
            //Image image2 = Properties.Resources.Oke_false;
            //String image_path1 = Application.StartupPath + @"..\\..\\Resources\\Oke_true.png";
            //String image_path2 = @"..\\..\\Resources\\Oke_false.png";
            //MySlide.Shapes.AddPicture(image_path1, MsoTriState.msoFalse, MsoTriState.msoTrue, 27F, 24F, 665F, 333F);

            //presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
            //AddSubmitOleForm1(NewSlide, 822F, 466F, 89F, 46F);
            AddSubmitOleForm(NewSlide, 727F, 466F, 80F, 46F, EnumExtend.GetDisplayText(ButtonNameEnum.GETANS), "answerButton");
            AddSubmitOleForm(NewSlide, 822F, 466F, 80F, 46F, EnumExtend.GetDisplayText(ButtonNameEnum.SUMBIT), "sumbitButton");

            #endregion
        }
Esempio n. 6
0
        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
            {
                // 创建一个Microsoft PowerPoint实例并使其不可见。

                oPowerPoint = new PowerPoint.Application();

                // 默认情况下PowerPoint不可见,直道你使它可见。
                //oPowerPoint.Visible = Office.MsoTriState.msoFalse;

                // 创建一个新的演示文稿。

                oPres = oPowerPoint.Presentations;
                oPre  = oPres.Add(Office.MsoTriState.msoTrue);
                Console.WriteLine("一个新的演示文稿被建立");

                // 插入一个幻灯片,并为幻灯片加入一些文本。

                Console.WriteLine("插入一个幻灯片");
                oSlides = oPre.Slides;
                oSlide  = oSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutText);

                Console.WriteLine("添加一些文本");
                oShapes        = oSlide.Shapes;
                oShape         = oShapes[1];
                oTxtFrame      = oShape.TextFrame;
                oTxtRange      = oTxtFrame.TextRange;
                oTxtRange.Text = "一站式代码框架";

                // 保存此演示文稿为pptx文件并将其关闭。

                Console.WriteLine("保存并退出演示文稿");

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

                // 退出PowerPoint应用程序

                Console.WriteLine("退出PowerPoint应用程序");
                oPowerPoint.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("解决方案1.AutomatePowerPoint抛出的错误: {0}",
                                  ex.Message);
            }
            finally
            {
                // 显式地调用Marshal.FinalReleaseComObject访问所有的存取器对象清除
                // 非托管的COM资源。
                // 参见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;
                }
            }
        }
Esempio n. 7
0
 public _Slide AddNewSlide()
 {
     return(pptSlides.Add(pptSlides.Count, PowerPoint.PpSlideLayout.ppLayoutTitleOnly));
 }
Esempio n. 8
0
 /// <summary>
 /// Adds a new slide to presentation.
 /// </summary>
 public void AddSlide()
 {
     oCount   = 1;
     objSlide = objSlides.Add(sCount++, PowerPoint.PpSlideLayout.ppLayoutBlank);
 }
Esempio n. 9
0
        public void InsertSlide(int slidePosition, string titleText, string slideText, string layout)
        {
            PowerPoint.PpSlideLayout slideLayout = PowerPoint.PpSlideLayout.ppLayoutTitle;
            switch (layout)
            {
            case "ContentWithCaption":
                slideLayout = PowerPoint.PpSlideLayout.ppLayoutTitle;
                break;

            case "TitleOnly":
                slideLayout = PowerPoint.PpSlideLayout.ppLayoutTitleOnly;
                break;

            case "Title":
                slideLayout = PowerPoint.PpSlideLayout.ppLayoutTitle;
                break;

            case "ObjectAndText":
                slideLayout = PowerPoint.PpSlideLayout.ppLayoutObjectAndText;
                break;

            case "Object":
                slideLayout = PowerPoint.PpSlideLayout.ppLayoutObject;
                break;

            default:
                slideLayout = PowerPoint.PpSlideLayout.ppLayoutObject;
                break;
            }
            if (slidePosition <= oSlides.Count + 1)
            {
                oSlide = oSlides.Add(slidePosition, slideLayout);
            }
            else
            {
                RobotMessageBox.Show("Your slide insert position is incorrect. Please check your number.");
                return;
            }
            oShapes = oSlide.Shapes;
            if (titleText != "")
            {
                PowerPoint.Shape     oShape    = oShapes[1];
                PowerPoint.TextFrame oTxtFrame = oShape.TextFrame;
                PowerPoint.TextRange oTxtRange = oTxtFrame.TextRange;
                oTxtRange.Text = titleText;
            }
            if (slideText != "")
            {
                if (oShapes[2] != null)
                {
                    PowerPoint.Shape     oShape    = oShapes[2];
                    PowerPoint.TextFrame oTxtFrame = oShape.TextFrame;
                    PowerPoint.TextRange oTxtRange = oTxtFrame.TextRange;
                    oTxtRange.Text = slideText;
                }
                else
                {
                    RobotMessageBox.Show("There is no element to add your text to. Have you selected appropriate slide layout?");
                }
            }
        }