0
Excelファイルからデータを取り出してWordファイルを作成するプログラムをPythonで作成しようとしています。 たとえば、次のExcelファイルの名前をProblems.xlsxとします。Pythonを使ったボーダーの追加に関する質問docxワード文書へのパッケージ
このExcelファイルに記載されている13の問題のすべてについて、(Book Id) - (Problem Id)という名前のファイルを作成します。各ファイルは次のようになります。
nt1.docx。それは52289-9.2-59PS.docxでなければなりません。しかし、最初の行にボトムボーダー、左のファイル名、会社名(定数)、および今日の日付が含まれていることを確認してください。
文書に罫線を追加したり、フォントサイズや名前を変更する際に問題があります。これまでに書いたコードです。
from openpyxl import load_workbook
from docx import Document
from time import strftime
from docx.shared import Pt
#Accessing data from excel file.
ws=load_workbook(filename="Problems.xlsx")
sheet=ws.get_sheet_by_name('Sheet2')
for i in range(2,15):
fileName=""
for j in range(1,4):
if j!=3:
fileName=fileName+str(sheet.cell(row=i,column=j).value)+"-"
else:
fileName=fileName+str(sheet.cell(row=i,column=j).value)
#Now we have the file names, so let's make a file
document=Document()
run=document.add_paragraph().add_run()
font=run.font
font.name="Times New Roman"
font.size=12
date=strftime("%d/%m/%Y")
document.add_paragraph(fileName+" AID: 1112|"+date)
document.add_paragraph("--------------------------------------------------------------------------------------------------------------------")
#Saving the document with the fileName
document.save(fileName+".docx")
上記のコードは、正しい名前のファイルを作成しますが、二つの重要な問題があります。
- はフォントがまだのTimes New Romanの代わりにCalibriままで、フォントサイズが11ではなく12です
- 私は今のところ破線を追加しましたが、私は本当に赤い丸で囲まれたボタンを通常クリックする下の境界線を持っていたいと思います。