Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C上的演示文稿(OpenXMLSDK)上添加日期#_C#_Powerpoint_Openxml - Fatal编程技术网

C# 在C上的演示文稿(OpenXMLSDK)上添加日期#

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

我的推荐信是

使用下面的代码,我在现有PowerPoint上添加日期

这段代码正常工作,并且在第一张幻灯片中添加了日期,但是可以自定义页面上插入此日期的位置?字体和大小

这是电流输出:

事先谢谢你的帮助

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网站下载)是您的朋友。当我需要这样做时,我:

  • 创建我想要的文档
  • 在适当的工具(本例中为PowerPoint)中打开它
  • 做一个小小的改变(弄脏文档,让PowerPoint相信它需要改变)
  • 保存结果
  • 对要查看的文档进行更改,并使用新名称保存结果
  • 打开OpenXML生产力工具并单击“比较文件”工具
  • 我强制保存(在步骤3/4中)的原因是,PowerPoint可以将其所有PowerPoint内容添加到我创建的文档中。第二次保存(步骤5)必须包含所有这些内容,因此我希望这两个文档尽可能接近—只有“我希望看到的文档更改”是这两个文档之间的区别

    在这一点上,您应该看到解决问题的方法。在使用OOXML时,该工具是必不可少的