Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BHAUTIK04 opened this issue Aug 4, 2020 · 2 comments
Open

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

BHAUTIK04 opened this issue Aug 4, 2020 · 2 comments
Labels

Comments

@BHAUTIK04
Copy link

BHAUTIK04 commented Aug 4, 2020

@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
@scanny scanny added the table label Dec 27, 2020
@unresto
Copy link

unresto commented Jul 8, 2021

I think this is similar to a problem i'm seeing where the number of gridCols is correct, but because the final row contains nothing the <w:tc> elements are omitted.

#564

@tonal
Copy link

tonal commented Feb 21, 2023

try #881 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants