GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — No. of columns are wrong in some table objects · Issue #852 · python-openxml/python-docx

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

New issue
Copy link
New issue
Copy link
Open
Open
No. of columns are wrong in some table objects#852
Copy link
Labels
table

Description

@BHAUTIK04
BHAUTIK04
opened on Aug 4, 2020
Issue body actions

@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

Activity

  1. scanny
    added
    table
    on Dec 27, 2020
  2. unresto commented on Jul 8, 2021

    @unresto
    unresto
    on Jul 8, 2021
    More actions

    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

  3. tonal commented on Feb 21, 2023

    @tonal
    tonal
    on Feb 21, 2023
    More actions

    try #881 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    table

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.