本文介绍了获取& quot; Powerpoint发现内容问题-...& quot;打开使用Open XML编辑的Powerpoint时发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用Open XML SDK将表插入到Powerpoint中,但是它发出错误,说"PowerPoint在Filename.pptx中发现内容有问题"。 PowerPoint可以尝试修复演示文稿。如果您信任此演示文稿的来源,请按点击修复。" 以下是我的代码 类&NBSP;的程序 { static void Main( string [] args) { 常量&NBSP;的串&NBSP;路径&NBSP;的 = @" C:\ UsersDocuments\PPTDemo \NewSlide.pptx" ; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的使用&NBSP;(&NBSP; DOC&NBSP;的 = &NBSP;的 PresentationDocument 。打开(路径, true )) ; { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; CreateTableInLastSlide(DOC); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;} &NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; } private static void CreateTableInLastSlide( PresentationDocument &NBSP; presentationDocument)&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;的 //&NBSP;获取&NBSP;所述&NBSP;介绍&NBSP;第二部分&NBSP;的&NBSP;所述&NBSP;介绍&NBSP;文件&NBSP; &NBSP;&NBSP; PresentationPart presentationPart = presentationDocument 。 PresentationPart; // Get  ; var slideIdList = presentationPart 。演示文稿。 SlideIdList; //  ;获取&NBSP;全部共个幻灯片&NBSP;第二部分&NBSP;的&NBSP;所述&NBSP;介绍&NBSP;文件&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;列表&NBSP;的 = &NBSP; slideIdList的。 ChildElements &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;的 演员LT;的 SlideId >()&NBSP ; 选择(X&NBSP;的 => &NBSP; presentationPart的。 GetP artById(X的 RelationshipId。))&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; 。 Cast< SlidePart >(); //  ;获取&NBSP;的&NBSP;最后&NBSP;幻灯片&NBSP;部分&NBSP;的&NBSP;的&NBSP;呈现&NBSP;文档&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; var tableSlidePart = ( SlidePart )列出。 Last(); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的 //声明&NBSP ;和&NBSP;实例&NBSP;所述&NBSP;图形&NBSP;框架&NBSP;的&NBSP;所述&NBSP;新&NBSP;滑动 &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; P 的 graphicFrame &NBSP; graphicFrame&NBSP;的。= tableSlidePart 。幻灯片。 CommonSlideData 。 ShapeTree 。 AppendChild( new P 。 GraphicFrame ()); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的 //&NBSP;指定&NBSP;所述&NBSP ;需&NBSP;框架&NBSP;属性&NBSP;的&NBSP;所述&NBSP; graphicFrame&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的 ApplicationNonVisualDrawingPropertiesExtension &NBSP; applicationNonVisualDrawingPropertiesExtension&NBSP;的 = &NBSP;的新&NBSP ;的 ApplicationNonVisualDrawingPropertiesExtension ()&NBSP; {&NBSP;乌里&NBSP;的 = &NBSP;的" {D42A27DB-BD31-4B8C-83A1-F6EECF244321}" &NBSP;}; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; P14的 的 ModificationId modificationId1 = new   ; P14 。 ModificationId () { Val = 3229994563U }; modificationId1 。 AddNamespaceDeclaration(" p14" , " http://schemas.microsoft.com/office/powerpoint/2010/main" ); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; applicationNonVisualDrawingPropertiesExtension的 追加(modificationId1); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; graphicFrame的 NonVisualGraphicFrameProperties&NBSP; = new P 。的 NonVisualGraphicFrameProperties &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;(的新&NBSP; A的 的 NonVisualDrawingProperties ()&NBSP; { Id = 5 , 名称 = &NBSP;的"表&NBSP; 1" &NBSP;},&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的新&NBSP; A的 NonVisualGraph icFrameDrawingProperties ( new A 。 GraphicFrameLocks () { NoGrouping = true &NBSP;}),&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的新&NBSP ;的 ApplicationNonVisualDrawingProperties (的新&NBSP;的 ApplicationNonVisualDrawingPropertiesExtensionList (applicationNonVisualDrawingPropertiesExtension))); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; graphicFrame的 转换 = new 转换( new A 。 抵消() { X = 1650609L , Y = 4343400L }, new A 。 范围() &NBSP; {&NBSP; CX&NBSP;的 = &NBSP;的 6096000L ,&NBSP; CY和NBSP;的 = 741680L }); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的 //&NBSP;指定&NBSP;所述&NBSP ; Griaphic&NBSP;的&NBSP;所述&NBSP;图形&NBSP;框架&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; graphicFrame的 图形&NBSP;的 = &NBSP;的新&NBSP; A 。 图形( new 一种的 的 GraphicData (GenerateTable())&NBSP; {&NBSP;乌里&NBSP;的 = " http://schemas.openxmlformats.org/drawingml/2006/table" }) ; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; presentationPart的 演示的 保存(); } private static A 。 表 GenerateTable() { string [,] tableSources = new string [,] { { " name" , " age"   ;}, { " Tom" , " 25"   ;}&NBSP;}; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的 //&NBSP;声明&NBSP;和&NBSP ;实例化 表 A 。 表 table = 新 A 。 表(); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的 //&NBSP;指定&NBSP;所述&NBSP ; required table properties for the nbsp; table A 的 tableProperties &NBSP; tableProperties&NBSP;的 = &NBSP; new A 。 TableProperties ()&NBSP; {&NBSP; FIRSTROW&NBSP;的 = &NBSP;的真,&NBSP; BandRow&NBSP; &NBSP; tableSources的 GetLength进行(的 0 ); 行 ++ )   ; { //&NBSP;实例化&NBSP;所述&NBSP;表&NBSP;排 &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; A 。 TableRow tableRow = new A 。 TableRow () { Height = 370840L }; for ( int column = 0 ;&NBSP;柱&NBSP;的< &NBSP; tableSources的 GetLength( 1 ); 列 ++ )   ; { tableRow 。追加(CreateTextCell(tableSources 。 GetValue(行, 列)。 ToString())); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;} &NBSP;&NBSP;&NBSP ; table 。 Append(tableRow); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;} &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; return table; } 解决方案 我注意到代码来自 如何将包含行的表添加到PowerPoint使用open xml 。我得到了和你一样的错误。 我使用Office2016,2013和2010进行了测试。使用这些代码插入表后,所有文件都被破坏了。 我很抱歉我修改了代码。 我正在尝试让一些高级工程师参与这个问题,这需要一些时间。非常感谢您的耐心。 此外,我建议您使用比较文件OpenXMLSDKTool生成你想要的代码。 抱歉给您带来不便,祝您有个愉快的一天! 问候, Celeste I am inserting a table into Powerpoint using Open XML SDK but it is throwing an error saying "PowerPoint found a problem with content in Filename.pptx. PowerPoint can attempt to repair the presentation. If you trust the source of this presentation , click repair."Below is my codeclass Program { static void Main(string[] args) { const string path = @"C:\UsersDocuments\PPTDemo\NewSlide.pptx"; using (PresentationDocument doc = PresentationDocument.Open(path, true)) { CreateTableInLastSlide(doc); } } private static void CreateTableInLastSlide(PresentationDocument presentationDocument) { // Get the presentation Part of the presentation document PresentationPart presentationPart = presentationDocument.PresentationPart; // Get the Slide Id collection of the presentation document var slideIdList = presentationPart.Presentation.SlideIdList; // Get all Slide Part of the presentation document var list = slideIdList.ChildElements .Cast<SlideId>() .Select(x => presentationPart.GetPartById(x.RelationshipId)) .Cast<SlidePart>(); // Get the last Slide Part of the presentation document var tableSlidePart = (SlidePart)list.Last(); //Declare and instantiate the graphic Frame of the new slide P.GraphicFrame graphicFrame = tableSlidePart.Slide.CommonSlideData.ShapeTree.AppendChild(new P.GraphicFrame()); // Specify the required Frame properties of the graphicFrame ApplicationNonVisualDrawingPropertiesExtension applicationNonVisualDrawingPropertiesExtension = new ApplicationNonVisualDrawingPropertiesExtension() { Uri = "{D42A27DB-BD31-4B8C-83A1-F6EECF244321}" }; P14.ModificationId modificationId1 = new P14.ModificationId() { Val = 3229994563U }; modificationId1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); applicationNonVisualDrawingPropertiesExtension.Append(modificationId1); graphicFrame.NonVisualGraphicFrameProperties = new P.NonVisualGraphicFrameProperties (new A.NonVisualDrawingProperties() { Id = 5, Name = "table 1" }, new A.NonVisualGraphicFrameDrawingProperties(new A.GraphicFrameLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new ApplicationNonVisualDrawingPropertiesExtensionList(applicationNonVisualDrawingPropertiesExtension))); graphicFrame.Transform = new Transform(new A.Offset() { X = 1650609L, Y = 4343400L }, new A.Extents() { Cx = 6096000L, Cy = 741680L }); // Specify the Griaphic of the graphic Frame graphicFrame.Graphic = new A.Graphic(new A.GraphicData(GenerateTable()) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/table" }); presentationPart.Presentation.Save(); } private static A.Table GenerateTable() { string[,] tableSources = new string[,] { { "name", "age" }, { "Tom", "25" } }; // Declare and instantiate table A.Table table = new A.Table(); // Specify the required table properties for the table A.TableProperties tableProperties = new A.TableProperties() { FirstRow = true, BandRow = true }; A.TableStyleId tableStyleId = new A.TableStyleId(); tableStyleId.Text = "{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}"; tableProperties.Append(tableStyleId); // Declare and instantiate tablegrid and colums A.TableGrid tableGrid1 = new A.TableGrid(); A.GridColumn gridColumn1 = new A.GridColumn() { Width = 3048000L }; A.GridColumn gridColumn2 = new A.GridColumn() { Width = 3048000L }; tableGrid1.Append(gridColumn1); tableGrid1.Append(gridColumn2); table.Append(tableProperties); table.Append(tableGrid1); for (int row = 0; row < tableSources.GetLength(0); row++) { // Instantiate the table row A.TableRow tableRow = new A.TableRow() { Height = 370840L }; for (int column = 0; column < tableSources.GetLength(1); column++) { tableRow.Append(CreateTextCell(tableSources.GetValue(row, column).ToString())); } table.Append(tableRow); } return table; } 解决方案 Hi,I notice the code is fromHow to add a table with rows to PowerPoint using open xml. I got the same error as you. And I tested with Office2016, 2013 and 2010. All the files are broken after inserting table with these code.I apologize that I failed to modify the code.I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.Besides, I suggest you compare files using OpenXMLSDKTool to generate code you want.Sorry for any inconvenience and have a nice day! Regards,Celeste 这篇关于获取& quot; Powerpoint发现内容问题-...& quot;打开使用Open XML编辑的Powerpoint时发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 04:30