teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

修正

2021/03/09 12:16

投稿

退会済みユーザー
answer CHANGED
@@ -8,7 +8,8 @@
8
8
  from pptx.util import Pt, Inches
9
9
  import openpyxl
10
10
 
11
- def create_presentation(previous_month, this_month, slide_title, sub_title, filenum):
11
+ def create_presentation(previous_month, this_month, slide_title, sub_title, template):
12
+
12
13
  # ---大きさの単位変更---
13
14
  # センチメートルをPowerPoint上の距離に変換する関数
14
15
  def Centis(length):
@@ -17,7 +18,7 @@
17
18
 
18
19
  # ---スライド作成---
19
20
  # 1枚のスライドでプレゼンテーションを作成する※今回はPPTを指定した
20
- prs = Presentation('templat.pptx')
21
+ prs = template
21
22
 
22
23
  # 1枚目のスライドのレイアウトを使用するように指定
23
24
  title_only_slide_layout = prs.slide_layouts[1]
@@ -80,19 +81,24 @@
80
81
  tfMonth.paragraphs[0].font.size = Pt(14)
81
82
  tfMonth.paragraphs[0].font.name = 'メイリオ'
82
83
 
83
- prs.save('chart-'+str.zfill(str(filenum),2)+'.pptx')
84
84
 
85
+
86
+
85
- # プログラム開始
87
+ # ブック取得
86
88
  wb = openpyxl.load_workbook("data.xlsx")
87
89
  # シートを取得
88
90
  sheet = wb["Sheet1"]
89
91
  list_A = []
90
- #A列のデータのみ取り出す ※10月
92
+
91
93
  #値の入っている最大行、最大列まで行単位でセルの値を取得する
92
94
  for rows in sheet.iter_rows(min_row=2, min_col=1, max_col=4):
93
95
  list_A.append([cell.value for cell in rows])
94
96
 
97
+ prs = Presentation('templat.pptx')
98
+
95
- # スライドを作成する関数を呼び出す。
99
+ # スライドを作成する
96
- for i, a in enumerate(list_A):
100
+ for a in list_A:
97
- create_presentation(previous_month=str(a[0]), this_month=str(a[1]), slide_title=a[2], sub_title=a[3], filenum=i+1)
101
+ create_presentation(previous_month=str(a[0]), this_month=str(a[1]), slide_title=a[2], sub_title=a[3], template=prs)
102
+
103
+ prs.save('chart-01.pptx')
98
104
  ```

1

修正

2021/03/09 12:16

投稿

退会済みユーザー
answer CHANGED
@@ -92,4 +92,7 @@
92
92
  for rows in sheet.iter_rows(min_row=2, min_col=1, max_col=4):
93
93
  list_A.append([cell.value for cell in rows])
94
94
 
95
+ # スライドを作成する関数を呼び出す。
96
+ for i, a in enumerate(list_A):
97
+ create_presentation(previous_month=str(a[0]), this_month=str(a[1]), slide_title=a[2], sub_title=a[3], filenum=i+1)
95
98
  ```