美丽心灵公益论坛

查看: 2196|回复: 3

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

[复制链接]
累计签到:57 天
连续签到:1 天

981

主题

461

回帖

8037

积分

版主

Rank: 7Rank: 7Rank: 7

积分
8037
发表于 2022-10-11 23:44:25| 字数 1,138 | 显示全部楼层 |阅读模式
本帖最后由 willsonlincake 于 2022-10-11 23:49 编辑

代码如下:
  1. import win32com
  2. import win32com.client
  3. import calendar
  4. import locale
  5. locale.setlocale(locale.LC_ALL, 'it')

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

  9. newdoc = newpowerpnt.Presentations.Add()
  10. SWidth = 8.5*72
  11. SHeight = 11*72
  12. newdoc.PageSetup.SlideWidth = SWidth
  13. newdoc.PageSetup.SlideHeight = SHeight
  14. newdoc.Slides.Add(1,12)
  15. 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)
  16. newTextBox.TextFrame.TextRange.Text = "Birthday Reminder"
  17. newTextBox.TextFrame.TextRange.ParagraphFormat.Alignment = win32com.client.constants.msoAlignCenter
  18. newTextBox.TextFrame.VerticalAnchor = win32com.client.constants.msoAnchorMiddle
  19. newTble = newdoc.Slides(1).Shapes.AddTable(12,2,1.6*28.35,3.5*28.35,26*28.35,23*28.35)
  20. newTble.Table.Columns(1).Width = 5.5*28.35
  21. for i in range(1,13):
  22.   newdoc.Slides(1).Shapes(2).Table.Cell(i,1).Shape.TextFrame.TextRange.Text = str(calendar.month_name[i])
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
累计签到:8 天
连续签到:8 天

10

主题

127

回帖

954

积分

高级会员

Rank: 4

积分
954
发表于 2022-10-12 01:02:31| 字数 14 来自手机 | 显示全部楼层
locale设成了意大利文。
累计签到:57 天
连续签到:1 天

981

主题

461

回帖

8037

积分

版主

Rank: 7Rank: 7Rank: 7

积分
8037
 楼主| 发表于 2022-10-12 09:09:34| 字数 87 来自手机 | 显示全部楼层
boo1977 发表于 2022-10-12 01:02
locale设成了意大利文。

Locale只是拿来演示设置语言的需要,locale在Windows和Linux上的代码还不一样
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|免责及版权声明|关于|美丽心灵公益论坛

GMT+8, 2025-11-21 13:28 , Processed in 0.071221 second(s), 33 queries .

Powered by Discuz! X3.4

!copyright!

快速回复 返回顶部 返回列表