C# 在C上的演示文稿(OpenXMLSDK)上添加日期#
我的推荐信是 使用下面的代码,我在现有PowerPoint上添加日期 这段代码正常工作,并且在第一张幻灯片中添加了日期,但是可以自定义页面上插入此日期的位置?字体和大小 这是电流输出: 事先谢谢你的帮助C# 在C上的演示文稿(OpenXMLSDK)上添加日期#,c#,powerpoint,openxml,C#,Powerpoint,Openxml,我的推荐信是 使用下面的代码,我在现有PowerPoint上添加日期 这段代码正常工作,并且在第一张幻灯片中添加了日期,但是可以自定义页面上插入此日期的位置?字体和大小 这是电流输出: 事先谢谢你的帮助 string fileName = @"C:\\inetpub\\wwwroot\\aspnet\\Template\\01_FOCUS.pptx"; using (PresentationDocument oPDoc = PresentationDocument.Open(fileName
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);
}
string fileName=@“C:\\inetpub\\wwwroot\\aspnet\\Template\\01\u FOCUS.pptx”;
使用(PresentationDocument oPDoc=PresentationDocument.Open(文件名,true))
{
PresentationPart oPPart=oPDoc.PresentationPart;
slidedlist slidedlist=oPPart.Presentation.slidedlist;
SlidePart sp=slidedlist.ChildElements
.Cast()
.Select(x=>oPPart.GetPartById(x.RelationshipId))
.Cast().First();
AddDateToSlidePart(sp);
}
公共静态void AddDateToSlidePart(SlidePart slidePart1)
{
幻灯片1=幻灯片1。幻灯片;
CommonSlideData commonSlideData1=slide1.GetFirstChild();
ShapeTree shapeTree1=commonSlideData1.GetFirstChild();
DocumentFormat.OpenXml.Presentation.shape1=
新的DocumentFormat.OpenXml.Presentation.Shape();
DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties NonVisualShapeProperties 1=
新的DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties();
DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties NonVisualDrawingProperties 1=
新的DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties(){Id=(UInt32Value)4U,Name=“日期占位符3”};
DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties NonVisualShapeDrawingProperties 1=
新的DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties();
DocumentFormat.OpenXml.Drawing.ShapeLocks shapeLocks1=
新的DocumentFormat.OpenXml.Drawing.ShapeLocks(){NoGrouping=true};
非可视形状的绘图属性1.追加(shapeLocks1);
应用程序非可视化绘图属性应用程序非可视化绘图属性1=
新应用程序NonVisualDrawingProperties();
占位符形状占位符形状1=
新的占位符形状(){Type=PlaceholderValues.DateAndTime,Size=PlaceholderSizeValues.Half,Index=(uint32值)10U};
applicationNonVisualDrawingProperties1.Append(占位符形状1);
非可视ShapeProperties 1.追加(非可视绘图属性1);
非可视形状属性1.Append(非可视形状属性1);
非可视ShapeProperties 1.Append(应用程序非可视绘图属性1);
DocumentFormat.OpenXml.Presentation.ShapeProperties ShapeProperties 1=
新的DocumentFormat.OpenXml.Presentation.ShapeProperties();
DocumentFormat.OpenXml.Presentation.TextBody TextBody 1=
新的DocumentFormat.OpenXml.Presentation.TextBody();
DocumentFormat.OpenXml.Drawing.BodyProperties BodyProperties 1=
新的DocumentFormat.OpenXml.Drawing.BodyProperties();
DocumentFormat.OpenXml.Drawing.ListStyle listStyle1=
新的DocumentFormat.OpenXml.Drawing.ListStyle();
DocumentFormat.OpenXml.Drawing.paragraph1段落=
新的DocumentFormat.OpenXml.Drawing.paragration();
DocumentFormat.OpenXml.Drawing.field1=
新的DocumentFormat.OpenXml.Drawing.Field(){Id=“{528B97E8-8E4B-4D32-BA17-4F287283DFD6}”,Type=“datetime1”};
DocumentFormat.OpenXml.Drawing.RunProperties runProperties1=
新的DocumentFormat.OpenXml.Drawing.RunProperties(){Language=“it”};
DocumentFormat.OpenXml.Drawing.Text text1=
新的DocumentFormat.OpenXml.Drawing.Text();
text1.Text=DateTime.Now.ToString(“dd/mm/yyyy”);
字段1.追加(runProperties1);
字段1.追加(text1);
DocumentFormat.OpenXml.Drawing.EndParagraphRunProperties EndParagraphRunProperties 1=
新的DocumentFormat.OpenXml.Drawing.EndParagraphRunProperties(){Language=“it”};
第1段追加(字段1);
第1段。追加(EndParagraphRunProperties 1);
textBody1.Append(bodyProperties1);
textBody1.Append(listStyle1);
正文1.附加(第1段);
形状1.附加(非可视形状属性1);
shape1.Append(shapeproperties 1);
shape1.Append(textBody1);
shapeTree1.Append(shape1);
}
OpenXML SDK生产力工具(可从Microsoft网站下载)是您的朋友。当我需要这样做时,我: