willsonlincake 发表于 2022-10-11 23:44:25

Python操作PowerPoint生成年度生日记录表

本帖最后由 willsonlincake 于 2022-10-11 23:49 编辑

代码如下:
import win32com
import win32com.client
import calendar
import locale
locale.setlocale(locale.LC_ALL, 'it')

newpowerpnt = win32com.client.gencache.EnsureDispatch("PowerPoint.Application")
win32com.client.gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 8)
newpowerpnt.Visible = 1

newdoc = newpowerpnt.Presentations.Add()
SWidth = 8.5*72
SHeight = 11*72
newdoc.PageSetup.SlideWidth = SWidth
newdoc.PageSetup.SlideHeight = SHeight
newdoc.Slides.Add(1,12)
newTextBox = newdoc.Slides(1).Shapes.AddTextbox(win32com.client.constants.msoTextOrientationHorizontal,Left=6.7*28.35,Top=2.17*28.35,Width = 8.8*28.35,Height=1.8*28.35)
newTextBox.TextFrame.TextRange.Text = "Birthday Reminder"
newTextBox.TextFrame.TextRange.ParagraphFormat.Alignment = win32com.client.constants.msoAlignCenter
newTextBox.TextFrame.VerticalAnchor = win32com.client.constants.msoAnchorMiddle
newTble = newdoc.Slides(1).Shapes.AddTable(12,2,1.6*28.35,3.5*28.35,26*28.35,23*28.35)
newTble.Table.Columns(1).Width = 5.5*28.35
for i in range(1,13):
newdoc.Slides(1).Shapes(2).Table.Cell(i,1).Shape.TextFrame.TextRange.Text = str(calendar.month_name)

boo1977 发表于 2022-10-12 01:02:31

locale设成了意大利文。

willsonlincake 发表于 2022-10-12 09:09:34

boo1977 发表于 2022-10-12 01:02
locale设成了意大利文。

Locale只是拿来演示设置语言的需要,locale在Windows和Linux上的代码还不一样
页: [1]
查看完整版本: Python操作PowerPoint生成年度生日记录表