繁体   English   中英

将Power Point(ppt)文件转换为图像

[英]Converting power point (ppt) file to image

我目前正在尝试自动化将PowerPoint幻灯片转换为图像的方法,然后可以在应用程序中使用该图像。 我有使用powerpoint插件的方法:

Private Function convert_slide(ByVal targetfile As String, ByVal imagepath As String, ByVal slide_index As Integer)
    Dim pptapplication As New Microsoft.Office.Interop.PowerPoint.Application
    Dim prsPres As Microsoft.Office.Interop.PowerPoint.Presentation = pptapplication.Presentations.Open(targetFile, True, False, False)
    prsPres.Slides(slide_index).Export(imagepath, "jpg", 0, 0)
    prsPres.Close()
    pptapplication.Quit()


    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(prsPres)
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pptapplication)

    Return Image.FromFile(imagepath)

End Function

现在这适用于一个文件,但是如果我再次尝试运行该功能,则说明目标路径正在使用中。 似乎Power Point正在锁定文件。 我不想每次运行时都更改文件名。 我想每次都重复使用该临时文件。 有什么想法使它不被锁定吗?

在此处输入图片说明

它是一个Com对象。 您需要处理它。

Private Function convert_slide(ByVal targetfile As String, ByVal imagepath As String, ByVal slide_index As Integer) As Image
  Dim pptapplication As New Microsoft.Office.Interop.PowerPoint.Application
  Dim prsPres As Microsoft.Office.Interop.PowerPoint.Presentation = pptapplication.Presentations.Open(targetFile, True, False, False)
  prsPres.Slides(slide_index).Export(imagepath, "jpg", 0, 0)
  prsPres.Close()
  pptapplication.Quit()
  Microsoft.Office.InteropMarshal.FinalReleaseComObject(prsPres)
  Microsoft.Office.InteropMarshal.FinalReleaseComObject(pptapplication) 
  Return Image.FromFile(imagepath)

End Function

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM