Newest 'python-docx' Questions - Stack Overflow

Questions tagged [python-docx]

A python library to create, read and write Microsoft Office Word 2007 docx files.

1
vote
1answer
21 views

How to print a word document from Python in A5 size?

I'm making a program which prints out receipts on word documents. I need the print-outs on A5 size sheets. This seems to work, but I don't know how to configure it to A5 size. from win32com import ...
0
votes
0answers
26 views

Is there any way to apply z-index to an image in python-docx word report or some other way to add a background/watermark image in python-docx report?

I am trying to create a word document report in Odoo 12 with the help of the python-docx. I have come across a problem where I want to add a watermark or background image in the document but it seems ...
0
votes
1answer
16 views

Unpacking set in string format in python only returns first value

I have converted a DataFrame Column into a set, and I am trying to format the values into a string using the * to unpack it like a list. However, it only returns the first value. I am using the ...
1
vote
1answer
12 views

Use Python docx to create phonetic guide / 'Ruby text' in Word?

I want to add phonetic guides to words in MS Word. Inside of MS Word the original word is called 'Base text' and the phonetic guide is called 'Ruby text.' Here's what I'm trying to create looks like ...
0
votes
0answers
22 views

How to make the column widths dynamic in docx?

I have written a pronunciation guide for a foreign language. It has information about each word in a list. I want to use docx to show the pronunciation guide above the original words and the part of ...
0
votes
3answers
30 views

Add page number using python-docx

I am trying to add a page number in the footer of a word doc using python-docx. So far, I haven't been able to find how to do so. This question address how to find a page number (or how you cannot). ...
1
vote
1answer
39 views

How remove blank column from table created in docx?

I have written a pronunciation guide for a foriegn language. It has information about each word in a list. I want to use docx to show the pronunciation guide above the original words and the part of ...
0
votes
0answers
17 views

How to make docx tables with varying table sizes and add text

So I have a list of numbers and am trying to create a .docx using Python but I have trouble going about how to make the tables I need. So I've tried to make a list of the numbers and then iterate ...
0
votes
0answers
15 views

Opening a list of .docx file addresses

So I have a tree like folder hierarchy. A root folder with sub directories and and further sub directories and in the end they all have a .docx file which i need to access. So far I have managed to ...
0
votes
1answer
18 views

Cannot change font.name for style “Heading 1”

I'm generating *.docx using python-docx. Cannot change font name for the built-in style "Heading 1". The font is still "Calibri". Other things, including changing of font size and color, work as ...
-1
votes
1answer
42 views

How to write multiple tables in docx file using python-docx?

I want to write/include more than two tables in a docx file using python. How can I write this structure as a table in a docx file using python? I tried the following code for a single table. Now I ...
2
votes
1answer
31 views

How to remove new line in Word header using python-docx when adding paragraph text?

I've successfully added text and image in a two-cells table in Word header. section = document.sections[0] header = section.header htable = header.add_table(1, 2, Inches(6)) htab_cells = htable....
0
votes
0answers
21 views

python-docx identify page endings

I'm trying to detect page endings using python-docx but I can't figure out how to do it, I searched so solutions but they don't work, like finding in the saved xml. btw I'm using linux if this is ...
-1
votes
1answer
49 views

How to generate a table with varying size of rows in Python?

I am trying to automate the generation of a report by taking data out of excel and putting into a word document with tables . I know how to read from excel and write to word , but I am trying to ...
-1
votes
1answer
51 views

Can we find a specific word in a docx file using python?

I have tried using the python-docx module. So far, I have been able to extract specific paragraphs and also the whole text out of the word file. pip install --pre python-docx #to install python-docx ...
2
votes
2answers
38 views

python-docx: tables missing from document.tables

When trying to access a table in the word document below, tables before the table of contents are missing from document.tables https://www.fedramp.gov/assets/resources/templates/FedRAMP-SSP-High-...
-2
votes
0answers
16 views

list index out of range in python-docx

