Exemple #1
0
        public void initPPTAutomation()
        {
            _pptApplication = new Application();

            _pptPresentation = _pptApplication.Presentations.Add(Office.MsoTriState.msoTrue);

            _customLayout = _pptPresentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];

            // 새 슬라이드 생성
            _slides = _pptPresentation.Slides;
            _slide  = _slides.AddSlide(1, _customLayout);

            // 타이틀 추가
            _objText      = _slide.Shapes[1].TextFrame.TextRange;
            _objText.Text = "제목입니당";
            //TOAN : 01/28/2019. FontName에서 Exception이 발생하는듯 하다.
            //_objText.Font.Name = "Gulim";
            //_objText.Font.Size = 32;
            _objText.Font.Size = 20;
            _objText           = _slide.Shapes[2].TextFrame.TextRange;
            //_objText.Text = "1번째줄\n2번째줄\n3번째줄";
            int ioop = 0;

            //int ioop = 48;
            for (ioop = 0; ioop < 10; ioop++)
            {
                _objText.Text += ioop.ToString();
                _objText.Text += "\n";
                //아래 코드를 사용하면 루프중에 프로그램이 종료되버린다.
                //Delay(1000);
            }

            //TOAN : 01/28/2019. Temporary Blocking
            _slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "여기는 슬라이드 설명쓰는곳입니당.";

            //File저장 영역은 현재 디렉토리에 저장을 시켜 준다.
            //_pptPresentation.SaveAs(@"c:\COOLA\ppttest.pptx", PpSaveAsFileType.ppSaveAsDefault, Office.MsoTriState.msoTrue);

            _slide = _slides.AddSlide(2, _customLayout);
            // 타이틀 추가
            _objText = _slide.Shapes[1].TextFrame.TextRange;
            //_objText.Text = "제목입니당";
            _objText.Font.Size = 32;
            _objText.Text      = "제목";

            //Delay(5000);

            _objText.Text      = _objText.Text + "입니당";
            _objText.Font.Name = "Gulim";
            _objText.Font.Size = 32;

            _objText      = _slide.Shapes[2].TextFrame.TextRange;
            _objText.Text = "4번째줄\n5번째줄\n6번째줄";

            _slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "여기는 슬라이드 설명쓰는곳입니당.";
        }
Exemple #2
0
        private void SubmitClick(object sender, RoutedEventArgs e)
        {
            // Create new Slide
            slides = pptPresentation.Slides;
            slide  = slides.AddSlide(1, customLayout);

            // Add title
            objText = slide.Shapes[1].TextFrame.TextRange;
            System.Windows.Documents.TextRange titleRange = new System.Windows.Documents.TextRange
                                                                (TitleBox.Document.ContentStart, TitleBox.Document.ContentEnd);
            objText.Text = titleRange.Text;

            // Add text
            objText = slide.Shapes[2].TextFrame.TextRange;
            System.Windows.Documents.TextRange textRange = new System.Windows.Documents.TextRange
                                                               (TextBox.Document.ContentStart, TextBox.Document.ContentEnd);
            objText.Text = textRange.Text;

            int numPics = 0;

            if (selected != null)
            {
                numPics = selected.Count();
            }

            Console.WriteLine("\n\nSelected Image URLs, \n");
            Microsoft.Office.Interop.PowerPoint.Shape photo = slide.Shapes[2];
            for (int i = 0; i < numPics && i < 3; i++)
            {
                Console.WriteLine(selected[i] + "\n");
                slide.Shapes.AddPicture(selected[i], MsoTriState.msoFalse, MsoTriState.msoTrue, (i * 200), 300, photo.Width, photo.Height);
            }
            Console.WriteLine("\n\n");
        }
