22

How to convert HTML template to Excel file

Saicharan S M
  • 828
  • 3
  • 11
  • 25
  • Er....I'm not completely sure that's possible in general, since Excel works with spreadsheets and HTML has many elements other than `table`. If your HTML essentially consists of just a table, then you might want to read it using a scripting language with a DOM parser that can export data to Excel (eg Perl, Python, etc), grab all of the entries in the table, and put them in an Excel file. You might want to consider just dumping the table to csv (if the data is simple enough). –  Mar 05 '12 at 12:09
  • 1
    xls is a table of values. html is a fairly generic means of describing arbitrary presentation. I think you're going to need to explain a little more about what you're working with and what you're doing, because generically speaking, the two are unrelated enough that you're asking how to convert Spanish to C++. – mah Mar 05 '12 at 12:10
  • 1
    See http://stackoverflow.com/questions/3206775/export-html-table-to-excel-using-jquery-or-java – John Doe Mar 05 '12 at 12:11
  • If you use Internet Explorer, you can copy the data in a table and paste it directly into Excel. Probably not helpful if you're trying to write a "save to excel" feature, but if you're just needing to quickly grab tabular data from an html page, it's great! – Chris Fletcher Mar 05 '12 at 12:34
  • Yes i have to develop a java plug-in which uses the POI api's to convert html to excel. Just wanted to know is there is a simpler way to do convert html to excel as excel can read HTML content. Basically i wanted to know if there is a way to convert .html file to .xls (.xlsx) ? I cannot just change the file extension or type i.e file.html to file.xls as the content of file.xls will still be html. If there is a way to make the content file.xls to proper excel content please let me know. It will save me a lot of time. Thanks :) – Saicharan S M Mar 06 '12 at 05:01
  • Did you still find a solution to this? I intend to create one similar java module. I intend to use flying saucer or lobobo browser for HTML parsing which also applies CSS2 on it, then take the object model to convert into PDF and excel. – samarjit samanta Sep 13 '12 at 03:08
  • 1
    No i dint find a solution for this. I parser the HTML using the swings Html parser and for each tag i found i formatted the contents accordingly using POI and put it in an excel file. – Saicharan S M Sep 13 '12 at 09:02

3 Answers3

18

So long as Excel can open the file, the functionality to change the format of the opened file is built in.

To convert an .html file, open it using Excel (File - Open) and then save it as a .xlsx file from Excel (File - Save as).

To do it using VBA, the code would look like this:

Sub Open_HTML_Save_XLSX()

    Workbooks.Open Filename:="C:\Temp\Example.html"
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Temp\Example.xlsx", FileFormat:= _
        xlOpenXMLWorkbook

End Sub
Robert Mearns
  • 11,796
  • 3
  • 38
  • 42
2

We copy/paste html pages from our ERP to Excel using "paste special.. as html/unicode" and it works quite well with tables.

gamov
  • 3,789
  • 1
  • 31
  • 28
1

Change the content type to ms-excel in the html and browser shall open the html in the Excel as xls. If you want control over the transformation of HTML to excel use POI libraries to do so.

  • Yes i have to develop a java plug-in which uses the POI api's to convert html to excel. Just wanted to know is there is a simpler way to do convert html to excel as excel can read HTML content. Basically i wanted to know if there is a way to convert .html file to .xls (.xlsx) ? I cannot just change the file extension or type i.e file.html to file.xls as the content of file.xls will still be html. If there is a way to make the content file.xls to proper excel content please let me know. It will save me a lot of time. Thanks :) – Saicharan S M Mar 06 '12 at 05:00
  • 2
    You might want to check this: http://www.glump.net/howto/html_in_an_excel_xls_file – Parag Mande Mar 07 '12 at 05:21