Ejemplo n.º 1
0
        public void createFile(string filepath)
        {
            if (filepath.EndsWith(".xlsx"))
            {
                Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
                Workbook ExcelWorkBook = null;
                ExcelApp.Visible       = false;
                ExcelApp.DisplayAlerts = false;

                ExcelWorkBook = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                ExcelWorkBook.SaveAs(filepath);
                ExcelWorkBook.Close();
                ExcelApp.Quit();
            }
            else if (filepath.EndsWith(".pptx"))
            {
                Application pptApplication = new Application();
                // Create the Presentation File
                Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
                Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

                Microsoft.Office.Interop.PowerPoint.Slides slides = pptPresentation.Slides;
                Microsoft.Office.Interop.PowerPoint.Slide  slide  = slides.AddSlide(1, customLayout);
                pptPresentation.SaveAs(filepath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
                pptPresentation.Close();
                pptApplication.Quit();
            }
            else
            {
                File.Create(filepath).Close();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Creating an Application
            Application myApplication = new Application();
            //Creating a Presentation - opening a existing PowerPoint      you need to put the @
            Presentation myPresentation = myApplication.Presentations.Open(@"C:\Users\lucaslemos\Desktop\Github\PowerPoint-CSharp\tutorial_slide.pptx");

            //Dealing with slides
            PowerPoint.Slides slides;                 //will be used as the whole collection of my presentation
            PowerPoint._Slide slide;                  //will be used as my current slide being edited
            slides = myPresentation.Slides;           // (big S)
            PowerPoint.CustomLayout customLayout = myPresentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutText];
            slide = slides.AddSlide(2, customLayout); //Creating a new slide, which will be second slide of my presentation
                                                      //CustomLayout is a mandatory input

            //Dealing with shapes
            PowerPoint.Shapes shapes = slide.Shapes;  //taking all the shapes collection from my current slide
                                                      //Deleting all shapes
                                                      //delete_shapes(shapes); //calling a new function to delete the shapes from the current slide
            //Add pictures
            addPictures(slide);

            //Add TextBox
            add_textbox(slide);
        }
Ejemplo n.º 3
0
        private void awardHeadingMasterCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            int comboIndex = awardHeadingMasterCombo.SelectedIndex;

            mGenInfo.awardHeadingLayoutIndex = comboIndex + 1;

            PowerPoint.CustomLayout selectedLayout = mPresentation.SlideMaster.CustomLayouts[comboIndex + 1];
            mPresentation.Slides.AddSlide(mPresentation.Slides.Count + 1, selectedLayout);
            string workingDirectory = Directory.GetCurrentDirectory();

            awardHeadingTextBoxCombo.Items.Clear();

            // Load the placeholder combo boxes and such
            PowerPoint.Shapes shapes = selectedLayout.Shapes;

            PowerPoint.Placeholders placeholders = shapes.Placeholders;

            foreach (PowerPoint.Shape placeholder in placeholders)
            {
                awardHeadingTextBoxCombo.Items.Add(placeholder.TextFrame.TextRange.Text);
            }

            if (File.Exists(workingDirectory + "/AwardHeadingRender.png"))
            {
                if (headingPictureBox.Image != null)
                {
                    headingPictureBox.Image.Dispose();
                }
                File.Delete(workingDirectory + "/AwardHeadingRender.png");
            }

            mPresentation.Slides[mPresentation.Slides.Count].Export(workingDirectory + "/AwardHeadingRender.png", "png", headingPictureBox.Width, headingPictureBox.Height);

            headingPictureBox.Image = Image.FromFile(workingDirectory + "/AwardHeadingRender.png");
        }
Ejemplo n.º 4
0
        private void testCode()
        {
            // Create a PowerPoint application object.
            PowerPoint.Application appPPT = Globals.ThisAddIn.Application;

            // Create a new PowerPoint presentation.
            PowerPoint.Presentation pptPresentation = appPPT.ActivePresentation;


            PowerPoint.CustomLayout pptLayout = default(PowerPoint.CustomLayout);
            if ((pptPresentation.SlideMaster.CustomLayouts._Index(7) == null))
            {
                pptLayout = pptPresentation.SlideMaster.CustomLayouts._Index(1);
            }
            else
            {
                pptLayout = pptPresentation.SlideMaster.CustomLayouts._Index(7);
            }

            // Create newSlide by using pptLayout.
            PowerPoint.Slide newSlide =
                pptPresentation.Slides.AddSlide((pptPresentation.Slides.Count + 1), pptLayout);

            Color myBackgroundColor = Color.Aqua;
            int   oleColor          = ColorTranslator.ToOle(myBackgroundColor);

            newSlide.FollowMasterBackground        = Core.MsoTriState.msoFalse;
            newSlide.Background.Fill.ForeColor.RGB = oleColor;
            //newSlide.Background.Fill.Visible = Core.MsoTriState.msoFalse;


            PowerPoint.Shape textBox = newSlide.Shapes.AddTextbox(Core.MsoTextOrientation.msoTextOrientationHorizontal, 100, 100, 500, 100);

            textBox.TextFrame.TextRange.Text = "teasdfst";
        }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Application pptApplication = new Application();

            Microsoft.Office.Interop.PowerPoint.Slides    slides;
            Microsoft.Office.Interop.PowerPoint._Slide    slide;
            Microsoft.Office.Interop.PowerPoint.TextRange objText;

            // Create the Presentation File
            Presentation pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

            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      = titleBox.Text;
            objText.Font.Name = "Arial";
            objText.Font.Size = 60;

            // Add body
            objText           = slide.Shapes[2].TextFrame.TextRange;
            objText.Text      = bodyBox.Text;
            objText.Font.Name = "Arial";
            objText.Font.Size = 30;

            Microsoft.Office.Interop.PowerPoint.Shape sheetShape = slides[1].Shapes[1];
            // Add Picture
            var img1 = slides[1].Shapes.AddPicture(pictureBox1.ImageLocation, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, sheetShape.Left + 300, sheetShape.Top + 300, sheetShape.Height - 500, sheetShape.Width + 200);

            img1.ScaleHeight(1, Microsoft.Office.Core.MsoTriState.msoTrue);
        }
