Ejemplo n.º 1
0
        //public void ExportToPPT(string folderPath, string themeFilePath)
        //{
        //    string pptFilePath = folderPath + @"\Report.pptx";
        //    if (DocumentFormat.OpenXml.Packaging.Extensions.PowerpointExtensions.CopyPresentation(themeFilePath, pptFilePath))
        //    {
        //        using (PresentationDocument presentationDocument = PresentationDocument.Open(pptFilePath, true))
        //        {
        //            DirectoryInfo imagesDirectory = new DirectoryInfo(folderPath);
        //            foreach (FileInfo file in imagesDirectory.GetFiles("*.png"))
        //            {
        //                Slide slide = presentationDocument.PresentationPart.InsertSlide("Title Only");
        //                Shape shape = slide.CommonSlideData.ShapeTree.Elements<Shape>().FirstOrDefault(
        //                    sh => sh.NonVisualShapeProperties.NonVisualDrawingProperties.Name.Value.ToLower().Equals("Content Placeholder 2".ToLower()));
        //                Picture pic = slide.AddPicture(shape, file.FullName);
        //                slide.CommonSlideData.ShapeTree.RemoveChild<Shape>(shape);
        //                slide.Save();
        //            }
        //            presentationDocument.PresentationPart.Presentation.Save();
        //            presentationDocument.Close();

        //        }
        //    }
        //}

        public void ExportToPPT(string folderPath, string themeFilePath)
        {
            string pptFilePath = folderPath + @"\Report.pptx";

            if (CopyPresentation(themeFilePath, pptFilePath))
            {
                using (PresentationDocument presentationDocument = PresentationDocument.Open(pptFilePath, true))
                {
                    DirectoryInfo imagesDirectory = new DirectoryInfo(folderPath);
                    int           position        = 7;
                    foreach (FileInfo file in imagesDirectory.GetFiles("*.png"))
                    {
                        Slide slide = InsertNewSlide(presentationDocument, position, file.Name);
                        Shape shape = slide.CommonSlideData.ShapeTree.Elements <Shape>().FirstOrDefault(
                            sh => sh.NonVisualShapeProperties.NonVisualDrawingProperties.Name.Value.ToLower().Equals("Content Placeholder 2".ToLower()));
                        Picture pic = slide.AddPicture(shape, file.FullName);
                        slide.CommonSlideData.ShapeTree.RemoveChild <Shape>(shape);
                        slide.Save();
                    }
                    presentationDocument.PresentationPart.Presentation.Save();
                    presentationDocument.Close();
                }
            }
        }