在 PowerPoint 应用程序中使用 VBA 将 'PPTX' 格式文件导出为 'SVG' 格式文件

Export a 'PPTX' format file to 'SVG' format files using VBA in the PowerPoint Application

一个'pptx'格式的文件应该能够导出到一个'svg'文件或一些'svg'文件(只需一张幻灯片到一个'svg'文件) PowerPoint版本(2019年9月新增功能),我可以在PowerPoint应用程序中完成。但是我不能在 PowerPoint 应用程序中使用 VBA 来完成,但是我可以将 'pptx' 格式文件导出到 'png' 或 'jpg' 或其他格式文件 [= PowerPoint 中的 54=] Application.The 中的代码 VBA 是:

Sub test()

With Application.ActivePresentation.Slides(1)
    .Export "c:\Graphic\Slide1", "svg"
End With

End Sub

我得到了这个错误:

PowerPoint can't export the slide(s) because no installed converter supports this file type.

其实我想做的是通过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 can't export the slide(s) because no installed converter supports this file type.

代码真的没问题,因为如果我将 'svg' 更改为 'png' 或 'jpg',它就可以正常工作。

2020-08-26 Additional part

我已将 PowerPoint 更新到最新版本并使用来自 pywin32 的 makepy.py 从 Microsoft PowerPoint 16.0 对象库 (2.c) 创建一个名为 91493440-5A91-11CF- 的新 py 文件8700-00AA0060263Bx0x2x12.py,我对比了旧文件和新文件,确实有些不同,见图the difference between the new file and the old, but in the "Shapes Export" aspect they seems to be the same, see the picture 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

SVG 是 PowerPoint 中相对较新的格式,尚未添加到对象模型中。

作为解决方法,您可以导出为 EMF。与 SVG 一样,它是一种矢量格式。然后使用免费且可编写脚本的 InkScape 转换为 SVG。