求教VB将excel转换为网页文件的代码!
各位老师跪求一段VB将某个文件夹里面的文件,excel转换为网页文件的代码,网上很少介绍这方面的内容,找到一行代码看不懂。
xlSheet.SaveAs FileName:="c:/te.htm",FileFormat:=xlHtml
请各位路过老师指点一下。谢谢!
程序代码:
Public Class Form1
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlhtml As Microsoft.Office.Interop.Excel.XlFileFormat
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim XlsxDir As String = "D:\Documents\Desktop\tt\"
Dim HtmlDir As String = "D:\Documents\Desktop\tt\html\" '必须已存在
Dim sFile As String
xlApp = CreateObject("Excel.Application") '创建EXCEL对象
sFile = Dir(XlsxDir)
Do While (Not sFile = "")
Debug.Print(sFile)
xlBook = xlApp.Workbooks.Open(XlsxDir & sFile)
xlBook.SaveAs(HtmlDir & sFile & ".html", FileFormat:=xlhtml.xlHtml)
xlBook.Close(False) '关闭工作簿
sFile = Dir()
Loop
xlApp.Quit() '结束EXCEL对象
xlApp = Nothing '释放xlApp对象
Debug.Print("OK")
End Sub
End Class
程序代码:
Private Sub Save()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim sFile As String
XlsxDir = "d:\Documents\Desktop\tt\"
HtmlDir = "d:\Documents\Desktop\tt\html\" '必须已存在
sFile = Dir(XlsxDir)
Do While (Not sFile = "")
Debug.Print (XlsxDir & sFile)
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(XlsxDir & sFile) '打开Excel文件
xlBook.SaveAs HtmlDir & sFile & ".html", Excel.XlFileFormat.xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False '保存html文件
xlBook.Close (False) '关闭Excel文件
Set xlBook = Nothing
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
sFile = Dir()
DoEvents
Loop
Debug.Print ("OK")
End Sub
程序代码:
Sub SaveHtml()
XlsxDir = "d:\Documents\Desktop\tt\"
HtmlDir = "d:\Documents\Desktop\tt\html\" '必须已存在
sFile = Dir(XlsxDir)
Do While (Not sFile = "")
Workbooks.Open Filename:=XlsxDir & sFile
ActiveWorkbook.SaveAs Filename:=HtmlDir & sFile & ".html", _
FileFormat:=xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
sFile = Dir()
DoEvents
Loop
End Sub
程序代码:Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim sFile As String
XlsxDir = App.Path & "\w\"
HtmlDir = App.Path & "\w\html\" '必须已存在
'XlsxDir = "d:\Documents\Desktop\tt\"
'HtmlDir = "d:\Documents\Desktop\tt\html\" '必须已存在
sFile = Dir(XlsxDir)
Do While (Not sFile = "")
Debug.Print (XlsxDir & sFile)
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(XlsxDir & sFile) '打开Excel文件
xlBook.SaveAs HtmlDir & sFile & ".html", Excel.XlFileFormat.xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False '保存html文件
xlBook.Close (False) '关闭Excel文件
Set xlBook = Nothing
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
sFile = Dir()
DoEvents
Loop
Debug.Print ("OK")
End Sub