When I am making changes into my doc from where it is getting the formatting of the word. It is showing me error list index out of range. I am simply changing the variable color in the doc and it is ...
0
votes
1answer
23 views

How to create a word docx using python docx in other than english?

I am building a program creating printed outputs from python code. Further, the final print containing the other language (Sinhala). I want to use python docx to save this output into a word document....
-1
votes
0answers
18 views

Conversion error of SQL data for insertion in MS Word document

I am making a Python program that collects data from bus about bus information and putting in a MS Word document but it says that 'cannot convert into int with base of 10', when I put float, it says ...
1
vote
1answer
29 views

UnrecognizedImageError - image insertion error - python-docx

I am trying to insert an wmf file to docx using python-docx which is producing the following traceback. Traceback (most recent call last): File "C:/Users/ADMIN/PycharmProjects/ppt-to-word/...
1
vote
1answer
32 views

How to search and replace a word/text in word document using python-docx

For example: Please find below paragraphs in a word document. The paragraphs are inside a table. Ok Guys Please get up Ok Guys Please getting up. I'm trying to replace "get" with "wake". I am ...
0
votes
0answers
19 views

How to add inter-page links in MS word using python-docx?

I am creating a file which contain text data on 1st 4 pages and all images from page 5 onwards. There is a table having page numbers as column. I want to add link to each of the page number in that ...
3
votes
1answer
228 views

How do I view the XML produced by the python-docx package

For the purposes of unit testing, I want to check that the XML produced for a Word paragraph is what I expect when I parse an HTML paragraph. How do I extract the XML itself instead of writing to a ...
0
votes
2answers
26 views

Python-docx module not overwriting same file name

I have been using python-docx to create and save .docx files automatically. It works to create a single uniquely named .docx file, but if I want to overwrite that file it doesn't do anything. I have ...
0
votes
0answers
29 views

python-docx split cells dynamically

I need to generate a word document wherein I have create a table in it. The number of columns in each row is dynamic depending on row number(default 2 else more than 2). So I want to know how to split ...
4
votes
1answer
45 views

How to apply strike-through using python-docx

My problem is that when I apply the strike-through or double strike-through formatting and save the file it is not reflected in output file. Following code does not do the trick: from docx import ...
0
votes
0answers
26 views

How to link two paragraphs of a different indentation format (python docx)?

I'm trying to build a SINGLE paragraph in a created word docx (via python docx) which looks like this: text kjdfkjshfkjshfdkjhskjdhf kjdhfksdfkhsgfdghsf ksjdgfkjsgkjfgjsgf ...
0
votes
0answers
26 views

How to add hyperlinks to images in same docx using python-docx?

I am creating a docx file using python-docx which contain some data, tables and images which are converted from PDF and attached lastly using add_picture(). Now I have a table in which each row ...
-2
votes
1answer
59 views

ImportError: cannot import name 'Document'