Exemple #3
0
        /// <summary>
        /// Create new slide
        /// </summary>
        /// <param name="pptPresentation">current ppt presentation file</param>
        /// <param name="customLayout">custom layout for slide</param>
        private void CreateNewSlide(Presentation pptPresentation, CustomLayout customLayout)
        {
            // Create new Slide
            slides = pptPresentation.Slides;
            slide  = slides.AddSlide(slide.SlideIndex + 1, customLayout);

            Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes.AddLabel(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 120, 500, 200, 70);
            shape.TextFrame.TextRange.Text = "Footer text goes here" + slide.SlideIndex.ToString();
        }
Exemple #4
0
        public void AddBlankSlide()
        {
            CustomLayout customLayout = _presentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];
            Slide        slide        = _slides.AddSlide(_slides.Count + 1, customLayout);

            int cnt = slide.Shapes.Count;

            for (int i = 0; i < cnt; i++)
            {
                slide.Shapes[1].Delete();
            }
        }
Exemple #5
0
        private void CheckOfficePermissions()
        {
            System.Diagnostics.Debug.WriteLine("Checking Office Permissions");

            Application pptApp = null;
            int         pId    = 0;

            try
            {
                // Prüft ob auf dem Rechner alle erforderlichen Rechte vorliegen um Reports zu erstellen
                // Es wird ein Testreport erstellt

                FileUtil.DeleteAllFilesInDirectory(_globalSettings.ReportDirectory_PPT_Init);

                pptApp = new Application();
                pId    = ProcessUtil.GetProcessId(pptApp, ApplicationType.POWERPOINT);

                Presentation ppt          = pptApp.Presentations.Add(MsoTriState.msoFalse);
                CustomLayout customLayout = ppt.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];
                Slides       slides       = ppt.Slides;
                _Slide       slide        = slides.AddSlide(1, customLayout);

                TextRange objText = slide.Shapes[1].TextFrame.TextRange;
                objText.Text      = "Test1";
                objText.Font.Name = "Arial";
                objText.Font.Size = 20;

                ppt.SaveAs(Path.Combine(_globalSettings.ReportDirectory_PPT_Init, "Text.pptx"), PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoFalse);
                ppt.Close();

                ProcessUtil.KillOfficeApplication(pptApp, ApplicationType.POWERPOINT, true);

                ppt    = null;
                pptApp = null;

                GC.Collect();
            }
            catch (Exception ex)
            {
                try
                {
                    ProcessUtil.KillOfficeApplication(pptApp, ApplicationType.POWERPOINT, true);
                }
                catch (Exception) {
                    ProcessUtil.KillProcessById(pId);
                }

                pptApp = null;

                throw new Exception("Error Creating Test PPT Report", ex);
            }
        }
        public PowerPointClass(string pptPath, List <Slide> list)
        {
            this.pptPath = pptPath;
            deleteIfExists();

            pptApplication = new Application();
            Presentation presentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
            CustomLayout customLayout = presentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];

            this.slides = presentation.Slides;



            int slideIndex = 1;

            foreach (var item in list)
            {
                // slide
                slide = slides.AddSlide(slideIndex++, customLayout);

                objText           = slide.Shapes[1].TextFrame.TextRange;
                objText.Text      = item.Title.Content;
                objText.Font.Size = item.Title.Size;


                foreach (var bullet in item.Bullets)
                {
                    objText           = slide.Shapes[2].TextFrame.TextRange;
                    objText.Text      = bullet.Content;
                    objText.Font.Size = bullet.Size;
                }
            }

            presentation.SaveAs(pptPath,
                                PpSaveAsFileType.ppSaveAsDefault,
                                MsoTriState.msoTrue);

            presentation.Close();
            try {
                pptApplication.Quit();
            }
            catch (Exception)
            {
                Console.WriteLine("Couldn't exit PowerPoint Application!");
            }
        }
