Add date on Presentations (Open XML SDK) on C#
Home › Forums › Open-Xml-Sdk › Add date on Presentations (Open XML SDK) on C#
This topic contains 0 replies, has 1 voice, and was last updated by cms9651 6 years, 4 months ago.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
July 25, 2018 at 10:42 am #7587
Hi all.
With the code-behind below I add the date on existing PowerPoint.
This code working and in the first slide the date is added, but it’s possible customize the point on the page where to insert this date? The font and size ?
This is current output:
Thank you in advance for help.
string fileName = @"C:\\inetpub\\wwwroot\\aspnet\\Template\\01_FOCUS.pptx"; using (PresentationDocument oPDoc = PresentationDocument.Open(fileName, true)) { PresentationPart oPPart = oPDoc.PresentationPart; SlideIdList slideIdList = oPPart.Presentation.SlideIdList; SlidePart sp = slideIdList.ChildElements .Cast<SlideId>() .Select(x => oPPart.GetPartById(x.RelationshipId)) .Cast<SlidePart>().First(); AddDateToSlidePart(sp); } public static void AddDateToSlidePart(SlidePart slidePart1) { Slide slide1 = slidePart1.Slide; CommonSlideData commonSlideData1 = slide1.GetFirstChild<CommonSlideData>(); ShapeTree shapeTree1 = commonSlideData1.GetFirstChild<ShapeTree>(); DocumentFormat.OpenXml.Presentation.Shape shape1 = new DocumentFormat.OpenXml.Presentation.Shape(); DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties nonVisualShapeProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties(); DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties nonVisualDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties() { Id = (UInt32Value)4U, Name = "Date Placeholder 3" }; DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties(); DocumentFormat.OpenXml.Drawing.ShapeLocks shapeLocks1 = new DocumentFormat.OpenXml.Drawing.ShapeLocks() { NoGrouping = true }; nonVisualShapeDrawingProperties1.Append(shapeLocks1); ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties(); PlaceholderShape placeholderShape1 = new PlaceholderShape() { Type = PlaceholderValues.DateAndTime, Size = PlaceholderSizeValues.Half, Index = (UInt32Value)10U }; applicationNonVisualDrawingProperties1.Append(placeholderShape1); nonVisualShapeProperties1.Append(nonVisualDrawingProperties1); nonVisualShapeProperties1.Append(nonVisualShapeDrawingProperties1); nonVisualShapeProperties1.Append(applicationNonVisualDrawingProperties1); DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties1 = new DocumentFormat.OpenXml.Presentation.ShapeProperties(); DocumentFormat.OpenXml.Presentation.TextBody textBody1 = new DocumentFormat.OpenXml.Presentation.TextBody(); DocumentFormat.OpenXml.Drawing.BodyProperties bodyProperties1 = new DocumentFormat.OpenXml.Drawing.BodyProperties(); DocumentFormat.OpenXml.Drawing.ListStyle listStyle1 = new DocumentFormat.OpenXml.Drawing.ListStyle(); DocumentFormat.OpenXml.Drawing.Paragraph paragraph1 = new DocumentFormat.OpenXml.Drawing.Paragraph(); DocumentFormat.OpenXml.Drawing.Field field1 = new DocumentFormat.OpenXml.Drawing.Field() { Id = "{528B97E8-8E4B-4D32-BA17-4F287283DFD6}", Type = "datetime1" }; DocumentFormat.OpenXml.Drawing.RunProperties runProperties1 = new DocumentFormat.OpenXml.Drawing.RunProperties() { Language = "it-IT" }; DocumentFormat.OpenXml.Drawing.Text text1 = new DocumentFormat.OpenXml.Drawing.Text(); text1.Text = DateTime.Now.ToString("dd/mm/yyyy"); field1.Append(runProperties1); field1.Append(text1); DocumentFormat.OpenXml.Drawing.EndParagraphRunProperties endParagraphRunProperties1 = new DocumentFormat.OpenXml.Drawing.EndParagraphRunProperties() { Language = "it-IT" }; paragraph1.Append(field1); paragraph1.Append(endParagraphRunProperties1); textBody1.Append(bodyProperties1); textBody1.Append(listStyle1); textBody1.Append(paragraph1); shape1.Append(nonVisualShapeProperties1); shape1.Append(shapeProperties1); shape1.Append(textBody1); shapeTree1.Append(shape1); }
-
AuthorPosts
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.