Ejemplo n.º 6
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Create a presentation
            PowerPoint.Presentation pres = Globals.ThisAddIn.Application
                                           .Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);

            //Get the blank slide layout
            PowerPoint.CustomLayout layout = pres.SlideMaster.
                                             CustomLayouts[7];

            //Add a blank slide
            PowerPoint.Slide sld = pres.Slides.AddSlide(1, layout);

            //Add a text
            PowerPoint.Shape shp = sld.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 150, 100, 400, 100);

            //Set a text
            PowerPoint.TextRange txtRange = shp.TextFrame.TextRange;
            txtRange.Text      = "Text added dynamically";
            txtRange.Font.Name = "Arial";
            txtRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue;
            txtRange.Font.Size = 32;

            //Write the output to disk
            pres.SaveAs("outVSTOAddingText.ppt",
                        PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
                        Microsoft.Office.Core.MsoTriState.msoFalse);
        }
Ejemplo n.º 7
0
        //To create ppt with generated .gif files
        private void CreatePPT(string sruninFileName)
        {
            string sTemplatePPTPath = Utility.m_sBinPath + "Template.pptm";
            string sNewPPTPath      = Utility.m_sOutputFolderPath + "" + sruninFileName + ".pptm";

            try
            {
                string[] sFiles = System.IO.Directory.GetFiles(Utility.m_sOutputFolderPath, "*.gif");
                if (System.IO.File.Exists(sTemplatePPTPath))
                {
                    System.IO.File.Copy(sTemplatePPTPath, sNewPPTPath, true);
                    Powerpoint.Application  pptApp       = new Powerpoint.Application();
                    Powerpoint.Presentation presentation = pptApp.Presentations.Open(sNewPPTPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);
                    Powerpoint.Slides       oSlides      = presentation.Slides;
                    for (int i = 0; i < sFiles.Length; i++)
                    {
                        int slide_index = i + 2;
                        Powerpoint.Slide        oSlide  = (Powerpoint.Slide)presentation.Slides._Index(slide_index);
                        Powerpoint.CustomLayout oLayout = (Powerpoint.CustomLayout)oSlide.CustomLayout;
                        pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                        Powerpoint.Slide oNewSlide = presentation.Slides.AddSlide(slide_index + 1, oLayout);
                        oNewSlide.Shapes.AddPicture(sFiles[i], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 86, 688, 401);
                    }
                    presentation.Save();
                }
                else
                {
                    MessageBox.Show(sTemplatePPTPath + " file doesn't exists in this path");
                }
            }
            catch (Exception ee)
            {
                Utility.WriteErrorLog(ee);
            }
        }
Ejemplo n.º 8
0
        public void AddSlide()
        {
            PowerPoint.CustomLayout ppt_layout = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutBlank];
            PowerPoint.Slide        slide;

            slide = Globals.ThisAddIn.Application.ActivePresentation.Slides.AddSlide(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
            slide.Shapes[1].Delete();
            slide.Shapes.Placeholders[1].Delete();
        }
Ejemplo n.º 9
0
        public pptfile(string pathway)
        {
            newapp           = new Powerpoint.Application();
            newpres          = newapp.Presentations.Add(MsoTriState.msoTrue);
            newslides        = newpres.Slides;
            directorypathway = pathway;
            newcustomlayout  = newpres.SlideMaster.CustomLayouts[7];

            createslides();
        }
Ejemplo n.º 10
0
        public void kuku()
        {
            PowerPoint.Application  CurrentApplication = Globals.ThisAddIn.Application;
            PowerPoint.Presentation currentPT          = CurrentApplication.ActivePresentation;
            PowerPoint.CustomLayout custom             = currentPT.Slides[1].CustomLayout;
            float width  = currentPT.Slides[1].Shapes[1].Width;
            float height = currentPT.Slides[1].Shapes[1].Height;

            MessageBox.Show("width : " + width + " | height : " + height);
        }
