예제 #1
0
        public IReadOnlyCollection <PresentationSlideNote> GetAllSlideNotes()
        {
            var comments = new List <PresentationSlideNote>();

            using (PresentationDocument presentationDocument = PresentationDocument.Open(this._filePath, false))
            {
                var         presentationPart = presentationDocument.PresentationPart;
                SlideIdList slideIdList      = presentationPart.Presentation.SlideIdList;
                uint        slideShowIndex   = 0;

                _logger.Verbose($"Getting notes from {slideIdList.Count()} slides");

                foreach (SlideId slideId in slideIdList.ChildElements)
                {
                    slideShowIndex++;
                    SlidePart slidePart = (SlidePart)presentationPart.GetPartById(slideId.RelationshipId);
                    var       notesText = slidePart.NotesSlidePart?.NotesSlide?.InnerText;

                    if (!string.IsNullOrWhiteSpace(notesText))
                    {
                        comments.Add(new PresentationSlideNote(slideId.Id?.Value, slideId.RelationshipId, notesText, slideShowIndex));
                    }
                    //slidePart.Parts.Select(rel => rel.)
                    // NotesSlidePart.NotesSlide.InnerXml:
                    // "<p:cSld xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\"><p:spTree><p:nvGrpSpPr><p:cNvPr id=\"1\" name=\"\" /><p:cNvGrpSpPr /><p:nvPr /></p:nvGrpSpPr><p:grpSpPr><a:xfrm xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:off x=\"0\" y=\"0\" /><a:ext cx=\"0\" cy=\"0\" /><a:chOff x=\"0\" y=\"0\" /><a:chExt cx=\"0\" cy=\"0\" /></a:xfrm></p:grpSpPr><p:sp><p:nvSpPr><p:cNvPr id=\"2\" name=\"Slide Image Placeholder 1\" /><p:cNvSpPr><a:spLocks noGrp=\"1\" noRot=\"1\" noChangeAspect=\"1\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:cNvSpPr><p:nvPr><p:ph type=\"sldImg\" /></p:nvPr></p:nvSpPr><p:spPr /></p:sp><p:sp><p:nvSpPr><p:cNvPr id=\"3\" name=\"Notes Placeholder 2\" /><p:cNvSpPr><a:spLocks noGrp=\"1\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:cNvSpPr><p:nvPr><p:ph type=\"body\" idx=\"1\" /></p:nvPr></p:nvSpPr><p:spPr /><p:txBody><a:bodyPr xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:lstStyle xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:p xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:r><a:rPr lang=\"en-US\" dirty=\"0\" /><a:t>Hey there!</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:cNvPr id=\"4\" name=\"Slide Number Placeholder 3\" /><p:cNvSpPr><a:spLocks noGrp=\"1\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:cNvSpPr><p:nvPr><p:ph type=\"sldNum\" sz=\"quarter\" idx=\"5\" /></p:nvPr></p:nvSpPr><p:spPr /><p:txBody><a:bodyPr xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:lstStyle xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /><a:p xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:fld id=\"{8E72DC8C-08B2-4C1F-8F46-48208154C347}\" type=\"slidenum\"><a:rPr lang=\"en-US\" smtClean=\"0\" /><a:t>1</a:t></a:fld><a:endParaRPr lang=\"en-US\" /></a:p></p:txBody></p:sp></p:spTree><p:extLst><p:ext uri=\"{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}\"><p14:creationId xmlns:p14=\"http://schemas.microsoft.com/office/powerpoint/2010/main\" val=\"3488005250\" /></p:ext></p:extLst></p:cSld><p:clrMapOvr xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\"><a:masterClrMapping xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" /></p:clrMapOvr>"
                }
            }

            return(comments.AsReadOnly());
        }
예제 #2
0
 public static void SlidesCount(string filePath, int numberOfSlides)
 {
     using (PresentationDocument document = PresentationDocument.Open(filePath, false))
     {
         SlideIdList slideIdList = document.PresentationPart.Presentation.SlideIdList;
         Assert.AreEqual(numberOfSlides, slideIdList.Count());
     }
 }
예제 #3
0
        public ActionResult DownLoadATCPPT(int ATSID)
        {
            string ExportFileName = "test.pptx";

            try
            {
                System.IO.File.Copy(Server.MapPath("~/ATSchedule/") + "Sample.pptx", Server.MapPath("~/ATSchedule/") + "SampleTemp.pptx", true);

                using (PresentationDocument prstDoc = PresentationDocument.Open(Server.MapPath("~/ATSchedule/") + "SampleTemp.pptx", true))
                {
                    using (tsmc14BDataContext db = new tsmc14BDataContext())
                    {
                        var ATSLast = db.vw_ATScheduleLastHistory.Where(x => x.ATSID == ATSID).SingleOrDefault();

                        if (ATSLast != null)
                        {
                            string ATSFolderString = Server.MapPath("~/ATSchedule/") + ATSID + "/" + ATSLast.FolderName;

                            System.IO.DirectoryInfo ATSFolder = new System.IO.DirectoryInfo(ATSFolderString);

                            if (ATSFolder.Exists)
                            {
                                FileInfo[] ATSFiles = ATSFolder.GetFiles();

                                for (int i = 0; i < ATSFiles.Count(); i++)
                                {
                                    string imgId = "rId" + ATSFiles[i].Name;
                                    Slide  S     = InsertNewSlide(prstDoc, i, imgId, ATSFiles[i]);
                                    InsertImageInLastSlide(S, ATSFiles[i].FullName, "image/png");
                                }
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }

                    SlideIdList slideIdList = prstDoc.PresentationPart.Presentation.SlideIdList;
                    SlideId     slideId     = slideIdList.ChildElements[slideIdList.Count() - 1] as SlideId;
                    string      slideRelId  = slideId.RelationshipId;
                    slideIdList.RemoveChild(slideId);
                    SlidePart slidePart = prstDoc.PresentationPart.GetPartById(slideRelId) as SlidePart;
                    prstDoc.PresentationPart.DeletePart(slidePart);

                    prstDoc.PresentationPart.Presentation.Save();
                    return(File(Server.MapPath("~/ATSchedule/") + "SampleTemp.pptx", "application/mspowerpoint", ExportFileName));
                }
            }
            catch (Exception ex)
            {
                MemoryStream fs = new MemoryStream();
                TextWriter   tx = new StreamWriter(fs);
                tx.WriteLine(ex.Message);
                tx.Flush();
                return(File(fs.ToArray(), "text/text", "error.txt"));
            }
        }