python-docx

Getting the List Numbers of List Items in docx file using Python-Docx

Getting the List Numbers of List Items in docx file using Python-Docx Question: When I am accessing paragraph text it does not include the numbering in a list. Current code: document = Document("C:/Foo.docx") for p in document.paragraphs: print(p.text) List in docx file: I am expecting: (1) The naturalization of both … (2) The naturalization of …

Total answers: 3

Trying to read a docx file using FastAPI and python-docx library: AttributeError: 'bytes' object has no attribute 'seek' error

Trying to read a docx file using FastAPI and python-docx library: AttributeError: 'bytes' object has no attribute 'seek' error Question: I’m using FastAPI (not async) and python-docx library, trying to read a docx file. I’m getting an error while trying to read the docx file. My code – @app.post(‘/translate_docx’, response_class=PlainTextResponse) def translateDocx(docFile: UploadFile = File(…), …

Total answers: 2

Closing a docx file if it's open

Closing a docx file if it's open Question: I’m working with docx files and to prevent the PermissionError: [Errno 13] Permission denied error, I tried to add os.close() in my code but as I saw, it doesn’t accept the file path, it accepts file descriptor as a parameter.So I tried that: file_path = ‘my file …

Total answers: 4

Python docx module ModuleNotFoundError

Python docx module ModuleNotFoundError Question: I am a windows 7 user with MS-Office 2016 and python 3.6. I recently found out that you can write word documents with python. I looked on how to do that I installed the docx module: pip install docx But whenever i try to import the docx module i get …

Total answers: 3

Replace String in XML while keeping function

Replace String in XML while keeping function Question: I’m trying to generate a Word document with data based on a template using python-docx. For the most part, I’ve managed to work out something. However, my document has some conditions that I am trying to fulfil, namely I need to generate certain data only in the …

Total answers: 1

How do I change Heading font face and size in python-docx?

How do I change Heading font face and size in python-docx? Question: I filed this as a python-docx issue: https://github.com/python-openxml/python-docx/issues/805 but was requested to open a discussion here. https://python-docx.readthedocs.io/en/latest/user/styles-using.html implies that I should be able to change Heading font styles like this: font = doc.styles[‘Heading 1’].font font.name = ‘Times New Roman’ font.size = docx.shared.Pt(16) But …

Total answers: 2

Can the Python .replace() function replace whole phrases?

Can the Python .replace() function replace whole phrases? Question: I’m a video editor trying to automate word docs of talent scripts into STR files for captions to speed up the process. Since each video is structured the same, the idea works pretty well. In the scripts, there are editing directions that I’m trying to remove …

Total answers: 2

How to extract image from table in MS Word document with docx library?

How to extract image from table in MS Word document with docx library? Question: I am working on a program that needs to extract two images from a MS Word document to use them in another document. I know where the images are located (first table in the document), but when I try to extract …

Total answers: 2

Make last paragraph – active pointer

Make last paragraph – active pointer Question: I am trying to write my research work in markdown, and it’s required by my institution to submit it in Word doc format. I decided to use python-docx package to automate this task. However, I am struggling with some specific task, like adding data to end of the …

Total answers: 1