Exemple #7
0
        public override void CreateFile(string filePath, DocumentModel data)
        {
            int          slideIndex      = 1; // created single slide file.
            Application  pptApp          = null;
            Presentation pptPresentation = null;
            Slides       slides          = null;
            _Slide       slide           = null;
            TextRange    objText         = null;
            CustomLayout customLayout    = null;

            try
            {
                pptApp          = new Application();
                pptPresentation = pptApp.Presentations.Add();

                // create new Slide
                slides       = pptPresentation.Slides;
                customLayout = pptPresentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];
                slide        = slides.AddSlide(slideIndex, customLayout);

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

                // write description
                objText      = slide.Shapes[2].TextFrame.TextRange;
                objText.Text = data.Description;

                pptPresentation.SaveAs(filePath);
                pptPresentation.Close();
                pptApp.Quit();
            }
            finally
            {
                ReleaseFileObject(pptPresentation);
                ReleaseFileObject(pptApp);
            }
        }
Exemple #8
0
        //TOAN : 06/08/2019. Code Enhancement
        public void addPage(int num)
        {
            //TOAN : 06/08/2019. Add-Page을 실행할 때, 아래 2줄은 꼭 쌍으로 참조가 되어야 한다.
            _slides = _pptPresentation.Slides;
            _slide  = _slides.AddSlide(/*1*/ num, _customLayout);

            _objText      = _slide.Shapes[1].TextFrame.TextRange;
            _objText.Text = "제목입니당";
            _objText      = _slide.Shapes[2].TextFrame.TextRange;
            //_objText.Text = "1번째줄\n2번째줄\n3번째줄";

            int ioop = 0;

            for (ioop = 0; ioop < 10; ioop++)
            {
                _objText.Text += ioop.ToString();
                _objText.Text += "\n";
                Thread.Sleep(2000);
            }

            _slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "여기는 슬라이드 설명쓰는곳입니당.";
        }
Exemple #9
0
        /// <summary>
        /// create ppt presantation file
        /// </summary>
        /// <returns></returns>
        public Presentation CreatePPTFile()
        {
            pptPresentation        = pptApplication.Presentations.Add(MsoTriState.msoTrue);
            pptApplication.Visible = MsoTriState.msoTrue;
            customLayout           = pptPresentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];

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

            slide.FollowMasterBackground        = MsoTriState.msoFalse;
            slide.Background.Fill.ForeColor.RGB = 0xFF3300;

            CreateOrderedList();

            CreateUnOrderList();

            //Create image in slide
            //CreateImage();

            //Create title
            CreateTitle("Name of the client", 32);

            CreateTextBox("Internal Audit - Review for Audit Period_________", 32, 120, 120, 500, 80);

            //Create new slide
            CreateNewSlide(pptPresentation, customLayout);

            //Create image in slide
            CreateChart();

            //Create new slide
            CreateNewSlide(pptPresentation, customLayout);

            CreateTable();

            return(pptPresentation);
        }
Exemple #10
0
        public void addPageWithTime()
        {
            int i = 1;

            _slides = _pptPresentation.Slides;
            do
            {
                if (_exit_flag == true)
                {
                    break;
                }

                _slide = _slides.AddSlide(i, _customLayout);
                // 타이틀 추가
                _objText      = _slide.Shapes[1].TextFrame.TextRange;
                _objText.Text = "제목입니당";
                //TOAN : 01/28/2019. FontName에서 Exception이 발생하는듯 하다.
                //_objText.Font.Name = "Gulim";
                //_objText.Font.Size = 32;
                _objText.Font.Size = 20;
                _objText           = _slide.Shapes[2].TextFrame.TextRange;
                //_objText.Text = "1번째줄\n2번째줄\n3번째줄";
                int ioop = 0;
                //int ioop = 48;
                for (ioop = 0; ioop < 10; ioop++)
                {
                    _objText.Text += ioop.ToString();
                    _objText.Text += "\n";
                    //아래 코드를 사용하면 루프중에 프로그램이 종료되버린다.
                    Delay(1000);
                }

                //TOAN : 01/28/2019. Temporary Blocking
                _slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "여기는 슬라이드 설명쓰는곳입니당.";

                i = i + 1;
            } while (_exit_flag == false);
        }