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

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

I'm trying to extract emails, and I'm getting a TypeError

I'm trying to extract emails, and I'm getting a TypeError Question: I’m attempting to take emails from 500 word documents, and use findall to extract them into excel. This is the code I have so far: import pandas as pd from docx.api import Document import os import re os.chdir(‘C:\Users\user1\test’) path = ‘C:\Users\user1\test’ output_path = ‘C:\Users\user1\test2’ …

Total answers: 1

How do I extract tables from word via table titles?

How do I extract tables from word via table titles? Question: I’m facing the problem of trying to extract data from word files in the form of tables. I have to iterate through 500 word files and extract a specific table in each file, but the table appears at a different point in each word …

Total answers: 1

Converting RTF Files to DOCX and PDF Files on Python-Django and linux server

Converting RTF Files to DOCX and PDF Files on Python-Django and linux server Question: Is there any way to accurately convert RTF Files to PDF and DOC files on linux server with Python ? I have gone through a number of past questions and here is what I concluded : The libreoffice command line converter …

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

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

How to display filenames of word documents in a folder using python?

How to display filenames of word documents in a folder using python? Question: I want to display the filenames of word document present in a specified path using python. Asked By: JUSTIN || Source Answers: this could work for you: for file in os.listdir(PATH): if file.endswith(“.doc”) or file.endswith(“.docx”): print(file) Answered By: sxeros It could be …

Total answers: 4

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