Skip to content

Getting an empty string from hyperlink text in table cell #304

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

Closed
lseongjoo opened this issue Jun 21, 2016 · 3 comments
Closed

Getting an empty string from hyperlink text in table cell #304

lseongjoo opened this issue Jun 21, 2016 · 3 comments

Comments

@lseongjoo
Copy link

lseongjoo commented Jun 21, 2016

When extracting text from hyperlink in table cell, below either cell.text or paragraphs in cell

for cell in row.cells:
    print(cell.text) # if hyperlink, empty
    cell_text = ''    
    for p in cell.paragraphs:
        cell_text += p.text # if hyperlink, empty
    print(cell_text, end=' ')
@q210
Copy link

q210 commented Sep 22, 2017

I too stumbled into this problem.
Sadly it's not that easy to fix ( reasons are explained here - #377 (comment) ).

AFAIK there is some progress on this in the issue #85 and official patch will be released eventually, but if you need this working right now and content only getting text from hyperlinks (without address part), you can install package with this quick and dirty hack q210@336ed9f from my own fork (based on patch proposed by Brad-Python in #85 )

pip command is:
pip install git+git://github.com/q210/python-docx.git@336ed9fed27ff0460b674d91ba1646ded9cecb59

P.S. I'll copy this answer to relevant SO questions and other similar issues just so people googling it in the future will spend less time understanding the problem than I did yesterday.

@Tuhin-thinks
Copy link

I suggest you can better select the piece of text and press ctrl+shift+F9
All hyper links will be removed and will display the plain text(Display text)

@scanny
Copy link
Contributor

scanny commented Sep 28, 2023

Paragraph.text will include the text of hyperlinks in the forthcoming v1.0 due out in a week or so.

@scanny scanny closed this as completed Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants