Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
10
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

@Ringa_hyj

pythonでwordとexcelレポートを自動作成

excel編

excel作成

import openpyxl as opy
book = opy.Workbook()

シートの名前を確認

sheet1 = book.active
sheet1.title

シートの名前を変更

sheet1.title = 'mysheet_1'

excelファイルを作成

book.save('make_excel.xlsx')

既にあるファイルを開く

my_made = opy.load_workbook('make_excel.xlsx')

指定のシートを編集する

sheet2 = my_made.active
table = my_made[sheet2.title]

セルを指定して文字を書き込む

table['A1'] = 'How is the weather today'

セルの書式変更する

from openpyxl.styles import Font
table['A1'].font = Font(bold=True,italic=True,size=28)

word編

pip install でdocxを指定するのは3.4まで
それ以降はパッケージ名をpython-docxで指定する。

ファイルを作る

import docx
doc = docx.Document()

文章の書きこみ

doc.add_paragraph('How is the weather today')
doc.add_paragraph()
doc.add_paragraph(today_list)
doc.add_paragraph()

画像の挿入

doc.add_picture('pict.png')

ファイルの保存

doc.save('make_word_today.doc')

以上

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
10
Help us understand the problem. What are the problem?