public ToxySlide Parse(int slideIndex) { if (!File.Exists(Context.Path)) { throw new FileNotFoundException("File " + Context.Path + " is not found"); } using (PresentationDocument ppt = PresentationDocument.Open(Context.Path, false)) { // Get the relationship ID of the first slide. PresentationPart part = ppt.PresentationPart; DocumentFormat.OpenXml.OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements; if (slideIds.Count - 1 < slideIndex) { throw new ArgumentOutOfRangeException(string.Format("This file only contains {0} slide(s).", slideIds.Count)); } string relId = (slideIds[slideIndex] as SlideId).RelationshipId; relId = (slideIds[slideIndex] as SlideId).RelationshipId; // Get the slide part from the relationship ID. SlidePart slide = (SlidePart)part.GetPartById(relId); var tslide = Parse(slide); return(tslide); } }
public ToxySlideshow Parse() { if (!File.Exists(Context.Path)) { throw new FileNotFoundException("File " + Context.Path + " is not found"); } ToxySlideshow ss = new ToxySlideshow(); using (PresentationDocument ppt = PresentationDocument.Open(Context.Path, false)) { // Get the relationship ID of the first slide. PresentationPart part = ppt.PresentationPart; DocumentFormat.OpenXml.OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements; for (int index = 0; index < slideIds.Count; index++) { string relId = (slideIds[index] as SlideId).RelationshipId; relId = (slideIds[index] as SlideId).RelationshipId; // Get the slide part from the relationship ID. SlidePart slide = (SlidePart)part.GetPartById(relId); var tslide = Parse(slide); ss.Slides.Add(tslide); } } return(ss); }
public static void GetSlideIdAndText(out string sldText, string docName, int index) { using (DocumentFormat.OpenXml.Packaging.PresentationDocument ppt = DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(docName, false)) { // Get the relationship ID of the first slide. DocumentFormat.OpenXml.Packaging.PresentationPart part = ppt.PresentationPart; DocumentFormat.OpenXml.OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements; string relId = (slideIds[index] as DocumentFormat.OpenXml.Presentation.SlideId).RelationshipId; // Get the slide part from the relationship ID. DocumentFormat.OpenXml.Packaging.SlidePart slide = (DocumentFormat.OpenXml.Packaging.SlidePart)part.GetPartById(relId); // Build a StringBuilder object. System.Text.StringBuilder paragraphText = new System.Text.StringBuilder(); // Get the inner text of the slide: System.Collections.Generic.IEnumerable <DocumentFormat.OpenXml.Drawing.Text> texts = slide.Slide.Descendants <DocumentFormat.OpenXml.Drawing.Text>(); foreach (DocumentFormat.OpenXml.Drawing.Text text in texts) { paragraphText.Append(text.Text); } sldText = paragraphText.ToString(); } }
public static string[] GetAllTextInSlide(DocumentFormat.OpenXml.Packaging.PresentationDocument presentationDocument, int slideIndex) { // Verify that the presentation document exists. if (presentationDocument == null) { throw new System.ArgumentNullException("presentationDocument"); } // Verify that the slide index is not out of range. if (slideIndex < 0) { throw new System.ArgumentOutOfRangeException("slideIndex"); } // Get the presentation part of the presentation document. DocumentFormat.OpenXml.Packaging.PresentationPart presentationPart = presentationDocument.PresentationPart; // Verify that the presentation part and presentation exist. if (presentationPart != null && presentationPart.Presentation != null) { // Get the Presentation object from the presentation part. DocumentFormat.OpenXml.Presentation.Presentation presentation = presentationPart.Presentation; // Verify that the slide ID list exists. if (presentation.SlideIdList != null) { // Get the collection of slide IDs from the slide ID list. DocumentFormat.OpenXml.OpenXmlElementList slideIds = presentation.SlideIdList.ChildElements; // If the slide ID is in range... if (slideIndex < slideIds.Count) { // Get the relationship ID of the slide. string slidePartRelationshipId = (slideIds[slideIndex] as DocumentFormat.OpenXml.Presentation.SlideId).RelationshipId; // Get the specified slide part from the relationship ID. DocumentFormat.OpenXml.Packaging.SlidePart slidePart = (DocumentFormat.OpenXml.Packaging.SlidePart)presentationPart.GetPartById(slidePartRelationshipId); // Pass the slide part to the next method, and // then return the array of strings that method // returns to the previous method. return(GetAllTextInSlide(slidePart)); } } } // Else, return null. return(null); }
public SlideLayoutPart GetSlideLayoutPart(int _slideLayoutIndex, SlideMasterPart slideMasterPart) { if (slideMasterPart != null && slideMasterPart.SlideMaster != null) { SlideMaster slideMaster = slideMasterPart.SlideMaster; if (slideMaster.SlideLayoutIdList != null) { DocumentFormat.OpenXml.OpenXmlElementList slideIds = slideMaster.SlideLayoutIdList.ChildElements; // If the slide ID is in range... if (_slideLayoutIndex < slideIds.Count) { // Get the relationship ID of the slide. string slidePartRelationshipId = (slideIds[_slideLayoutIndex] as SlideLayoutId).RelationshipId; return((SlideLayoutPart)slideMasterPart.GetPartById(slidePartRelationshipId)); // Get the specified slide part from the relationship ID. } } } return(null); }
/// <summary> /// Hàm lấy SlidePart /// </summary> /// <param name="_slideIndex"></param> /// <returns></returns> public SlidePart GetSlidePart(int _slideIndex) { if (Utils.presentationPart != null && Utils.presentationPart.Presentation != null) { Presentation presentation = Utils.presentationPart.Presentation; if (presentation.SlideIdList != null) { DocumentFormat.OpenXml.OpenXmlElementList slideIds = presentation.SlideIdList.ChildElements; // If the slide ID is in range... if (_slideIndex < slideIds.Count) { // Get the relationship ID of the slide. string slidePartRelationshipId = (slideIds[_slideIndex] as SlideId).RelationshipId; // Get the specified slide part from the relationship ID. return((SlidePart)Utils.presentationPart.GetPartById(slidePartRelationshipId)); } } } return(null); }