I ran a code generated in python 3.6.5, it perfectly worked (countless times), now I turned on my computer, runned it again (didn't change anything at all) and: ImportError: cannot import name '...
0
votes
0answers
14 views

Create footer in word docx by creating a footer.xml file in the word - folder of the docx.zip via python?

No idea how I can do this considering the (randomly?) generated rsids in the xml code, anyone has a solution? from docx.text.run import Run from docx import Document doc = Document('/Users/cezi/...
0
votes
0answers
17 views

Code Page Number / Total Page Number in Word Docx via Python Docx?

Is the only way to do this by changing the XML - structure of the footer?? I already tried a huge bunch of different things, but nothing worked, so I won't copy 872634852846 useless codes in here.
0
votes
0answers
21 views

Generate already expanded Table of contents using python docxtpl library and MS word

I am working on doc generation using the python-docxtpl library. So, I have created a template to use, in which I have a dummy Table of contents. When I generate doc using this template, generated doc ...
0
votes
0answers
25 views

Create word fields in python-docx to automatize footer from upon page 2 of the word document (e.g. # Page / # Total Pages)?

I'm trying to automatize a word - file generation via python docx. I created a template with the first page and its specific footers and headers; now I only need to implement this footer, starting ...
1
vote
1answer
42 views

Apply on Dataframe passes first row values to all rows

When using apply in the below way, the values that get passed as "row" are exclusively those from the first row of the dataframe. df.apply(make_word_file, axis=1) Oddly, the file name created in the ...
0
votes
1answer
33 views

Scraping text from doc and docx files in one function

I am iterating over a list of urls that link to docx, doc and pdf files. I wrote a function that allows me to extract the text from docx files and append it to a new list. I have no interest in the ...
0
votes
1answer
24 views

python-docx v0.8.10 - Unable to read/add header

Attempting to create a new document with headers and footers, but without success. My code: doc = Document() section = doc.sections[0] header = section.header ... Unfortunately I am not able to ...
0
votes
0answers
51 views

Edit table's border style with python-docx

I need to create a new docx file containg 2 tables exactly like in the picture bellow. How can i change the borders style of the whole table ?
0
votes
0answers
95 views

What is the way to add watermark text in a docx file using python?

I'm manipulating a docx file using python-docx module which doesn't seem to have watermark support. What can be the possible way to add some watermark text in a docx file using python? Edit: I've ...
0
votes
1answer
48 views

How to print individual rows of a pandas dataframe using Python?

newbie to Python. I'm trying to extract data from a dataframe and put it into a string to print to a docx file. This is my current code: add_run("Placeholder A").italic= True for i in range(0, ...
0
votes
1answer
21 views

python-docx How to get content/body of a section

I am using Word's sections term to be able for each page to have different header, where I mark page with some markup like {page1}. Using python-docx I get sections by: doc = Document(my_file)` ...
1
vote
1answer
37 views

'CT_Highlight' object has no attribute 'attribute'

I'm trying to read in text from a word document, docx and trying to find all the text that has been highlighted in yellow but it gives me an error message import docx document = docx.Document(r'C:/...
0
votes
1answer
37 views

How to copy each paragraph from .docx file to new row in .csv file?

I am new to python. I am trying to parse a .docx file and copy each paragraph to an individual row in a new .csv file. I am able to count the number of paragraphs accurately, as well as print the ...
1
vote
0answers
36 views

How to copy all the paragraphs and styles within a heading to another MS Word file

I am using Python docx library and try to copy paragraphs under a few headings in many .docx files to a single new word document. In those original .docx files, there are some custom styles created ...
0
votes
2answers
67 views

Attribute error with .docx document no attribute 'xpath'

from docx import * document = Document(r'filepath.docx') words = document.xpath('//w:r', namespaces=document.nsmap) WPML_URI = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main' tag_rPr = ...
0
votes
1answer
43 views

How to change alignment of cell text in MS Word table without “paragraph” object

I have a MS Word "template" file that I am opening, modifying with new data from various sources, and then saving as a new file. I have multiple tables in the template document which are appropriately ...
0
votes
0answers
24 views

how to set right to left for text in word using python-docx

I cant set text direction (note: not text alignment) into right to left using the python-docx library. Do you have any idea to solve this problem? from docx import Document from docx.enum.style ...
0
votes
1answer
40 views

How to make header rows for table bold using Python docx?

I have created a table using the Python docx library and would like to make the header rows bold. Here is the code I am using: a= doc.add_table(rows=5, cols=7) heading_cells = a.rows[0].cells w = ...
0
votes
0answers
30 views

TypeError when creating a variable and creating class

I am learning python-docx (see below) and I am having troubles with a TypeError. When I run the document = Document() I get this error: TypeError: super(type, obj): obj must be an instance or ...
3
votes
0answers
47 views

How to add a page border with python-docx

I want to add a page border to my MS Word Document using python-docx. How can I do ? I check the section's documentation but I didn't find anything about this.
0
votes
0answers
16 views

Is it possible to change the data in a table to the contents of a .txt file with Python-docx?

I need to get the data within some .txt files into a table in a word document. I am using Python-docx. Looking at the ReadTheDocs for Python-Docx it says to have a list of "records" which can then be ...