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 code
class 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; }