【问题标题】:Converting power point (ppt) file to image将电源点 (ppt) 文件转换为图像
【发布时间】:2015-04-17 05:06:56
【问题描述】:

我目前正在尝试自动化一种方法,将 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

现在这适用于一个文件,但如果我再次尝试运行该函数,它会说目标路径正在使用中。似乎电源点正在锁定文件。我不想每次运行时都更改文件名。我想每次都重用那个临时文件。任何想法如何使它不会被锁定?

【问题讨论】:

    标签: vb.net powerpoint


    【解决方案1】:

    它是一个 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
    

    【讨论】:

    • 我添加了显示行但仍然是同样的问题。我更新了我的问题以反映这一点。
    • 应用程序变量是否有退出/退出方法?如果是这样,请在处理之前调用它。
    • 我调用了 pptapplication.Quit() 但仍然出现相同的锁定文件错误。
    • 这通常适用于我使用过的所有其他 Com 对象。请确保您的第一个实例在重试之前已被任务管理器关闭。它可能仍然从早些时候被锁定。
    • @EricF,你有没有尝试我最后的建议?
    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 2011-03-20
    • 2018-01-22
    • 2020-10-11
    • 2019-03-15
    • 1970-01-01
    • 2012-03-21
    相关资源
    最近更新 更多