Beispiel #1
0
        private void GetShapeVisualProperties(SlidePart slidePart, Picture picture)
        {
            base.VisualShapeProp = new PPTVisualPPTShapeProp();

            if (picture.ShapeProperties.Transform2D != null)
            {
                base.VisualShapeProp.Extents = picture.ShapeProperties.Transform2D.Extents;
                base.VisualShapeProp.Offset  = picture.ShapeProperties.Transform2D.Offset;
                string    rId       = picture.BlipFill.Blip.Embed.Value;
                ImagePart imagePart = (ImagePart)slidePart.GetPartById(rId);
                FileExtension = imagePart.Uri.OriginalString.Substring(imagePart.Uri.OriginalString.LastIndexOf(".") + 1).ToLower();
            }
            else
            {
                ShapeTree shapeTree =
                    slidePart.SlideLayoutPart.SlideLayout.CommonSlideData.ShapeTree;
                if (shapeTree != null)
                {
                    var layoutShape = shapeTree.GetFirstChild <Picture>();
                    if (layoutShape.ShapeProperties.Transform2D != null)
                    {
                        VisualShapeProp.Extents = layoutShape.ShapeProperties.Transform2D.Extents;
                        VisualShapeProp.Offset  = layoutShape.ShapeProperties.Transform2D.Offset;
                    }
                }
                //base.SetSlideLayoutVisualShapeProperties(slidePart,picture);
            }
            DocumentFormat.OpenXml.Drawing.EffectList effectList = picture.ShapeProperties.GetFirstChild <DocumentFormat.OpenXml.Drawing.EffectList>();
            if (effectList != null)
            {
                recalculatePropertiesWithEffect(effectList);
            }
        }
Beispiel #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;
        }
Beispiel #3
0
        /// <summary>
        /// Change the fill color of a shape, docName must have a filled shape as the first shape on the first slide.
        /// </summary>
        /// <param name="docName">path to the file</param>
        public static void SetPPTShapeColor(string docName)
        {
            using (PresentationDocument ppt = PresentationDocument.Open(docName, true))
            {
                // Get the relationship ID of the first slide.
                PresentationPart   part     = ppt.PresentationPart;
                OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;
                string             relId    = (slideIds[0] as SlideId).RelationshipId;

                // Get the slide part from the relationship ID.
                SlidePart slide = (SlidePart)part.GetPartById(relId);

                if (slide != null)
                {
                    // Get the shape tree that contains the shape to change.
                    ShapeTree tree = slide.Slide.CommonSlideData.ShapeTree;

                    // Get the first shape in the shape tree.
                    PShape shape = tree.GetFirstChild <PShape>();

                    if (shape != null)
                    {
                        // Get the style of the shape.
                        ShapeStyle style = shape.ShapeStyle;

                        // Get the fill reference.
                        FillReference fillRef = style.FillReference;

                        // Set the fill color to SchemeColor Accent 6;
                        fillRef.SchemeColor = new SchemeColor
                        {
                            Val = SchemeColorValues.Accent6
                        };

                        // Save the modified slide.
                        slide.Slide.Save();
                    }
                }
            }
        }
Beispiel #4
0
 private void SetConnectionShapeVisualProperties(SlidePart slidePart,
                                                 ConnectionShape connectionShape)
 {
     base.VisualShapeProp = new PPTVisualPPTShapeProp();
     if (connectionShape.ShapeProperties.Transform2D != null)
     {
         base.VisualShapeProp.Extents = connectionShape.ShapeProperties.Transform2D.Extents;
         base.VisualShapeProp.Offset  = connectionShape.ShapeProperties.Transform2D.Offset;
     }
     else
     {
         ShapeTree       shapeTree = slidePart.SlideLayoutPart.SlideLayout.CommonSlideData.ShapeTree;
         ConnectionShape layoutShape;
         if (shapeTree != null)
         {
             layoutShape = shapeTree.GetFirstChild <ConnectionShape>();
             if (layoutShape.ShapeProperties.Transform2D != null)
             {
                 base.VisualShapeProp.Extents = layoutShape.ShapeProperties.Transform2D.Extents;
                 base.VisualShapeProp.Offset  = layoutShape.ShapeProperties.Transform2D.Offset;
             }
         }
     }
 }