import pickle
from docx import Document
from docx.shared import Inches
with open("notice.pickle", "rb") as f:
data = pickle.load(f)
data_short = data[:]
document = Document("form.docx")
paragraph = document.add_paragraph('Lorem ipsum dolor sit amet.')
prior_paragraph = paragraph.insert_paragraph_before('insert')
paragraph = document.add_paragraph('@@.')
table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = '번호2'
hdr_cells[1].text = '주소'
hdr_cells[2].text = '제목'
for i in data_short:
print(i)
row_cells = table.add_row().cells
row_cells[0].width = Inches(1)
row_cells[0].text = i['번호']
# print("0",row_cells[0].width)
row_cells[1].width = Inches(4)
row_cells[1].text = i['주소']
# print("1",row_cells[1].width)
row_cells[2].width = Inches(3)
row_cells[2].text = i['제목']
# print("2",row_cells[2].width)
table.style="my"
document.save('demo65.docx')
Leave a Comment