wordpress hit counter
Re: Tables in docx - Open XML SDK 2.0 - Development Tools - OpenXML Developer

Re: Tables in docx

Development Tools

Discussions about working with Open XML using a wide range of development tools

Tables in docx

  • rated by 0 users
  • This post has 4 Replies |
  • 4 Followers
  • hi everyone,

     

    i'm new in the sdk/docx world but i ran into a problem and i can't find a solution for it.

     

    I'm usin sdk 2.0 in a wpf c# .net4.0 project and the task in hands is to create a docx file( in word 2010 in my case) with fields in order to replace that fileds with data.

    The replace is made in c#, using regex and everything is ok... until the point i inserted a table with some fields inside.

    When i execute method Validate of the OpenXmlValidator class i get 6 errors, all related with the table (described bellow)

     

    The 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:firstRow' attribute is not declared.

    The 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:lastRow' attribute is not declared.

    The 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:firstColumn' attribute is not declared.

    The 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:lastColumn' attribute is not declared.

    The 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:noHBand' attribute is not declared.

    The 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:noVBand' attribute is not declared.

     

    i narrow the problem to the table (a simple 1row x 1column emplty table9 will produce the same errors.

     

    word2010 opens the docx file with no problems.

     

    Can anyone help me with this?

     

    Thanks

  • Hi,

    You said that "The replace is made in C#, using regex".  Are you doing a regex replace directly on the XML?  This is an incorrect approach.  You need to either use an XML parser (XmlDocument, LINQ to XML) to modify the XML tree, or you need to use the strongly typed OM of the Open XML SDK 2.0 to modify the XML tree.  In modifying the tree, you need to make sure that you are modifying the tree exactly per the spec.  It is not hard, but there is no short-cut.

    -Eric

  • Just replying in case others come across this thread (the only reference to this issue I found on Google/Bing).

    I too was getting the message "The 'schemas.openxmlformats.org/.../main:firstRow& attribute is not declared."  for documents I created using Word or the SDK in my application code.

    Initially I validated using the Open XML SDK 2.0 Productivty Tool for Microsoft Office. The default Validation setting for this tools is Office 2007 - when changing to Office 2010 the validation message disappears.

    Working from this, I assumed you can set the validation option for OpenXmlValidator(), and you can:

    new OpenXmlValidator(DocumentFormat.OpenXml.FileFormatVersions.Office2010);

    Hope this helps (albeit months after Nuno's query)

  • How do I set this for the Powersheel PowerTool 2.2 commandlet? Confirm-OpenXMLValid

  • There is currently no option in the cmdlet, but it would be easy enough to add.

Page 1 of 1 (5 items)