Click here to Skip to main content
15,029,369 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Windows Forms with button click operation.

On button click the specified columns in excel should be exported to html.

I used "SaveAs" method. But not able to open the file format in any browser. Please help me how to export specific columns('B','D') to hmtl with cell color.

What I have tried:

''''
Dim xlApp As Excel.Application

Dim xlWB As Excel.WorkBook

Dim xlSH As Excel.WorkSheet

Dim str_File As String = "C:\Sample.xlsx"

xlApp = New Excel.Application

xlWB = xlApp.Workbooks.Open(str_File)
xlSH = xlWB.WorkSheets("merge") xlSH.SaveAs("C:\Sample.html")

'''
Posted
Updated 10-Mar-20 20:11pm

1 solution

_Worksheet.SaveAs(String, Object, Object, Object, Object, Object, Object, Object, Object, Object) Method (Microsoft.Office.Interop.Excel) | Microsoft Docs[^]
XlFileFormat enumeration (Excel) | Microsoft Docs[^]

Why don't you try to specify the format explicitly?
VB
xlSH.SaveAs("C:\Sample.html", XlFileFormat.xlHtml)

(Terrible idea to store anything at the root of a drive. Modern OS's may even prevent you from doing that.)
   
Comments
Member 14747725 11-Mar-20 2:58am
   
Thank you.This is working to export the whole excel to html. PLEASE HELP HOW TO EXPORT PARTICULAR COLUMNS(say B,C,D)
phil.o 11-Mar-20 3:08am
   
You have to create another worksheet and copy only desired columns; then export the new worksheet.
EricERankin 25-Mar-20 13:43pm
   
You don't have to create another worksheet for this.
Instead, you can specify print area and Excel will export just that area.
For example, try something like this:

xlSH.PageSetup.PrintArea = "B1:D50"
Maciej Los 11-Mar-20 16:24pm
   
5ed!
phil.o 11-Mar-20 16:37pm
   
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900