Python Forum
Use module docx to get text from a file with a table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use module docx to get text from a file with a table
#1
I made a simple function to get text from .docx files. Works OK.

Now I have a file containing a text frame at the top, a little text and a big table.

I can't get the text from the table or the text frame. Any tips on how that might be achieved?

import docx

def getText(filename):
    print(len(doc.paragraphs))
    doc = docx.Document(filename)
    fullText = []
    for para in doc.paragraphs:
        fullText.append(para.text)
    return '\n'.join(fullText)

myfile = input('Enter the full path to the file you want ... ')
text = getText(myfile)
This only gets free-standing text, not text in the frame or the table.
.docx   table_Adverbs_ly.docx (Size: 7.32 KB / Downloads: 143)
Reply


Messages In This Thread
Use module docx to get text from a file with a table - by Pedroski55 - Aug-28-2022, 03:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 976 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Replace a text/word in docx file using Python Devan 4 3,654 Oct-17-2023, 06:03 PM
Last Post: Devan
  Color a table cell based on specific text Creepy 11 2,115 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 960 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,160 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  python-docx regex: replace any word in docx text Tmagpy 4 2,299 Jun-18-2022, 09:12 AM
Last Post: Tmagpy
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,741 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  How to perform DESC table sort on dates stored as TEXT type. hammer 7 2,266 Mar-15-2022, 01:10 PM
Last Post: hammer
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,076 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 7,899 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020