前提・実現したいこと
python-pptxを用いてpowerpoint上に表を作成したいです。表の作成自体は
from pptx import Presentation from pptx.util import Inches prs = Presentation() title_only_slide_layout = prs.slide_layouts[5] slide = prs.slides.add_slide(title_only_slide_layout) shapes = slide.shapes shapes.title.text = 'Adding a Table' rows = cols = 2 left = top = Inches(2.0) width = Inches(6.0) height = Inches(0.8) table = shapes.add_table(rows, cols, left, top, width, height).table # set column widths table.columns[0].width = Inches(2.0) table.columns[1].width = Inches(4.0) # write column headings table.cell(0, 0).text = 'Foo' table.cell(0, 1).text = 'Bar' # write body cells table.cell(1, 0).text = 'Baz' table.cell(1, 1).text = 'Qux' prs.save('test.pptx')
でできるのですが、
上図のデザインの表のスタイルでしか作成できません。別のデザインの表のスタイルで表を出力したいです。
例えば下図のような。
試したこと
python
1#slide 2slide = prs.slides[4] 3 4#new table 5x, y, cx, cy = Inches(2), Inches(2), Inches(4), Inches(1.5) 6shape = slide.shapes.add_table(3, 3, x, y, cx, cy) 7 8#set table look 9tbl = shape._element.graphic.graphicData.tbl 10style_id = '{E8B1032C-EA38-4F05-BA0D-38AFFFC7BED3}' 11tbl[0][-1].text = style_id
というコード(python-pptx/issues/27)も試しましたが、
'CT_GroupShape' object has no attribute 'graphic'
というエラーが出てしまいます。
dir(shape._element)でattributeをしらべると確かにgraphicはありませんでした。
補足情報(FW/ツールのバージョンなど)
python-pptx 0.6.18
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/17 16:23