[Python] Can not get the text in ContentControl in Word by usting Python-docx

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    ContentControl Document

    I am new to the Python and coding. New I have a problem and need your help. I tried to read a docx document by using Python-docx, but all of the text I wanted were in the ContentControl. When I try to print the text of the paragraph with a ContentControl, error occurs.

    For exemple, I try to print the 1st paragraphe, using

    import docx
    doc= docx.Document("C:\ContentControl.docx")
    p=doc.paragraphs
    print(p[0].text)


    then I get an error like:

    UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 8: illegal multibyte sequence


    So what should I do to get the text in ContentControl? Thanks a lot for your help!

    Continue reading...

Compartilhe esta Página