python-docx

Extract image position from .docx file using python-docx

谁说胖子不能爱 提交于 2019-12-19 03:18:38
问题 I'm trying to get the image index from the .docx file using python-docx library. I'm able to extract the name of the image, image height and width. But not the index where it is in the word file import docx doc = docx.Document(filename) for s in doc.inline_shapes: print (s.height.cm,s.width.cm,s._inline.graphic.graphicData.pic.nvPicPr.cNvPr.name) output 21.228 15.920 IMG_20160910_220903848.jpg In fact I would like to know if there is any simpler way to get the image name , like s.height.cm

python -docx to extract table from word docx

孤者浪人 提交于 2019-12-19 02:08:39
问题 I know this is a repeated question but those answers are not works for me. I have a word file which consist one table now i want that table as a output of my python program. I'm using python 3.6 and i have installed python -docx as well. Here is my code for the data extraction from docx.api import Document document = Document('test_word.docx') table = document.tables[0] data = [] keys = None for i, row in enumerate(table.rows): text = (cell.text for cell in row.cells) if i == 0: keys = tuple

Generate the MS word document in django

我的梦境 提交于 2019-12-18 04:23:23
问题 Currently i am generating the reports in pdf format. But now i want to generate the reports in ms word or docx format. my api.py file def export_pdf(request,id): report = Report.objects.get(id=id) options1 = ReportPropertyOption.objects.filter(report=report,is_active=True) locations = [] out_string = "" map = None for option in options1: option.property = get_property_name(option.property) option.exterior_images = ReportExteriorImages.objects.filter(report = option) option.interior_images =

Page number python-docx

血红的双手。 提交于 2019-12-17 12:41:32
问题 I am trying to create a program in python that can find a specific word in a .docx file and return page number that it occurred on. So far, in looking through the python-docx documentation I have been unable to find how do access the page number or even the footer where the number would be located. Is there a way to do this using python-docx or even just python? Or if not, what would be the best way to do this? 回答1: Short answer is no, because the page breaks are inserted by the rendering

Page number python-docx

梦想与她 提交于 2019-12-17 12:41:29
问题 I am trying to create a program in python that can find a specific word in a .docx file and return page number that it occurred on. So far, in looking through the python-docx documentation I have been unable to find how do access the page number or even the footer where the number would be located. Is there a way to do this using python-docx or even just python? Or if not, what would be the best way to do this? 回答1: Short answer is no, because the page breaks are inserted by the rendering

How to get python-docx working with complex scripts?

泄露秘密 提交于 2019-12-14 02:24:31
问题 I have a working docx generator which works fine for European languages, and I'm trying to add complex script support. I found another question with some recipes to try: python-docx add_style with CTL (Complex text layout) language I managed to get it working so that complex-script text comes out in the correct typeface and size, but I can't get bidirectional (right-to-left) text working. The obvious "x.font.rtl = True" doesn't work, and neither does the spell given in the other post ("lang

Bold, underlining, and Iterations with python-docx

别说谁变了你拦得住时间么 提交于 2019-12-13 02:58:13
问题 I am writing a program to take data from an ASCII file and place the data in the appropriate place in the Word document, and making only particular words bold and underlined. I am new to Python, but I have extensive experience in Matlab programming. My code is: #IMPORT ASCII DATA AND MAKE IT USEABLE #Alternatively Pandas - gives better table display results import pandas as pd data = pd.read_csv('203792_M-51_Niles_control_SD_ACSF.txt', sep=",", header=None) #print data #data[1][3] gives value

python docx set table cell background and text color

試著忘記壹切 提交于 2019-12-12 10:37:16
问题 I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition. I could not find any usefull resources about single cell formatting Any suggestions? Edit 1 my code style_footer = "DarkList" style_red = "ColorfulList" style_yellow = "LightShading" style_green = "MediumShading2-Accent6" style_transperent = "TableNormal" for a,rec in enumerate(data): #V headinh se piše prvo polje iz table heada document.add_heading(rec['tableHead'

Using docx python library, how to apply color and font size simultaneously

╄→гoц情女王★ 提交于 2019-12-12 09:30:58
问题 I am writing to an .docx file using python docx library. I want to prespecify the font size and color of a paricular sentence. My problem is that I am not able to do it simultaneously. Let me illustrate - from docx import Document from docx.shared import Pt #Helps to specify font size from docx.shared import RGBColor #Helps to specify font Color document=Document() #Instantiation p=document.add_heading(level=0) p.add_run('I want this sentence colored red with fontsize=22').font.size=Pt(22)

Loading text from .docx to MySQL using Python-docx

雨燕双飞 提交于 2019-12-12 06:06:33
问题 As of now, I am using Python-docx to convert the text in a .docx file into a single string. f = open(os.path.expanduser("~/documents/myFile.docx")) document = opendocx(f) docString = ''.join(getdocumenttext(document)) I am then parsing the string using simple built-in Python split methods. Once the string is parsed into a list, I am loading that list into a MySQL database. This works great, but my only problem is I want to preserve the special characters. The database supports these special