Ejemplo n.º 11
0
        void Application_PresentationSave(PowerPoint.Presentation Prs)
        {
            Prs.ApplyTheme(
                @"C:\Program Files\Microsoft Office\root\Document Themes 16\Wisp.thmx");

            PowerPoint.CustomLayout pptLayout = Prs.Slides[1].CustomLayout;
            Prs.Slides.AddSlide(1, pptLayout);

            Prs.RemovePersonalInformation = Office.MsoTriState.msoTrue;
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
 private int GetIndexAns(pp.CustomLayout _slide, pp.Shape _shape)
 {
     for (int i = 1; i <= _slide.TimeLine.MainSequence.Count; i++)
     {
         if (_slide.TimeLine.MainSequence[i].Shape == _shape)
         {
             return(i);
         }
     }
     return(0);
 }
Ejemplo n.º 14
0
        public void Generate()
        {
            var ppt = new Microsoft.Office.Interop.PowerPoint.Application();

            ppt.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            var pptPresentations = ppt.Presentations;
            var pptPresentation  = pptPresentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

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

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

            var shapes    = slide.Shapes;
            var shape     = shapes[1];
            var textFrame = shape.TextFrame;
            var textRange = textFrame.TextRange;

            textRange.Text = "All-In-One Code Framework";

            var shape2     = shapes[2];
            var textFrame2 = shape2.TextFrame;
            var textRange2 = textFrame2.TextRange;

            textRange2.Text      = "Aloha";
            textRange2.Text     += "FPPT.com";
            textRange2.Font.Name = "Arial";
            textRange2.Font.Size = 32;

            textRange2 = slide.Shapes[2].TextFrame.TextRange;
            // \n denotes a bullet
            textRange2.Text = "Content goes here\nYou can add text\nItem 3";

            slide.Shapes.AddPicture(GetImagePath(@"C:\Users\wong_ga\Pictures"),
                                    Microsoft.Office.Core.MsoTriState.msoFalse,
                                    Microsoft.Office.Core.MsoTriState.msoTrue,
                                    shape.Left, shape.Top + 150.0f, shape.Width + 150.0f, shape.Height + 150.0f);
            slide.NotesPage.Shapes[3].TextFrame.TextRange.Text = "m";



            string fileName = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().Location) + "\\Sample1.pptx";

            pptPresentation.SaveAs(fileName,
                                   Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,
                                   Microsoft.Office.Core.MsoTriState.msoTriStateMixed);

            // close and quit
            //pptPresentation.Close();
            //ppt.Quit();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            string Title    = "";
            string Text     = "";
            string ImageURL = "";

            Console.WriteLine("Enter the name of the slide title, please. This will allow you to search for related images.");
            Title += Console.ReadLine().ToString();
            Console.WriteLine("Enter description, please.");
            Text += Console.ReadLine().ToString();

            Application  pptApplication  = new Application();
            Presentation pptpresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

            string[] titleArray = Title.Split(' ');

            for (int i = 0; i < titleArray.Length; i++)
            {
                Microsoft.Office.Interop.PowerPoint.CustomLayout custLayout =
                    pptpresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
                Microsoft.Office.Interop.PowerPoint.Slides slides;
                Microsoft.Office.Interop.PowerPoint._Slide slide;

                slides = pptpresentation.Slides;
                slide  = slides.AddSlide(i + 1, custLayout);

                ImageURL = "https://www.google.com/search?q=" + titleArray[i] + "&tbm=isch";

                Microsoft.Office.Interop.PowerPoint.TextRange objTextTitle;
                objTextTitle           = slide.Shapes[1].TextFrame.TextRange;
                objTextTitle.Font.Size = 24;
                objTextTitle.Text      = Title;

                slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal,
                                        Left: 150,
                                        Top: 200,
                                        Width: 200,
                                        Height: 300
                                        ).TextFrame.TextRange.Text = Text;

                Microsoft.Office.Interop.PowerPoint.TextRange objText;
                objText           = slide.Shapes[2].TextFrame.TextRange;
                objText.Font.Size = 24;
                objText.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue;
                objText.Text      = "Images for " + titleArray[i];
                objText.ActionSettings
                [Microsoft.Office.Interop.PowerPoint.PpMouseActivation.ppMouseClick]
                .Hyperlink.Address = ImageURL;
                objText.Text.PadLeft(100);
            }
            pptpresentation.SaveAs("newslide.pptx",
                                   Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
                                   Microsoft.Office.Core.MsoTriState.msoTrue);
        }
Ejemplo n.º 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            Application pptApplication = new Application();

            Microsoft.Office.Interop.PowerPoint.Slides    slides;
            Microsoft.Office.Interop.PowerPoint._Slide    slide;
            Microsoft.Office.Interop.PowerPoint.TextRange objText;

            // Create the Presentation File
            Presentation pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

            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      = titleBox.Text;
            objText.Font.Name = "Arial";
            objText.Font.Size = 60;

            // Add body
            objText           = slide.Shapes[2].TextFrame.TextRange;
            objText.Text      = richTextBox1.Text;
            objText.Font.Name = "Arial";
            objText.Font.Size = 30;

            Microsoft.Office.Interop.PowerPoint.Shape sheetShape = slides[1].Shapes[1];
            // Add Picture
            // var img1 = slides[1].Shapes.AddPicture(pictureBox1.ImageLocation, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, sheetShape.Left+300, sheetShape.Top+300, sheetShape.Height-500, sheetShape.Width+200);
            //   img1.ScaleHeight(1,Microsoft.Office.Core.MsoTriState.msoTrue);

            //  if (pictureBox2.BorderStyle > 0)
            //  {
            //     var img2 = slides[1].Shapes.AddPicture(pictureBox2.ImageLocation, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, sheetShape.Left + 300, sheetShape.Top + 300, sheetShape.Height - 500, sheetShape.Width + 200);
            //     img2.ScaleHeight(1, Microsoft.Office.Core.MsoTriState.msoTrue);
            //   }

            PictureBox[] pictures = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6, pictureBox7, pictureBox8, pictureBox9 };


            foreach (PictureBox picture in pictures)
            {
                if (picture.BorderStyle > 0)
                {
                    slides[1].Shapes.AddPicture(picture.ImageLocation, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, sheetShape.Left + 300, sheetShape.Top + 300, sheetShape.Height - 500, sheetShape.Width + 200).ScaleHeight(1, Microsoft.Office.Core.MsoTriState.msoTrue);
                }
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            //initialize powerpoint
            pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();

            // Create the Presentation File
            pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

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

            slideNumber = 1;
        }
