Repository navigation
Table cells with form fields seem to be parsed incorrectly #689
Description
Hi,
Im using python-docx to extract info out of docx files. My code iterates over a 2 column table with where the first column is the "key" and the second column the "value".
However, cells which have word "form fields" in them are not included in the table, which results in an incorrect table setup. My table in word looks like this
Date 01-01-2019 (not a form field)
Initals A.B.
Name TestName
PC 111111
In the second column, all values are form fields except the first one. I have the following code to debug this:
for i in range(0,14):
print doc.tables[0]._cells[i].text
Which shows me:
Date
01-01-2019
Initials
Name
PC
...
So it seems that something goes wrong while parsing the form fields in the table and instead of inserting an empty field or a blank or whatever, it just moves on with the next cell and creates a corrupted table structure.
My questions
- Are there any plans for supporting form fields in the near future?
- Wouldn't it be better if the library throws an exception or somehow indicates something went wrong with parsing, instead of building a corrupted internal table state?
For reference, this is how a row looks like in XML without form fields:
<w:tc>
<w:tcPr>
<w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="1" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="001000000000"/>
<w:tcW w:type="dxa" w:w="1951"/>
</w:tcPr>
<w:p w14:paraId="42042D40" w14:textId="77777777" w:rsidR="008014F0" w:rsidRDefault="008014F0">
<w:r>
<w:t xml:space="preserve">Date </w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:type="dxa" w:w="6496"/>
</w:tcPr>
<w:p w14:paraId="3548CF69" w14:textId="64ED0FF3" w:rsidP="000D46F4" w:rsidR="008014F0" w:rsidRDefault="003A3175">
<w:pPr>
<w:tabs>
<w:tab w:pos="1760" w:val="left"/>
</w:tabs>
<w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="000000000000"/>
</w:pPr>
<w:r>
<w:t>17-4-2019</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
And this is how it looks like with a form field
<w:tr w14:paraId="7459588F" w14:textId="77777777" w:rsidR="00382944" w:rsidRPr="00A21D4E" w:rsidTr="00D85E3F">
<w:tc>
<w:tcPr>
<w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="1" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="001000000000"/>
<w:tcW w:type="dxa" w:w="1951"/>
</w:tcPr>
<w:p w14:paraId="552E8CDB" w14:textId="2A99DF2E" w:rsidR="00382944" w:rsidRDefault="00382944">
<w:r>
<w:t>Initials</w:t>
</w:r>
</w:p>
</w:tc>
<w:sdt>
<w:sdtPr>
<w:alias w:val="Initials"/>
<w:tag w:val="Initials"/>
<w:id w:val="-1231847748"/>
<w:placeholder>
<w:docPart w:val="5C7BC912E04B4694A18A39EF621426E0"/>
</w:placeholder>
<w:text/>
</w:sdtPr>
<w:sdtEndPr/>
<w:sdtContent>
<w:tc>
<w:tcPr>
<w:tcW w:type="dxa" w:w="6496"/>
</w:tcPr>
<w:p w14:paraId="75DE8320" w14:textId="17F2800A" w:rsidP="001B7C01" w:rsidR="00382944" w:rsidRDefault="003A3175" w:rsidRPr="001B7C01">
<w:pPr>
<w:cnfStyle w:evenHBand="0" w:evenVBand="0" w:firstColumn="0" w:firstRow="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastColumn="0" w:lastRow="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0" w:oddHBand="0" w:oddVBand="0" w:val="000000000000"/>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:t>P.J.</w:t>
</w:r>
</w:p>
</w:tc>
</w:sdtContent>
</w:sdt>
</w:tr>
Thanks
Activity