DocxToSource icon indicating copy to clipboard operation
DocxToSource copied to clipboard

Generated code for Table in Powerpoint does not open file correctly

Open raymrdc opened this issue 3 years ago • 5 comments

Using generated code for Table in Powerpoint, the generated powerpoint will encounter "Powerpoint found a problem with content. Powerpoint can attempt to repair the presentation"

Root cause: code for ExtensionList in Table->TableGrid->GridColumn is incorrect

Generated by DocxToSource

           A.Extension aExtension = new A.Extension();
            aExtension.Uri = "{9D8B030D-6E8A-4147-A177-3AD203B41FA5}"; 
            OpenXmlUnknownElement openXmlUnknownElement = new OpenXmlUnknownElement("a16", "colId", "http://schemas.microsoft.com/office/drawing/2014/main");
            openXmlUnknownElement.AddNamespaceDeclaration("a16", "http://schemas.microsoft.com/office/drawing/2014/main");
            aExtension.Append(openXmlUnknownElement);
            aExtensionList.Append(aExtension);
            
            A.Extension aExtension1 = new A.Extension();
            aExtension1.Uri = "{0D108BD9-81ED-4DB2-BD59-A6C34878D82A}";
            OpenXmlUnknownElement openXmlUnknownElement1 = new OpenXmlUnknownElement("a16", "rowId", "http://schemas.microsoft.com/office/drawing/2014/main");
            openXmlUnknownElement1.AddNamespaceDeclaration("a16", "http://schemas.microsoft.com/office/drawing/2014/main");
            openXmlUnknownElement1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main");
            aExtension1.Append(openXmlUnknownElement1);

But when using code generated by SDK Productivity Tool, the generated powerpoint opens correctly.

Generated by SDK Productivity Tool

            Extension extension1 = new Extension(){ Uri = "{9D8B030D-6E8A-4147-A177-3AD203B41FA5}" };
            OpenXmlUnknownElement openXmlUnknownElement1 = OpenXmlUnknownElement.CreateOpenXmlUnknownElement("<a16:colId xmlns:a16=\"http://schemas.microsoft.com/office/drawing/2014/main\" val=\"20005\" />");
            extension1.Append(openXmlUnknownElement1);

            Extension extension2 = new Extension(){ Uri = "{0D108BD9-81ED-4DB2-BD59-A6C34878D82A}" };
            OpenXmlUnknownElement openXmlUnknownElement2 = OpenXmlUnknownElement.CreateOpenXmlUnknownElement("<a16:rowId xmlns:a16=\"http://schemas.microsoft.com/office/drawing/2014/main\" xmlns:p14=\"http://schemas.microsoft.com/office/powerpoint/2010/main\" />");
            extension2.Append(openXmlUnknownElement2);

raymrdc avatar Dec 08 '21 11:12 raymrdc

Thanks for this. Do you happen to have a sample doc I can use for testing?

Also, I may move this bug to the Serialize.OpenXml.CodeGen project as that is the project responsible for creating the source code. That being said, i would be interested in seeing whether or not the latest version of the openxml sdk would use classes from the A16 namespace instead of the unknown element class. Regardless, the code being generated should use the OpenXmlUnknownElement.CreateOpenXmlUnknownElement method to create unknown elements instead of using the standard ctor.

rmboggs avatar Dec 11 '21 16:12 rmboggs

I couldn't upload the powerpoint file in a public site.

raymrdc avatar Dec 28 '21 11:12 raymrdc

If you can, give it another try with the latest source. I updated the Serialize.OpenXml.CodeGen library it uses to generate the correct create method for OpenXmlUnknownElement objects

rmboggs avatar Jan 29 '22 16:01 rmboggs

I tried using the latest codes. But the result is still the same as the previously generated version. Just checking if I got the correct version Serialize.OpenXml.CodeGen-bbbb75c586bcc8e633d9ee91627854d6d9fa1cf7.zip

Also, I'm only checking this portion ExtensionList in Table->TableGrid->GridColumn

raymrdc avatar Feb 07 '22 05:02 raymrdc

The error was recreated using the latest DocxToSource (Nov 14, 2022) and CodeGen (Dec 18, 2022) from Github. The OpenXML is version 2.20.0.

The error in Visual Studio is

Severity Code Description Error CS0619 'OpenXmlUnknownElement.CreateOpenXmlUnknownElement(string)' is obsolete: 'Use extension method CreateUnknownElement off of a part container'

Attached is a simple test file that reproduce the same issue on Slide 3. Test powerpoint file.pptx

raymrdc avatar Jul 13 '23 03:07 raymrdc