如何使用python在word文档中的特定位置插入图像?
我的程序创建了一组word文件:它们包含有关学生的信息,如姓名、地址、电话号码。。。还有条形码。 当我将QRCode作为图片插入时,它会附加在文件的末尾。我希望它被插入到文本“条形码”的最右边。 我徒劳地寻找解决办法。 我插入了解释这个词的图片。对不起,我已经隐藏了这些信息,因为它是机密的。 这是我的密码:如何使用python在word文档中的特定位置插入图像?,python,ms-word,docx,Python,Ms Word,Docx,我的程序创建了一组word文件:它们包含有关学生的信息,如姓名、地址、电话号码。。。还有条形码。 当我将QRCode作为图片插入时,它会附加在文件的末尾。我希望它被插入到文本“条形码”的最右边。 我徒劳地寻找解决办法。 我插入了解释这个词的图片。对不起,我已经隐藏了这些信息,因为它是机密的。 这是我的密码: import uuid import pandas as pd import pyqrcode from docx import Document from docx.shared im
import uuid
import pandas as pd
import pyqrcode
from docx import Document
from docx.shared import Inches
def generateBarCode(length):
return str(uuid.uuid4()).replace('-','')[0:length]
df=pd.DataFrame(pd.read_excel('Komplette-
GastAccountFHZugangsdatenFertig.xlsx'))
array=[]
for i in range(len(df)):
qr=pyqrcode.create(generateBarCode(8))
array.append(qr)
df.insert(8,'Barcode',array)
x=['.png']
with pd.ExcelWriter('Komplette-GastAccountFHZugangsdatenFertig.xlsx') as
writer :
df.to_excel(writer,sheet_name='Sheet1')
for i in range(len(df)):
document=Document()
document.add_heading('Informationen')
document.add_paragraph('Name : ' + df['Name'][i])
document.add_paragraph('Vorname : ' + df['Vorname '][i])
document.add_paragraph('Geschlecht : ' + df['Geschlecht'][i])
document.add_paragraph('Adresse(in Marokko) : ' + df['Adresse (in
Marokko)'][i])
document.add_paragraph('Telefonnummer : ' + str(df['Telefonnummer'][i]))
document.add_paragraph('E-Mailadresse : ' + str(df['E-Mailadresse'][i]))
document.add_paragraph('Studiengang : ' + df['Studiengang'][i] )
document.add_paragraph('Semester : ' + str(df['Semester'][i]))
document.add_paragraph('Barcode : ')
qr=df['Barcode'][i]
qr.png(df['Name'][i]+df['Vorname '][i]+x[0])
document.add_picture(df['Name'][i]+df['Vorname ']
[i]+'.png',width=Inches(2.0))
document.save(df['Name'][i]+' '+ df['Vorname '][i]+'.docx')
截图
感谢查看
文档的实现。在python docx的文档中添加图片
使用此信息,您可以使用
document.add_paragraph('Barcode : ')
.add_run()
.add_picture(df['Name'][i]+df['Vorname '] [i]+'.png',width=Inches(2.0))
将图片添加到同一段落。我还没有测试过,但我希望这能起到作用。谢谢,这就是我要找的!
document.add_paragraph('Barcode : ')
.add_run()
.add_picture(df['Name'][i]+df['Vorname '] [i]+'.png',width=Inches(2.0))