[英]Excel to HTML using VB.Net
In a Windows form, I need to export data (Columns A to C) from Excel to HTML.在 Windows 窗体中,我需要将数据(A 列到 C 列)从 Excel 导出到 HTML。
I am trying as below but getting "Public member 'NamedaRanges' on type 'Worksheet' not found" in namedRanges.我正在尝试如下,但在namedRanges中得到“未找到'Worksheet'类型的公共成员'NamedaRanges'”。 Not able to verify after that whether it will save HTML successfully.之后无法验证是否会成功保存 HTML。 Please help to solve this.请帮助解决这个问题。
Private Sub Button_click()
xlSheet=xlWB.Worksheets("Sheet3")
xlSheet.NamedRanges.SetPrintArea
(xlSheet.Cells.GetSubrange
("A1",C1"))
xlSheet.SaveAs(FileName:="C:\Users\
Sample.html",FileFormat:=xlHtml)
End Sub
For non-contiguous ranges you may have to copy to a temporary sheet as a contiguous range and export that对于非连续范围,您可能必须将其作为连续范围复制到临时表并导出
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Const folder = "C:\tmp\"
Const xlFile = "test1.xlsx"
Const htmlfile = "export.html"
Dim xls As New Excel.Application
Dim wb As Workbook
Dim ws As Worksheet, wsHtml As Worksheet
wb = xls.Workbooks.Open(folder & xlFile, False, True) ' no link update , radonly
ws = wb.Worksheets("Sheet3")
' create temp sheet, copy range to it, export and then delete it
wsHtml = wb.Sheets.Add()
ws.Range("A:A,C:C").Copy(wsHtml.Range("A1"))
wsHtml.PageSetup.PrintArea = wsHtml.Columns("A:B").Address
wsHtml.SaveAs(Filename:=folder & htmlfile, FileFormat:=44) ' html
xls.DisplayAlerts = False
wsHtml.Delete()
xls.DisplayAlerts = True
wb.Close(False)
xls.Quit()
MsgBox("Exported to " & folder & htmlfile)
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.