PPT文件转换为HTML文件

参考01年王洪超写的,由于引用的Office版本不同,命名空间有所改变,故整理一下,代码如下:

//本案例中引用的是:11.0.0.0

using Microsoft.Office;

using Microsoft.Office.Interop.PowerPoint;

using Microsoft.Office.Interop;

using Microsoft.Office.Core;

/// <summary>

/// C#转换PPT文件为HTML文件

/// </summary>

public class ConvertPowerPoint

{

/// <summary>

/// 建立对PowerPoint.Application的Com组件的引用

/// </summary>

private Microsoft.Office.Interop.PowerPoint.Application ppt;

/// <summary>

/// 指向具体的文件;

/// </summary>

private Microsoft.Office.Interop.PowerPoint.Presentation pptFile;

/// <summary>

/// 构造器

/// </summary>

public ConvertPowerPoint()

{

ppt = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();

}

/// <summary>

/// 转换过程

/// </summary>

/// <param name="pptFilePath">欲转换的PPT文件的绝对路径</param>

///<param name="htmFilePath">htm文件的绝对路径,如”e:\\Project2008\\PPT_Test\\1.html“</param>

public void Convert(string htmFilePath,string pptFilePath)

{

if (ppt == null)

return;

pptFile = ppt.Presentations.Open(pptFilePath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);

pptFile.SaveAs(htmlFilePath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoCTrue);

pptFile.Close();

}

}