rmboggs / DocxToSource

A multi-platform application that is able to generate dotnet source code based on OpenXml based documents.
MIT License
67 stars 10 forks source link

Generated code for Table in Powerpoint does not open file correctly #9

Open raymrdc opened 2 years ago

raymrdc commented 2 years ago

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);
rmboggs commented 2 years ago

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.

raymrdc commented 2 years ago

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

rmboggs commented 2 years ago

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

raymrdc commented 2 years ago

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 commented 1 year ago

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