Ejemplo n.º 18
0
        private PowerPoint.CustomLayout GetCustomLayout(PowerPoint.Presentation ppPresentation, string slideLayout)
        {
            PowerPoint.CustomLayout ppCustomLayout = null;

            foreach (PowerPoint.CustomLayout customLayout in ppPresentation.SlideMaster.CustomLayouts)
            {
                if (customLayout.Name == slideLayout)
                {
                    return(customLayout);
                }
            }

            return(ppCustomLayout);
        }
Ejemplo n.º 19
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;
            }
Ejemplo n.º 20
0
        public void dodo()
        {
            PowerPoint.Application  CurrentApplication = Globals.ThisAddIn.Application;
            PowerPoint.Presentation currentPT          = CurrentApplication.ActivePresentation;
            PowerPoint.CustomLayout custom             = currentPT.Slides[1].CustomLayout;
            PowerPoint.Slide        newSlide           = currentPT.Slides.AddSlide(1, custom);
            newSlide.Shapes.Title.Title = "타이틀";
            newSlide.Shapes.Title.TextFrame.AutoSize       = PowerPoint.PpAutoSize.ppAutoSizeShapeToFitText;
            newSlide.Shapes.Title.TextFrame.TextRange.Text = "TITLETEXT";
            float t = newSlide.Shapes.Title.Top;

            newSlide.Shapes.Title.TextEffect.Text               = @"한글이로세";
            newSlide.Shapes.Title.TextEffect.FontName           = @"나눔고딕";
            newSlide.Shapes.Title.TextFrame.TextRange.Font.Name = @"나눔고딕";
            newSlide.Shapes.Title.TextFrame.TextRange.Font.Size = 100;
        }
Ejemplo n.º 21
0
        //This button generates the Powerpoint slide from the inputted text and images.
        private void button3_Click(object sender, EventArgs e)
        {
            //Modified from https://stackoverflow.com/questions/26372020/how-to-programmatically-create-a-powerpoint-from-a-list-of-images

            string pictureFileName = "C:\\temp\\test.jpg";

            var 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
            Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

            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      = slideTitle;
            objText.Font.Name = "Arial";
            objText.Font.Size = 32;

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

            if (chosenPictures != null)
            {
                foreach (Picture picture in chosenPictures)
                {
                    Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
                    slide.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
                }
            }

            pptPresentation.SaveAs(@"c:\temp\test.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
            //pptPresentation.Close();
            //pptApplication.Quit();
        }
Ejemplo n.º 22
0
        public PowerPoint.Slide AddPPTSlide(PowerPoint.Presentation pptPreso)
        {
            // Define pptLayout as the "Blank" layout of the default presentation template.
            // If another template is set as default, select the first layout.
            PowerPoint.CustomLayout pptLayout = default(PowerPoint.CustomLayout);
            if ((pptPreso.SlideMaster.CustomLayouts._Index(7) == null))
            {
                pptLayout = pptPreso.SlideMaster.CustomLayouts._Index(1);
            }
            else
            {
                pptLayout = pptPreso.SlideMaster.CustomLayouts._Index(7);
            }

            // Create newSlide by using pptLayout.
            PowerPoint.Slide newSlide =
                pptPreso.Slides.AddSlide((pptPreso.Slides.Count + 1), pptLayout);

            return(newSlide);
        }
Ejemplo n.º 23
0
        private void DoInsertSlide()
        {
            try
            {
                base.InitPresentation();

                if (this.PptPresentation != null)
                {
                    PowerPointObj.CustomLayout customLayout = base.GetCustomLayout();

                    this.PptPresentation.Slides.AddSlide(base.SlideCount + 1, customLayout);

                    base.SavePresentation();
                }
            }
            catch (Exception ex)
            {
                base.ClearObject();
                throw ex;
            }
        }
Ejemplo n.º 24
0
        private void button2_Click(object sender, EventArgs e)
        {
            Point.Application  oApp;
            Point.Presentation pptPresentation;

            Point.Slides    oSlides;
            Point._Slide    oSlide;
            Point.TextRange objText;

            //Create Presentation Text

            oApp = new Point.Application();

            pptPresentation = oApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

            Point.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Point.PpSlideLayout.ppLayoutText];

            //Create Slide
            oSlides = pptPresentation.Slides;

            oSlide = oSlides.AddSlide(1, customLayout);

            //Add Tittle
            objText           = oSlide.Shapes[1].TextFrame.TextRange;
            objText.Text      = "Prueba.com";
            objText.Font.Name = "Arial";
            objText.Font.Size = 28;

            //Body

            objText      = oSlide.Shapes[2].TextFrame.TextRange;
            objText.Text = "One text\nTwo Text\nThree Text";

            oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Es el primer ejemplo para la creación de presentaciones";
            pptPresentation.SaveAs(Directory.GetCurrentDirectory() + "\\presentacion.pptx", Point.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);

            pptPresentation.Close();

            oApp.Quit();
        }
Ejemplo n.º 25
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            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
            Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

            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      = txtTitle.Text.Trim();
            objText.Font.Name = "Arial";
            objText.Font.Size = 32;

            // Add body text
            objText      = slide.Shapes[2].TextFrame.TextRange;
            objText.Text = rtText.Text.Trim();

            // Get list of selected images
            foreach (object file in chkLstImages.CheckedItems)
            {
                string fileName = file.ToString();

                // Insert Image
                Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
                slide.Shapes.AddPicture(fileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Width / 2, shape.Top * 2, shape.Width / 2, shape.Height / 2);
            }

            // Launch PowerPoint
            pptPresentation.SaveAs(@"c:\temp\result.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
        }
