Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,

I need to generate Excel file using HTML table/contents. This HTML table is in stringbuilder currently. I need to do this console application(not asp.net - using response).

I tried Saving the html file with xls extension, but not working.


Could you please help me?

Thanks in advance.

What I have tried:

I tried Saving the html file with xls extension, but not working.
Posted
Updated 6-Nov-19 4:26am
v2
Comments
MadMyche 6-Nov-19 10:21am    
Please post the code for how you are creating the HTML Table version of the data.

You can try to create an HTML file having the table and open this file in a workbook. Then save the workbook in .xlsx format. The solution would look like this
Workbooks.Open Filename:="C:\Temp\Example.html"
   ActiveWorkbook.SaveAs Filename:= _
       "C:\Temp\Example.xlsx", FileFormat:= _
       xlOpenXMLWorkbook
 
Share this answer
 
Comments
Swati_g1985 7-Nov-19 1:45am    
Thanks...did some modification and it worked!
deepak21188 7-Nov-19 9:22am    
Great!
You cannot convert a file in that way. You need to find a converter application (use Google to search), or write your own.
 
Share this answer
 
You should really re-think the process; both HTML and Excel (in this instance) are filling the Presentation Layer.

It would be much more efficient and a better architecture to do a parallel creation of the HTML and XLS(x). The way to do this would be to create the cells in both simultaneously.
How to do this is going to depend on how the data is within the program. Without the code of how you are creating the HTML variant it is hard to know, so I am going to assume you are using some type of loop for this flowchart

1_. Creation of documents
1a. Create new Excel document
1b. Keep existing Stringbuilder

2_. Begin Loop
2a. Add a cell to the XLS
2b. Add a <TD> to the HTML
2x. End Loop

3_. Presentation
3a. Save the XLS, offer for download?
3b. Return the HTML
 
Share this answer
 

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