python-docx

How do I delete particular pages from a DOCX file?

How do I delete particular pages from a DOCX file? Question: I have quite a large collection of DOCX documents, and I need to delete all but the first page in all of them. From what I have read, docx-python does not support this since it has no notion of pages. One option I have …

Total answers: 1

AtributeError: can't set attribute for python list property

AtributeError: can't set attribute for python list property Question: I’m working with the python-docx library from a forked version, and I’m having an issue with editing the elements list as it is defined as a property. # docx.document.Document @property def elements(self): return self._body.elements I tried to go with the solution mentioned here but the error …

Total answers: 2

How to extract text without tags (between br)?

How to extract text without tags (between br)? Question: I am trying to store headings and paragraphs into different arrays, i can’t manage with text between <br>. Here’s my HTML code and python below: <p><strong>W Ognisku</strong><br>W londyńskim Ognisku Polskim odbyło się spotkanie z brytyjskim historykiem<br><br><strong>10 lat polskiej szkoły sobotniej Copernicus </strong><br>W Wielkiej Brytanii <br><br><strong>IV Bieg …

Total answers: 2

Python error :OSError: [Errno 9] Bad file descriptor

Python error :OSError: [Errno 9] Bad file descriptor Question: I have wanted to transform DOCX file using docx library. Everytime I run it i get this error OSError: [Errno 9] Bad file descriptor The code is : from docx import Document def bionify(path_to_text: str) -> None: doc = Document(path_to_text) new_doc = Document() all_paragraphs = doc.paragraphs …

Total answers: 2

Replace JSON values in a doc python

Replace JSON values in a doc python Question: I want to replace a json values in a doc using python, I tried this code using a list, but it didn’t work with my json form. This is my code : from docx import Document #open the document doc=Document(‘./test.docx’) Dictionary = {"#prenom#": "Dina", "#nom#":"Robert"} for i …

Total answers: 1

How do I change the font color in the cell under the table in the Word document?

How do I change the font color in the cell under the table in the Word document? Question: I tried to use document.styles[‘Normal’].font.color.rgb = RGBColor(255, 0, 255) to change the font color in the table, but it made all of the colors change in the fonts of the table. Am I missing something? import docx …

Total answers: 1

How to implement re.IGNORECASE method in grep of python-docx

How to implement re.IGNORECASE method in grep of python-docx Question: I would like to make grep function with python-docx. from docx import Document files = glob.glob("Folders/*.docx") fetchWord = "sample" for file in files: document = Document(file) count = 0 for para in document.paragraphs: if para.text.find(fetchWord) > -1: print(file + ":" + "Line" + str(count) + …

Total answers: 1

Working with picture in AlternateContent tag

Working with picture in AlternateContent tag Question: I need to move an element from one document to another by using python-docx. The element is AlternateContent which represents shapes and figures in Office Word, the issue here is that one of the elements contains an image like this: <AlternateContent> <Choice Requires="wpc"> <drawing> <inline distT="0" distB="0" distL="0" …

Total answers: 1

packageError py2exe and python-docx

packageError py2exe and python-docx Question: I have a program written in python that reads certain datafiles and produces a docx file and a pdf file. Now I need to distribute this, so I created a GUI and found that with py2exe I can create the .exe that I should then be able to distribute. The …

Total answers: 1