第一步:引用组件: 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();