PPT TO Html

第一步:引用组件: Interop.PowerPoint.dll
 
Public uploadppt(ByVal uploadFiles As System.Web.UI.WebControls.FileUpload) As String
        If Not (uploadFiles.PostedFile Is Nothing) Then
            Dim path As String = "../UpLoadFolder/" & courseId & "/pptTmp/"
 
            Dim filesize As Integer = CInt(uploadFiles.PostedFile.ContentLength.ToString)
            If filesize > 83886080 Then
                Return "3"
            End If
 
            Dim fileName As String = uploadFiles.PostedFile.FileName
            Dim extendNameIndex As Integer = InStrRev(fileName, ".")
            Dim extendName As String = "." & Mid(fileName, extendNameIndex + 1)
            Dim newName As String = ""
            Try
                '// 验证是否为word格式
                If extendName = ".ppt" Then
                    Dim now As DateTime = DateTime.Now
                    newName = now.DayOfYear.ToString + uploadFiles.PostedFile.ContentLength.ToString
                    uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path + newName + extendName))
                Else
                    Return "1"
                End If
            Catch ex As Exception
                Return "0"
            End Try
            Return path + newName + extendName
        Else
            Return "0"
        End If
    End
    Public pptConvertFile(ByVal wordFilePath As System.Web.UI.WebControls.FileUpload) As String
 
        Dim ppt As PowerPoint.Application = New PowerPoint.Application
        Dim m1 As Microsoft.Office.Core.MsoTriState = 0
        Dim m2 As Microsoft.Office.Core.MsoTriState = 0
        Dim m3 As Microsoft.Office.Core.MsoTriState = 0
 
        Dim filePath As String = uploadppt(wordFilePath)
        If filePath = "0" Then
            Return "0"
        End If
        If filePath = "1" Then
            Return "1"
        End If
        If filePath = "3" Then
            Return "3"
        End If
        Dim fileName As Object = filePath
        filePath = System.Web.HttpContext.Current.Server.MapPath(filePath)
        Dim savepath As String = "../UpLoadFolder/" & courseId & "/pptTmp/"
 
        fileName = System.DateTime.Now.Year.ToString + System.DateTime.Now.Month.ToString + System.DateTime.Now.Day.ToString + System.DateTime.Now.Hour.ToString + System.DateTime.Now.Minute.ToString + System.DateTime.Now.Second.ToString
 
        Dim pp As PowerPoint.Presentation = ppt.Presentations.Open(filePath, m1, m2, m3)
        Try
            pp.SaveAs(System.Web.HttpContext.Current.Server.MapPath(savepath + fileName + ".html"), PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoTriStateMixed)
        Catch ex As Exception
            Response.Write("Error : " + ex.ToString)
        Finally
            If Not (pp Is Nothing) Then
                pp.Close()
            End If
        End Try
        'delete ppt file
        If File.Exists(filePath) Then
            File.Delete(filePath)
        End If
        Return (savepath + fileName + ".html")
    End
 
调用:
Dim uploadFiles As System.Web.UI.WebControls.FileUpload = Me.uploadfile
Dim message As String = pptConvertFile(uploadFiles)
 
 
 
将ppt转换为html
有两种方式,
ppt=>html:
http://www.codeproject.com/vb/net/litewait.asp
 
ppt=>image:
http://www.codeproject.com/cs/media/PowerpointBitmaps.asp
 
以下是将htm文件转换成mht格式文件,参考一下
 
public void SaveMht(string url,string path)
{
CDO.Message msg = new CDO.MessageClass();
CDO.Configuration c = new CDO.ConfigurationClass();
msg.Configuration = c;
msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressObjects, "", "");
ADODB.Stream stream = msg.GetStream();
stream.SaveToFile(path,ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
}
ppt转换为html:
PowerPoint.Application ppt = new PowerPoint.Application();
Microsoft.Office.Core.MsoTriState m1 = 0;
Microsoft.Office.Core.MsoTriState m2 = 0;
Microsoft.Office.Core.MsoTriState m3 = 0;
PowerPoint.Presentation pp = ppt.Presentations.Open(this.FilePath,m1,m2,m3);
pp.SaveAs(this.SavePath +
this.FileName+".html",
PowerPoint.PpSaveAsFileType.ppSaveAsHTML,Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
pp.Close();
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值