Ejemplo n.º 1
0
 public int CountSlide()
 {
     using (PresentationDocument ppt = PresentationDocument.Open(HttpContext.Current.Server.MapPath(folder), true))
     {
         PresentationPart   part     = ppt.PresentationPart;
         OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;
         ppt.Close();
         return(slideIds.Count());
     }
 }
Ejemplo n.º 2
0
        private static void InsertNameAndDate(string pptxPath, string insertName, string insertDate)
        {
            using (PresentationDocument ppt = PresentationDocument.Open(pptxPath, true))
            {
                if (ppt == null)
                {
                    throw new ArgumentNullException("presentationDocument");
                }

                PresentationPart   part     = ppt.PresentationPart;
                OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;

                for (int index = 0; index < slideIds.Count(); index++)
                {
                    // スライドを取得する
                    string    relId = (slideIds[index] as SlideId).RelationshipId;
                    SlidePart slide = (SlidePart)part.GetPartById(relId);

                    if (slide != null)
                    {
                        ShapeTree tree = slide.Slide.CommonSlideData.ShapeTree;

                        //1番目の<s:sp>を取得する
                        Shape shape = tree.GetFirstChild <Shape>();

                        if (shape != null)
                        {
                            TextBody textBody = shape.TextBody;
                            IEnumerable <Drawing2.Paragraph> paragraphs = textBody.Descendants <Drawing2.Paragraph>();

                            foreach (Drawing2.Paragraph paragraph in paragraphs)
                            {
                                foreach (var text in paragraph.Descendants <Drawing2.Text>())
                                {
                                    if (text.Text.Contains("様邸"))
                                    {
                                        text.Text = insertName + text.Text;
                                    }
                                    else if (text.Text.Contains("年月日"))
                                    {
                                        text.Text = text.Text.Replace("年月日", insertDate);
                                    }
                                }
                            }
                        }
                        slide.Slide.Save();
                    }
                }
            }

            return;
        }