Word changing table cell width on load

Home Forums Open-Xml-PowerTools Word changing table cell width on load

This topic contains 2 replies, has 2 voices, and was last updated by  gamartin 7 years, 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4170

    gamartin
    Participant

    Eric:

    I am having an issue with the HtmlToWMLConverter and a table. The HTML table has 2 columns, each identified as style="width:50% !important;". If I step through the generation of the WML from the HTML, the table grid is generated properly with each column having the same width.

    However if I open the resulting file in Word, I get the following for the tblGrid element:

     <w:tblGrid>
            <w:gridCol w:w="5762"/>
            <w:gridCol w:w="4048"/>
          </w:tblGrid>

    To add to the problem, it appears to be content related. The “wider” the information in the right column, the narrower the left column.

    Do you think there is any way to get around this or is it truly Word being “smart” when opening the file? If I download the docx and view the XML, the widths are correct. The problem is if I open the document the column widths are adjusted. Obviously if I save it, it’s changed in the xml.

    I don’t think this is a converter issue, but more a Word issue.

    Any help is appreciated as always!

    Garth

    #4171

    Eric White
    Keymaster

    Hi Garth,

    Yes, you are absolutely correct, Word is being “smart” when opening the file. The issue is that the actual layout of the table is sometimes just a set of desired configurations, and Word will do whatever it wants to.

    The genesis of this issue is that it is quite possible to set up a table with invalid column widths with regards to content, and Word then does whatever it wants with the table.

    I have seen this, but it has never become important to me to fully understand the algorithm that Word uses. Further, I think it likely that different versions of Word behave differently, but I don’t know.

    Best, Eric

    #4178

    gamartin
    Participant

    Thanks again Eric. I was able to get it to do what I needed by changing the call to GetTableProperties, passing in the settings. I added a setting to respect the column widths (since I know they are going to be valid – 50% each) and if set then the GetTableProperties adds a w:tblLayout type="fixed" element to the TableProperties element. In playing around with it, I found that Word added that element if I went into the table options and de-selected the “Automatically resize to fit contents” option.

    A bit of a hack, but it works for me. I was initially thinking that I could do it in the GetTableGrid method if the width properties had the important declaration, but it appears to be too late in the game…

    Thanks again.

    Garth

    • This reply was modified 7 years, 10 months ago by  gamartin.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.