How to create a valid docx with a table using Open XML

So far every example I was able to find here or elsewhere (like https://stackoverflow.com/a/72016283/13831836) was a barebones code that creates something that may or may not be opened by MS Word, knowing Microsoft’s attitude towards enforcing standards, but is not a valid document. And by valid I mean:

  • Libre Office opens it and displays more or less correctly (a must)
  • Open Office opens it and displays more or less correctly (a must)
  • MS Open XML Productivity Tool validates it (nice to have)

document in question is rather simple, a short paragraph followed by a large table (600+ rows) followed by another short paragraph.

I attempted to fix errors displayed by Productivity Toolkit on my own, alas it turned out to be too difficult without knowing much more about the SDK and the format than I do. Most of the errors have to do with invalid children of a table, a row, etc., or missing Styles and so on, some of them I could fix with the help of internet search, but not all.

I am not against using libraries built on top of The Open XML SDK provided the license is right, but again I wasn’t able to find one that actually works yet.

  • 1

    I don’t really understand what you actually want from us? A sample of a table? if so why would it be better than the one you mentioned stackoverflow.com/a/72016283/13831836 ?!? so currently I am like „cool story, so what?“

    – 




  • @RandRandom I want to know the answer to the question “How to create a valid docx with a table using Open XML?” a sample of a code that does produce that would be one of the possible answers. A link to an article / guide teaching that would be another. I am sure there can be more possible answers. I hope that clarifies.

    – 

  • Microsoft Word is not OpenXml, but can read XML. I would first manually open Microsoft Word and using the File Open menu with Open XML option. See the results. Programming will only get you the same results as manually reading the file. If you are satisfied with the manual results I would use the Microsoft Word Interop Library and do the same you did manually.

    – 

  • @jdweng my question was about Open XML, not MS Word or Interop, but thanks for suggestion.

    – 

  • You said “Open Office opens it and displays more or less correctly (a must)”. Most people think MS Office is OpenXML and it isn’t.

    – 

Leave a Comment