2
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Posted at

#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')

#以上

2
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?