python-docx

Python Docx - how to number headings?

淺唱寂寞╮ 提交于 2020-06-17 19:20:40
问题 There is a good example for Python Docx. I have used multiple document.add_heading('xxx', level=Y) and can see when I open the generated document in MS Word that the levels are correct. What I don't see is numbering, such a 1, 1.1, 1.1.1, etc I just see the heading text. How can I display heading numbers, using Docx ? 回答1: Alphanumeric heading prefixes are automatically created based on the outline style and level of the heading. Set the outline style and insert the correct level and you will

Python Docx - how to number headings?

你。 提交于 2020-06-17 19:19:00
问题 There is a good example for Python Docx. I have used multiple document.add_heading('xxx', level=Y) and can see when I open the generated document in MS Word that the levels are correct. What I don't see is numbering, such a 1, 1.1, 1.1.1, etc I just see the heading text. How can I display heading numbers, using Docx ? 回答1: Alphanumeric heading prefixes are automatically created based on the outline style and level of the heading. Set the outline style and insert the correct level and you will

Modify docx page margins with python-docx

亡梦爱人 提交于 2020-06-14 02:46:27
问题 I need to quickly change the margins of many docx documents. I checked python-docx and I do not find a way to access/modify the page layout (in particular the margins) properties. Is there a way? 回答1: Thanks to @tdelaney for pointing out the page where it clearly indicated the solution. I am just posting here the code I used in case anyone else is confused as I initially was: #Open the document document = Document(args.inputFile) #changing the page margins sections = document.sections for

How do I apply both bold and italics in python-docx?

怎甘沉沦 提交于 2020-05-27 09:32:25
问题 I'm working on making a dictionary. I'm using python-docx to put it into MS Word. I can easily make it bold, or italics, but can't seem to figure out how to do both. Here's the basics: import docx word = 'Dictionary' doc = docx.Document() p = doc.add_paragraph() p.add_run(word).bold = True doc.save('test.docx') I have tried p.add_run(word).bold.italic = True, but receive a 'NoneType' error, which I understand. I have also tried p.bold = True and p.italic = True before and after the add_run,

How do I apply both bold and italics in python-docx?

那年仲夏 提交于 2020-05-27 09:32:10
问题 I'm working on making a dictionary. I'm using python-docx to put it into MS Word. I can easily make it bold, or italics, but can't seem to figure out how to do both. Here's the basics: import docx word = 'Dictionary' doc = docx.Document() p = doc.add_paragraph() p.add_run(word).bold = True doc.save('test.docx') I have tried p.add_run(word).bold.italic = True, but receive a 'NoneType' error, which I understand. I have also tried p.bold = True and p.italic = True before and after the add_run,

How do I apply both bold and italics in python-docx?

依然范特西╮ 提交于 2020-05-27 09:32:08
问题 I'm working on making a dictionary. I'm using python-docx to put it into MS Word. I can easily make it bold, or italics, but can't seem to figure out how to do both. Here's the basics: import docx word = 'Dictionary' doc = docx.Document() p = doc.add_paragraph() p.add_run(word).bold = True doc.save('test.docx') I have tried p.add_run(word).bold.italic = True, but receive a 'NoneType' error, which I understand. I have also tried p.bold = True and p.italic = True before and after the add_run,

python-docx get info from dropdownlist (in table)

℡╲_俬逩灬. 提交于 2020-05-27 09:25:28
问题 I have a docx-file with multiple tables and I want to get all of the information from the tables in a list (the list is called 'alletabellen'). With the script below I receive almost all of the information in the tables, except the values of some variables which are in a dropdown list (in some of the table cells). The values of these cells remain empty in my list (for example the value '1.2' from the variable 'Number:', see: https://s30.postimg.org/477j8z6ch/table.png I do not get that value

python-docx get info from dropdownlist (in table)

北慕城南 提交于 2020-05-27 09:25:10
问题 I have a docx-file with multiple tables and I want to get all of the information from the tables in a list (the list is called 'alletabellen'). With the script below I receive almost all of the information in the tables, except the values of some variables which are in a dropdown list (in some of the table cells). The values of these cells remain empty in my list (for example the value '1.2' from the variable 'Number:', see: https://s30.postimg.org/477j8z6ch/table.png I do not get that value

python-docx: Parse a table to Panda Dataframe

≯℡__Kan透↙ 提交于 2020-05-17 08:30:26
问题 I'm using the python-docx library to extract ms word document. I'm able to get all the tables from the word document by using the same library. However, I'd like to parse the table into a panda data frame, is there any built-in functionality I can use to parse the table into data frame or I'll have to do it manually? Also, is there a possibility to know the heading name in which the table lies inside? Thank you from docx import Document from docx.shared import Inches document = Document('test

In python-docx how do I delete a table row?

白昼怎懂夜的黑 提交于 2020-05-15 10:54:19
问题 I can't figure out how to delete a table row in python-docx. Specifically, my tables come in with a header row and a row that has a special token stored in the text of the first cell. I search for tables with the token and then fill in a bunch of rows of the table. But how do I delete row 1, which has the token, before adding new rows? I tried table.rows[1].Delete() and table.rows = table.rows[0:1] The first one fails with an unrecognized function (the documentation refers to this function in