Help us understand the problem. What is going on with this article?

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

以上

Ringa_hyj
R,python,分析,ML engineer,社内コンサル。 元:生命科学(創薬有機) 元:製品開発・実験計画 現在:製造業のデータ分析活用 概念検証(需要予測,異常検知,etc.) https://amazongodman.github.io/
https://sit-jhonny.hatenablog.com/
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした