【发布时间】:2020-04-04 08:38:11
【问题描述】:
一个'pptx'格式的文件应该可以在最新版本的PowerPoint中导出到一个'svg'文件或一些'svg'文件(一张幻灯片到一个'svg'文件)(该功能是在2019 年 9 月),我可以在 PowerPoint 应用程序中完成。但是我不能用 PowerPoint 应用程序中的 VBA 来做到这一点,但是我可以在 PowerPoint 应用程序中使用 VBA 将“pptx”格式文件导出为“png”或“jpg”或其他格式文件。VBA 中的代码是:
Sub test()
With Application.ActivePresentation.Slides(1)
.Export "c:\Graphic\Slide1", "svg"
End With
End Sub
我得到了这个错误:
PowerPoint 无法导出幻灯片,因为没有安装转换器 支持这种文件类型。
其实我想做的是通过python导出文件(使用pywin32模块),代码是:
from win32com import client as wc
ppt = wc.Dispatch('PowerPoint.Application')
doc = ppt.Presentations.Open(path)
doc.Slides(1).Export(file_path, 'svg')
我得到了同样的错误:
Slide.Export : PowerPoint 无法导出幻灯片,因为没有 已安装的转换器支持此文件类型。
代码真的没问题,因为如果我将 'svg' 更改为 'png' 或 'jpg' 就可以了。
2020-08-26 附加部分
我已将 PowerPoint 更新到最新版本,并使用 pywin32 中的 makepy.py 从 Microsoft PowerPoint 16.0 Object Library(2.c) 创建一个名为 91493440-5A91-11CF-8700-00AA0060263Bx0x2x12.py 的新 py 文件,我比较了旧文件和新文件,它们确实有一些差异,请参见图片the difference between the new file and the old,但在“形状导出”方面它们似乎相同,请参见图片ppShapeFormat。无论如何,我已经尝试了以下代码:
doc.Slides(1).Shapes('Rectangle 3').Export(file_path, i)
“i”我试过-5到20,但只有0-5有所不同,其他导出的文件与i = 1相同(即JPG文件),我查看了所有文件, 都是二进制文件,不能是 SVG 文件,请问如何将 Shapes 导出为 SVG?
顺便说一下,我也直接在VBA中尝试过,结果是一样的。
如果图片无法显示,这里有一些关键信息:
ppShapeFormatBMP =3 # from enum PpShapeFormat
ppShapeFormatEMF =5 # from enum PpShapeFormat
ppShapeFormatGIF =0 # from enum PpShapeFormat
ppShapeFormatJPG =1 # from enum PpShapeFormat
ppShapeFormatPNG =2 # from enum PpShapeFormat
ppShapeFormatWMF =4 # from enum PpShapeFormat
【问题讨论】:
标签: vba svg export powerpoint pywin32