Ejemplo n.º 26
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            PowerPoint.Presentation pres = Globals.ThisAddIn.Application
                                           .Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);

            //Get the title slide layout
            PowerPoint.CustomLayout layout = pres.SlideMaster.
                                             CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutTitle];

            //Add a title slide.
            PowerPoint.Slide slide = pres.Slides.AddSlide(1, layout);

            //Set the title text
            slide.Shapes.Title.TextFrame.TextRange.Text = "Slide Title Heading";

            //Set the sub title text
            slide.Shapes[2].TextFrame.TextRange.Text = "Slide Title Sub-Heading";

            //Write the output to disk
            pres.SaveAs("outVSTO.ppt",
                        PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
                        Microsoft.Office.Core.MsoTriState.msoFalse);
        }
Ejemplo n.º 27
0
        private void button1_Click(object sender, EventArgs e)
        {
            // here is where I want to code to output the images on a powerpoint
            // string of the images
            // img.Images.Add(im); this is holding all the images

            // have to call the microsoft library for application since forms and the microsoft library both use Application. Just need to specify
            Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();

            Presentation pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

            for (var i = 0; i < imgList.Count; i++)
            {
                // creating my powerpoint with slides and text
                Microsoft.Office.Interop.PowerPoint.Slides    slides;
                Microsoft.Office.Interop.PowerPoint.Slide     slide;
                Microsoft.Office.Interop.PowerPoint.TextRange objText;
                Microsoft.Office.Interop.PowerPoint.TextRange descrText;

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

                slides    = pptPresentation.Slides;
                slide     = slides.AddSlide(i + 1, custLayout);
                objText   = slide.Shapes[1].TextFrame.TextRange;
                descrText = slide.Shapes[2].TextFrame.TextRange;

                // here is where i added the title to the powerpoint
                objText.Text = title;
                // here is where i added the description to the powerpoint
                descrText.Text = description;

                Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
                slide.Shapes.AddPicture(imgList[i], Microsoft.Office.Core.MsoTriState.msoFalse,
                                        Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
            }
            pptPresentation.SaveAs(@"C:\powerpoint\newPpt.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
        }
Ejemplo n.º 28
0
        private void btCameraSelectata_Click(object sender, EventArgs e)
        {
            if (cmbDisponibile.Text == "SINGLE")
            {
                Hotel = new PP.Application();
                pres  = Hotel.Presentations.Add();

                int nrs = pres.Slides.Count;

                PP.CustomLayout cl = pres.SlideMaster.CustomLayouts[PP.PpSlideLayout.ppLayoutTitle];

                slide = pres.Slides.AddSlide(nrs + 1, cl);

                slide.Shapes.Title.TextFrame.TextRange.Text = "CAMERA SINGLE";

                slide.Shapes[2].TextFrame.TextRange.Text = "Camerele Single ofera oaspetilor o atmosfera calda si linistitoare care imbina perfect relaxarea cu utilul. Camerele single sunt cu vedere spre curtea interioara si asigura liniste deplina atat pe timp de zi cat si pe timp de noapte." +
                                                           "Oaspetii se pot bucura de Internet wireless, televiziune prin cablu si control individual al climei.";

                slide.Shapes.Title.TextFrame.TextRange.Font.Color.RGB = Color.White.ToArgb();

                slide.Shapes[2].TextFrame.TextRange.Font.Color.RGB = Color.White.ToArgb();

                slide.Shapes.Title.TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoCTrue;

                slide.Shapes[2].TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoCTrue;

                string cale = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\single1.jpg";

                string cale2 = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\single2.jpg";

                string cale3 = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\single3.jpg";


                float lat   = slide.CustomLayout.Width;
                float inalt = slide.CustomLayout.Height;


                PP.Shape shape = slide.Shapes.AddPicture(cale, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);

                slide.Shapes[2].ZOrder(Office.MsoZOrderCmd.msoBringToFront);

                slide.Shapes.Title.ZOrder(Office.MsoZOrderCmd.msoBringToFront);


                slide = pres.Slides.AddSlide(nrs + 2, cl);

                PP.Shape shape2 = slide.Shapes.AddPicture(cale2, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);


                slide = pres.Slides.AddSlide(nrs + 3, cl);

                PP.Shape shape3 = slide.Shapes.AddPicture(cale3, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);
            }

            if (cmbDisponibile.Text == "DOUBLE")
            {
                Hotel = new PP.Application();
                pres  = Hotel.Presentations.Add();

                int nrs = pres.Slides.Count;

                PP.CustomLayout cl = pres.SlideMaster.CustomLayouts[PP.PpSlideLayout.ppLayoutTitle];

                slide = pres.Slides.AddSlide(nrs + 1, cl);

                slide.Shapes.Title.TextFrame.TextRange.Text = "CAMERA DOUBLE";

                slide.Shapes[2].TextFrame.TextRange.Text = "Camerele Double oferta oaspetilor nostri o atmosfera calda si linistitoare care imbina perfect relaxarea cu utilul. Camerele double au vedere spre cladirea Cercului Militar si Calea Victoriei asigurand o panorama incontestabila asupra arhitecturii de altadata. Oaspetii se pot bucura de Internet wireless, televiziune prin cablu si control individual al climei";


                slide.Shapes.Title.TextFrame.TextRange.Font.Color.RGB = Color.White.ToArgb();

                slide.Shapes[2].TextFrame.TextRange.Font.Color.RGB = Color.White.ToArgb();

                slide.Shapes.Title.TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoCTrue;

                slide.Shapes[2].TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoCTrue;

                string cale = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\double1.jpg";

                string cale2 = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\double2.jpg";

                string cale3 = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\double3.jpg";


                float lat   = slide.CustomLayout.Width;
                float inalt = slide.CustomLayout.Height;


                PP.Shape shape = slide.Shapes.AddPicture(cale, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);

                slide.Shapes[2].ZOrder(Office.MsoZOrderCmd.msoBringToFront);

                slide.Shapes.Title.ZOrder(Office.MsoZOrderCmd.msoBringToFront);


                slide = pres.Slides.AddSlide(nrs + 2, cl);

                PP.Shape shape2 = slide.Shapes.AddPicture(cale2, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);


                slide = pres.Slides.AddSlide(nrs + 3, cl);

                PP.Shape shape3 = slide.Shapes.AddPicture(cale3, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);
            }


            if (cmbDisponibile.Text == "APARTAMENT")
            {
                Hotel = new PP.Application();
                pres  = Hotel.Presentations.Add();

                int nrs = pres.Slides.Count;

                PP.CustomLayout cl = pres.SlideMaster.CustomLayouts[PP.PpSlideLayout.ppLayoutTitle];

                slide = pres.Slides.AddSlide(nrs + 1, cl);

                slide.Shapes.Title.TextFrame.TextRange.Text = "APARTAMENT";

                slide.Shapes[2].TextFrame.TextRange.Text = "Apartamentele ofera oaspetilor nostri o atmosfera calda si linistitoare care imbina perfect relaxarea cu utilul. Apartamentele au vedere spre cladirea Cercului Militar si Calea Victoriei, asigurand o panorama incontestabila asupra arhitecturii de altadata. Oaspetii se pot bucura de Internet wireless, televiziune prin cablu si control individual al climei.";


                slide.Shapes.Title.TextFrame.TextRange.Font.Color.RGB = Color.White.ToArgb();

                slide.Shapes[2].TextFrame.TextRange.Font.Color.RGB = Color.White.ToArgb();

                slide.Shapes.Title.TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoCTrue;

                slide.Shapes[2].TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoCTrue;

                string cale = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\ap1.jpg";

                string cale2 = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\ap2.jpg";

                string cale3 = @"C:\Users\Gabriel Birzu\OneDrive\Desktop\Proiect IPLA\Poze\ap3.jpg";


                float lat   = slide.CustomLayout.Width;
                float inalt = slide.CustomLayout.Height;


                PP.Shape shape = slide.Shapes.AddPicture(cale, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);

                slide.Shapes[2].ZOrder(Office.MsoZOrderCmd.msoBringToFront);

                slide.Shapes.Title.ZOrder(Office.MsoZOrderCmd.msoBringToFront);


                slide = pres.Slides.AddSlide(nrs + 2, cl);

                PP.Shape shape2 = slide.Shapes.AddPicture(cale2, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);


                slide = pres.Slides.AddSlide(nrs + 3, cl);

                PP.Shape shape3 = slide.Shapes.AddPicture(cale3, Office.MsoTriState.msoCTrue, Office.MsoTriState.msoFalse, 0, 0, lat - 0, inalt - 0);
            }


            PP.SlideRange          ssr = pres.Slides.Range();
            PP.SlideShowTransition sst = ssr.SlideShowTransition;
            sst.AdvanceOnTime = Office.MsoTriState.msoTrue;
            sst.AdvanceTime   = 3;
            sst.EntryEffect   = PP.PpEntryEffect.ppEffectRevealSmoothRight;
            PP.SlideShowSettings ssp = pres.SlideShowSettings;
            ssp.StartingSlide = 1;
            ssp.EndingSlide   = pres.Slides.Count;
            ssp.Run();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// This method will generate the PowerPoint from the information provided in the slide.csv.
        /// It will take each slide title, slide text, and slide image and make it into a simple
        /// powerpoint with simple white background and normal fonts/sizes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gen_slide_button_Click(object sender, EventArgs e)
        {
            //string PictureFile = @"C:\powerpoint\img1.jpg";
            //First get required information from csv file
            //3) Open csv file, read contents
            List <List <string> > info_list = new List <List <string> >();

            try
            {
                //3A) Open csv file
                StreamReader info = File.OpenText(csv_slide_file);
                //3B) Get header line to be used later
                string[] header_line = info.ReadLine().Split(sep_char);

                //3C) Use a while loop to get all of the info
                while (!info.EndOfStream)
                {
                    string rawline = info.ReadLine();
                    //string[] line = sep_and_return(rawline);
                    string[]      line  = rawline.Split(sep_char);
                    List <string> entry = line.ToList();
                    info_list.Add(entry);
                }

                //Always be sure to close the file after opening it!
                info.Close();
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
            }

            //Then create PowerPoint File
            Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
            Presentation pptpresent   = ppt.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
            float        slide_height = pptpresent.PageSetup.SlideHeight;
            float        slide_width  = pptpresent.PageSetup.SlideWidth;

            int num_slides = slide_count;

            for (int i = 0; i < num_slides; i++)
            {
                string[] current_info   = info_list[i].ToArray();
                int      number_of_pics = current_info.Length - 3;
                Microsoft.Office.Interop.PowerPoint.Slides    slides;
                Microsoft.Office.Interop.PowerPoint._Slide    slide;
                Microsoft.Office.Interop.PowerPoint.TextRange slide_title;
                Microsoft.Office.Interop.PowerPoint.TextRange slide_text;

                Microsoft.Office.Interop.PowerPoint.CustomLayout custLayout =
                    pptpresent.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTable];

                slides = pptpresent.Slides;
                slide  = slides.AddSlide(i + 1, custLayout);

                //slide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 30, 30, 100, 10);
                //slide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 50, 50, 100, 10);

                //slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 300, 100);
                slide_title           = slide.Shapes[1].TextFrame.TextRange;
                slide_title.Text      = current_info[1];
                slide_title.Font.Name = "";
                slide_title.Font.Size = 32;

                //slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 10, 110, 300, 300).TextFrame.TextRange;
                slide_text           = slide.Shapes[2].TextFrame.TextRange;
                slide_text.Text      = current_info[2];
                slide_text.Font.Name = "";
                slide_text.Font.Size = 18;

                //add a bunch of photos
                float pic_width  = 0;   //100;
                float pic_height = 0;   // 100;
                float padding    = 10;  //

                //Declare a counter to keep track of all of the shapes. Initialized with a 3 to account for the Title and 2 textboxes
                int shape_counter = 3;

                List <string> picture_filenames = new List <string>();

                for (int en = 3; en < current_info.Length; en++)
                {
                    picture_filenames.Add(current_info[en]);
                }

                string[] pic_filenames = picture_filenames.ToArray();

                if (pic_filenames.Length == 1)
                {
                    pic_width  = (slide_width / 2) - 10;
                    pic_height = (slide_height - 200) - 10;

                    float height_placeholder = 0;
                    float width_placeholder  = 0;

                    for (int p = 0; p < pic_filenames.Length; p++)
                    {
                        var rec_shape = slide.Shapes.AddShape(
                            Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle,
                            (slide_width - pic_width - padding),
                            (slide_height - pic_height - padding),
                            pic_width,
                            pic_height
                            );
                        rec_shape.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();

                        shape_counter++;
                        string PictureFile = pic_filenames[p];
                        Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[shape_counter];
                        slide.Shapes.AddPicture(PictureFile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
                    }
                }
                else if (pic_filenames.Length == 2)
                {
                    pic_width  = (slide_width / 2) - 10;
                    pic_height = ((slide_height - 200) / 2) - 10;

                    float height_placeholder = pic_height * 2;
                    float width_placeholder  = pic_width;

                    for (int p = 0; p < pic_filenames.Length; p++)
                    {
                        var rec_shape = slide.Shapes.AddShape(
                            Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle,
                            (slide_width - pic_width - padding),
                            (slide_height - pic_height - padding),
                            pic_width,
                            pic_height
                            );
                        rec_shape.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();

                        shape_counter++;
                        string PictureFile = pic_filenames[p];
                        Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[shape_counter];
                        slide.Shapes.AddPicture(PictureFile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);

                        height_placeholder -= pic_height;
                    }
                }
                else if (pic_filenames.Length < 5 && pic_filenames.Length > 2)
                {
                    pic_width  = (slide_width / 4) - 10;
                    pic_height = (slide_height - 200) / 2;

                    for (int p = 0; p < pic_filenames.Length; p++)
                    {
                        float height_placeholder = pic_height * 2;
                        float width_placeholder  = pic_width * 2;

                        if (p == 1)
                        {
                            width_placeholder -= pic_width;
                        }
                        else if (p == 2)
                        {
                            height_placeholder -= pic_height;
                        }
                        else if (p == 3)
                        {
                            height_placeholder -= pic_height;
                            width_placeholder  -= pic_width;
                        }
                        var rec_shape = slide.Shapes.AddShape(
                            Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle,
                            (slide_width - pic_width - padding),
                            (slide_height - pic_height - padding),
                            pic_width,
                            pic_height
                            );
                        rec_shape.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();

                        shape_counter++;
                        string PictureFile = pic_filenames[p];
                        Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[shape_counter];
                        slide.Shapes.AddPicture(PictureFile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
                    }
                }
                else if (pic_filenames.Length < 7 && pic_filenames.Length > 4)
                {
                    pic_width  = (slide_width / 4) - 10;
                    pic_height = (slide_height - 200) / 3;

                    for (int p = 0; p < pic_filenames.Length; p++)
                    {
                        float height_placeholder = pic_height * 3;
                        float width_placeholder  = pic_width * 2;

                        if (p == 1)
                        {
                            width_placeholder -= pic_width;
                        }
                        else if (p == 2)
                        {
                            height_placeholder -= pic_height;
                        }
                        else if (p == 3)
                        {
                            height_placeholder -= pic_height;
                            width_placeholder  -= pic_width;
                        }
                        else if (p == 4)
                        {
                            height_placeholder -= pic_height * 2;
                        }
                        else if (p == 5)
                        {
                            height_placeholder -= pic_height * 2;
                            width_placeholder  -= pic_width;
                        }
                        var rec_shape = slide.Shapes.AddShape(
                            Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle,
                            (slide_width - pic_width - padding),
                            (slide_height - pic_height - padding),
                            pic_width,
                            pic_height
                            );
                        rec_shape.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();

                        shape_counter++;
                        string PictureFile = pic_filenames[p];
                        Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[shape_counter];
                        slide.Shapes.AddPicture(PictureFile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
                    }
                }
            }
            //pptpresent.SaveAs("newslide.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
        }
Ejemplo n.º 30
0
        private void buttonCreateSlides_Click(object sender, EventArgs e)
        {
            DataRowView fromBook  = this.selectBookFrom.SelectedItem as DataRowView;
            DataRowView fromChap  = this.selectChapterFrom.SelectedItem as DataRowView;
            DataRowView fromVerse = this.selectVerseFrom.SelectedItem as DataRowView;

            string fB = fromBook.Row["book_number"].ToString();
            string fC = fromChap.Row["chapter"].ToString();
            string fV = fromVerse.Row["verse"].ToString();

            DataRowView toBook  = this.selectBookTo.SelectedItem as DataRowView;
            DataRowView toChap  = this.selectChapterTo.SelectedItem as DataRowView;
            DataRowView toVerse = this.selectVerseTo.SelectedItem as DataRowView;

            string tB = toBook.Row["book_number"].ToString();
            string tC = toChap.Row["chapter"].ToString();
            string tV = toVerse.Row["verse"].ToString();

            if (Int32.Parse(tB) < Int32.Parse(fB))
            {
                MessageBox.Show("You selected a book in the To part that is before the one in the from :-/ Try again");
                return;
            }

            if ((Int32.Parse(tB) == Int32.Parse(fB)) && (Int32.Parse(tC) < Int32.Parse(fC)))
            {
                MessageBox.Show("You selected a chapter in the To part that is before the one in the from :-/ Try again");
                return;
            }

            if ((Int32.Parse(tB) < Int32.Parse(fB)) && (Int32.Parse(tC) < Int32.Parse(fC)))
            {
                MessageBox.Show("You selected a chapter or book in the To part that is before the one in the from :-/ Try again");
                return;
            }

            if ((Int32.Parse(tB) == Int32.Parse(fB)) && (Int32.Parse(tC) == Int32.Parse(fC)) && (Int32.Parse(tV) < Int32.Parse(fV)))
            {
                MessageBox.Show("You selected a verse in the To part that is before the one in the from :-/ Try again");
                return;
            }

            Queue <string> pagesOfVerses             = new Queue <string>();
            string         currentPage               = "";
            int            currentPageCharacterCount = 0;
            int            maxCharactersOnAPage      = 350;

            //get verses.. check there aren't too many
            using (SQLiteConnection conn = new SQLiteConnection(connString))
            {
                try
                {
                    string query = "SELECT text from verses WHERE absoluteVerseNumber >= " +
                                   "(SELECT absoluteVerseNumber from verses where book = '" + fB + "' AND chapter = '" + fC + "' AND verse = '" + fV + "')" +
                                   "AND absoluteVerseNumber <= (SELECT absoluteVerseNumber from verses where book = '" + tB + "' AND chapter = '" + tC + "' AND verse = '" + tV + "')" +
                                   "order by absoluteVerseNumber;";


                    SQLiteDataAdapter da = new SQLiteDataAdapter(query, conn);
                    conn.Open();
                    DataSet ds = new DataSet();
                    da.Fill(ds, "Verses");
                    var allVerses = ds.Tables[0].AsEnumerable().Select(r => r.Field <string>("text")).ToList();

                    if (allVerses.Count > 100)
                    {
                        MessageBox.Show("Whoa there! You selected waaay tooo many verses.. over 100!! Try again, I'm not working this hard");
                        return;
                    }

                    foreach (string s in allVerses)
                    {
                        string better = s.Replace("; ; ; ;", "");
                        better = better.Trim();
                        better = s.Replace("<pb />", "\n");
                        better = s.Replace("<pb/>", "\n");

                        if ((currentPageCharacterCount + better.Length) < maxCharactersOnAPage)
                        {
                            currentPageCharacterCount = currentPageCharacterCount + better.Length;
                            currentPage = currentPage + " " + better;
                        }
                        else
                        {
                            pagesOfVerses.Enqueue(currentPage);
                            currentPage = better;
                            currentPageCharacterCount = better.Length;
                        }
                    }
                    pagesOfVerses.Enqueue(currentPage);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }


            //create slides

            // Create an instance of Microsoft PowerPoint
            PowerPoint.Application oPowerPoint = new PowerPoint.Application();

            // Create a new Presentation
            PowerPoint.Presentation oPre = oPowerPoint.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

            oPre.ApplyTheme(this.templateFile);
            oPre.PageSetup.SlideSize = PowerPoint.PpSlideSizeType.ppSlideSizeOnScreen16x9;

            PowerPoint.CustomLayout titleMasterSlide = oPre.SlideMaster.CustomLayouts[Enums.SlidesMaster.ChromakeyScriptureTitle];
            PowerPoint.CustomLayout verseSlide       = oPre.SlideMaster.CustomLayouts[Enums.SlidesMaster.WhiteScriptureText]; //[PowerPoint.PpSlideLayout.ppLayoutBlank];

            // Insert a new Slide and add some text to it.
            int countSlides = 1;

            //Insert the title
            PowerPoint.Slide titleSlide   = oPre.Slides.AddSlide(countSlides, titleMasterSlide);
            string           scriptureRef = fromBook.Row["long_name"].ToString() + " " + fC + ":" + fV + " - " + toBook.Row["long_name"].ToString() + " " + tC + ":" + tV;

            if (fromBook.Row["long_name"].ToString() == toBook.Row["long_name"].ToString())
            {
                scriptureRef = fromBook.Row["long_name"].ToString() + " " + fC + ":" + fV + " - " + " " + tC + ":" + tV;
            }

            titleSlide.Shapes[1].TextFrame.TextRange.Text = scriptureRef;
            countSlides++;

            foreach (string aPage in pagesOfVerses)
            {
                PowerPoint.Slide oSlide = oPre.Slides.AddSlide(countSlides, verseSlide);
                oSlide.Shapes[1].TextFrame2.AutoSize = Office.MsoAutoSize.msoAutoSizeTextToFitShape;
                oSlide.Shapes[1].TextFrame2.TextRange.ParagraphFormat.SpaceAfter             = 6;
                oSlide.Shapes[1].TextFrame2.TextRange.ParagraphFormat.SpaceBefore            = 0;
                oSlide.Shapes[1].TextFrame2.TextRange.Paragraphs.ParagraphFormat.SpaceAfter  = 6;
                oSlide.Shapes[1].TextFrame2.TextRange.Paragraphs.ParagraphFormat.SpaceBefore = 0;
                oSlide.Shapes[1].TextFrame2.TextRange.Text = aPage;
                countSlides++;
            }
        }