Skip to content

No. of columns are wrong in some table objects #852

Open
@BHAUTIK04

Description

@BHAUTIK04

@scanny
I am using docx lib to parse my docx files, and in one of the file i found the issue for the table object. If i check the XML(document.xml) for the document it shows 3 gridCol node but in <w:tr> tag it show only two cells. And so when i loop through all the rows it is giving the wrong cell values. What can be the reason? If word document is wrong then how we can correct the document and if Something which we can do in the code.
GridCol tag code is given like this

<w:tblGrid>
    <w:gridCol w:w="1808"/>
    <w:gridCol w:w="8656"/>
    <w:gridCol w:w="8634"/>
  </w:tblGrid> 

Here is the <w:tr> xml

<w:tr w:rsidR="008B0C52" w:rsidRPr="00445981" w14:paraId="35CC8211" w14:textId="77777777" w:rsidTr="00D74CDB">
    <w:trPr>
      <w:gridAfter w:val="1"/>
      <w:cnfStyle w:val="100000000000" w:firstRow="1" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:oddVBand="0" w:evenVBand="0" w:oddHBand="0" w:evenHBand="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0"/>
      <w:wAfter w:w="8634" w:type="dxa"/>
    </w:trPr>
    <w:tc>
      <w:tcPr>
        <w:cnfStyle w:val="001000000000" w:firstRow="0" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:oddVBand="0" w:evenVBand="0" w:oddHBand="0" w:evenHBand="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0"/>
        <w:tcW w:w="1808" w:type="dxa"/>
        <w:tcBorders>
          <w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/>
          <w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>
          <w:bottom w:val="none" w:sz="0" w:space="0" w:color="auto"/>
          <w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>
        </w:tcBorders>
        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
      </w:tcPr>
      <w:p w14:paraId="22A73613" w14:textId="77777777" w:rsidR="008B0C52" w:rsidRPr="00445981" w:rsidRDefault="008B0C52" w:rsidP="008B0C52">
        <w:pPr>
          <w:pStyle w:val="ListParagraph"/>
          <w:numPr>
            <w:ilvl w:val="0"/>
            <w:numId w:val="1"/>
          </w:numPr>
          <w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
          <w:rPr>
            <w:rFonts w:cstheme="minorHAnsi"/>
          </w:rPr>
        </w:pPr>
      </w:p>
    </w:tc>
    <w:tc>
      <w:tcPr>
        <w:tcW w:w="8656" w:type="dxa"/>
        <w:tcBorders>
          <w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/>
          <w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>
          <w:bottom w:val="none" w:sz="0" w:space="0" w:color="auto"/>
          <w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>
        </w:tcBorders>
        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
      </w:tcPr>
      <w:p w14:paraId="03D24C79" w14:textId="77777777" w:rsidR="008B0C52" w:rsidRPr="00445981" w:rsidRDefault="008B0C52" w:rsidP="00D74CDB">
        <w:pPr>
          <w:pStyle w:val="ListParagraph"/>
          <w:ind w:left="0"/>
          <w:cnfStyle w:val="100000000000" w:firstRow="1" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:oddVBand="0" w:evenVBand="0" w:oddHBand="0" w:evenHBand="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0"/>
          <w:rPr>
            <w:rFonts w:cstheme="minorHAnsi"/>
            <w:b w:val="0"/>
            <w:bCs w:val="0"/>
          </w:rPr>
        </w:pPr>
        <w:r w:rsidRPr="00445981">
          <w:rPr>
            <w:rFonts w:cstheme="minorHAnsi"/>
          </w:rPr>
          <w:t>Firm: General information</w:t>
        </w:r>
      </w:p>
    </w:tc>
  </w:tr>

Code to loop through table rows.

for i in d.tables:
    print (i._column_count)
    for j in i.rows:
        for c in j.cells:
            print (c.text)
        break

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions