Excel to HTML conversions

Location: http://www.mvps.org/dmcritchie/excel/xl2html.htm      
Home page: http://www.mvps.org/dmcritchie/excel/excel.htm
[View without Frames]

XL2HTML and XL2HTMLX macros

Macro Code «  http://www.mvps.org/dmcritchie/excel/code/xl2htmlx.txt  «  Macro Code
Instructions to install a macro are on my Formula page

The generated code will be about one third the size of the humonguous code generated by Microsoft converters which attempt to make HTML look like an Excel page.  The primary purpose of XL2HTML is to generate a smaller file and let HTML do it's own thing rather than simulate Excel.

The XL2HTML and XL2HTMLx macros are really designed to create a smaller footprint without all of the extra garbage, fonts, colors.  Quite the opposite of the conversions provided in Excel.  For tables not concerning numbers, HTML does a much better job at formatting and my objective is to let HTML do what it does best without interference of adding information I don't want:  exact cells, colors, formatting, excessive hyperlinks, etc.  You definitely will not see the results of Conditional Formatting because that is difficult to pick up.

The Excel save as, save as webpage and HTML wizards on the otherhand try to specifically make everything look the same between Excel, MS Word, and HTML.  Excel particularly generates excessive HTML coding in order to generate XML code, styles, and round-tripping where you can take the HTML and actually go back to the actual Excel from just the HTML and all its added auxiliary files which you may not see at first glance.

The macros described simply show that it is possible to write out your own HTML code using macros and you can modify macros to do more specifically what you really want to do.  I try to include a lot of the features but specifically leave out space robbing font and exact size things, especially since I think HTML browsers generally do a much better job left to their own devices.  I also purposely drop some but not all of the hyperlinks.  so if you want more or less you will have to modify coding to fit your requirements, unlike working with an add-in or a program that you have no control over.

XL2HTML, converts selection on an Excel sheet to HTML

The selection to be converted may comprise the entire page. 

XL2HTMLX (extended), converts selection on an Excel sheet to HTML, including row/col headers

The selection to be converted may comprise the entire page.  You will be able to see the shaded A-B-C column headings and the shaded 1-2-3-4 row headings.

A brief look into what HTML is, limitations, etc.

What these macros do

    'Original coding and concept is based on
    'http://www.herber.de/mailing/020598v.txt
    ' Hans W. Herber * Microsoft Excel MVP
    'Major changes D.McRitchie, 1998-08- msgbox, close,
    ' http://www.mvps.org/dmcritchie/excel/code/xl2htmlx.txt
    ' Shading option, Column & ROW headings and will use right justification
    ' when specifically formatted into Excel.
    'Additional help Invoking IExplorer from VBA -
    ' From: "Chris Rae" posted Excel.programming 9Jun1999
    'rev. 2000-06-25, hyperlinks for http:// (not email)
    ' Include  Bold, Italic, Color (black for email)
    'rev. 2000-07-01, handle merged cells (Rob Bruce),
    ' additional changes: center justification,
    ' multiple cells with TR "line", if fits in 80 bytes,
    ' XL2HTML_Main will be used by both XL2HTML and XL2HTMLx,
    ' center justification.   Rev. 2000-07-02 added <BR> for Chr(10)
    'rev. 2000-07-03 for Center Across Selection (cell format)

Preparation of an Excel file for conversion using XL2HTML or XL2HTMLX

Macro Code   « http://www.mvps.org/dmcritchie/excel/code/xl2htmlx.txt  « Macro Code
Instructions to install a macro are on my Formula page
XL2HTMLX was used in the above examples.  XL2HTML was used in the example for Shortcut keys for Excel 2000.  The macro « code is available here« for both macros.
The main focus of this web page is on creating HTML tables to be inserted into your HTML coding and was described above.  Other HTML items continue.

Simple .BAT file to merge files

Was going to try to place coding into XL2HTML to embed some files and then realised there would be a problem incorporating code to include files in the very table that should be embedded. 

In the meantime while mulling this over a simple DOS .BAT file can be incorporated in a SHELL command using the same directory that you would output the HTML to from the Excel file. .

A simple .BAT file to copy 3 files into one output.

     c:
     cd c:\temp\billsweb
     copy part1.html +passlist.html +part3.html  composite.html
The above could be named PUSH.BAT and included in a macro as follows:
Sub push01()
  'Generate the HTML table, specifying
  Call XL2HTML_Main(0, "1T", "c:\temp\billsweb\passlist.html")
  'documented in http://wwww.mvps.org/dmcritchie/excel/xl2html.htm
  'push.bat  merges 3 files:  part1.html +passlist.html +part2.html into Composite.html
  Shell "c:\temp\billsweb\push.bat"
  Shell "notepad.exe c:\temp\billsweb\composite.html"
  Shell """c:\program Files\Internet Explorer\iexplore.exe"" c:\temp\billsweb\composite.html"
End Sub
The 1st option is without row/column headings, the 2nd option is 1 pass, and Timestamp, The 3rd option is the name of the output file overriding default.

The above "1T" will not generate HEAD, TITLE, BODY records, nor their closing tags, because file created from Excel will be placed in the middle of the merged files.

Internet Explorer, Netscape and Excel

This section will be moved to it's own page when sufficient new material accumulates.

Differences in versions of Excel

The versions of Excel have so many differences relative to generating HTML, and pasting HTML into Excel that when questions are posted to newsgroups concerning Excel and HTML you must indicate which version of Excel you are using.  The big thing in Excel 2000 is the ability to cut and paste from any Office Application into another Office 2000 Application with round-trip coding.  This results in bad (unreadable) HTML coding that is twice as large as might be coded by other means but it does work.  Excel 97 had earlier introduced HTML links into Excel.

Pasting IE Favorites into Excel 2000

The Favorites file is a space wasting set of directories, but they can be pasted into an Excel file by Exporting a Netscape compatible HTML file.  It really doesn't have the breadth (descriptive information) of a Netscape file but it will allow you to paste it into Excel and display the text and the link information.

Pasting Netscape Bookmarks into Excel 2000

View your Netscape bookmarks in IE5/IE6 and proceed from step 3 above.

Sorting Bookmarks or Favorites, and Sorted Menus

Bookmarks (Netscape), and Favorites (Internet Explorer)

The information in this topic has nothing to do with Excel, but relates to sorting and printing of bookmarks.

Printing Bookmarks.  Any of your Netscape bookmark files can be printed as they are HTML files (i.e. Bookmark.htm).  Your single IE Favorites must be exported to an HTML file first using Export from the file menu of Internet Explorer -- be very careful to rename the file so you do not wipe out your real Netscape bookmarks.

Display of the URL in a Hyperlink such as from a column of bookmarks can be done with a User Defined Function such as URL function on my Build Table of Contents page which has lots of information on hyperlinks.

Bookmarks:  Netscape 3 versions provide for sorting bookmarks.  Later versions of Netscape (4 and up) and Internet Explorer do not allow permanent sorting of bookmarks alphabetically.  In order to sort files properly (folders first) a space in inserted in front of each heading (directory) and then they can be sorted with Netscape 3.7.

Ever since IE came out neither Netscape nor IE can sort the bookmarks nicely.  But if you have an old Netscape version (version 3) you can sort the bookmarks very nicely after a little preparation.  If working from IE export the favorites as described earlier.  Edit a copy of Netscape bookmark file (in case you mess things up).  Each folder (heading item) should begin with a single space so they sort ahead of individual bookmarks in the topic.  You can use a Tilde after the space for folders you want at the very top.  Using an old «Netscape 3.7« version you can sort the bookmarks.  Check out the results, and rename your old bookmarks and new bookmarks.  If they were IE5 you can delete your old favorites and Import the new bookmark file into your favorites.  Working with over 800 bookmarks is not fun in the current versions of Netscape and IE5.  update: IE6 on Win98 still did not sort favorites.  IE6 on Win2000 automatically sorts favorites and does it properly with the folders first; nevertheless, you cannot export them as a sorted bookmark file.

The bookmarks file uses dictionary list (<dl>,<dt>,><dd>) the bookmark wizard mentioned below inserts heading levels and does not have bookmark things like last time used indicators.

IE did something to mess this up quite a bit.  In the imported bookmarks some of the folders are repeated later and not sorted or mixed in with the riff-raff uncategorized bookmarks.  Solution: delete all of the IE bookmarks then reimport the sorted favorite bookmarks.  2001-04-25.  When you have 616 directories, subdirectories, and urls working with favorites is not pleasant at all, actually it is next to impossible.  In Netscape I had 1723 directories, subdirectories, and urls and had no problem managing them and sorting them with Netscape 3.0. 

Freeware version of Download CustomMenu V4.30 Freeware Release on 10/28/2000, which provided a more friendly interface to bookmark type entries.  Not bad, if using bookmarks as bookmarks is your only use of bookmarks. http://www.yellowriversw.com/download.htm.  Available versions to process IE Favorites, and Netscape Bookmarks.

Bookmark Wizard « can be downloaded from Moon Software http://www.moonsoftware.com/ which creates a web page from your IE Favorites file.  The list is sorted with individual files above the sub-directory folders.  The opposite of the way I sort them, but they are organized unlike the Favorites. 

Current state of bookmark files:  The only decent treatment of bookmarks is from the Old Netscape that sorted bookmarks permanently, were regular HTML files that you could include descriptions of the articles, and have any number of additional (separate) bookmark files.  All of the other software to organize bookmarks and substitute for bookmarks is sheer nonsense, has large overhead by comparison, and you have no idea whether they are extracting marketing information from your usage.  The nonsensical IE Favorites list is strictly a marketing tool to place their own bookmarks in with your own, is difficult to manage, cannot be read as web page with bookmarks and descriptions, and Netscape has bought into this nonsense by no longer providing the means of permanently sorting bookmarks and also are tampering with your bookmarks by injecting their advertising bookmarks just like in IE.


Acknowledgments

My main interest in converting Excel to HTML was to generate efficient coding.  Machine generated coding lacks such things as formatting the table or rows instead of cells to generate the smallest coding.  The Internet Assistant generates terrible HTML coding, overriding HTML defaults that make HTML so flexible; but does make the result look the same as the Excel original.  While I dislike and do not have the web space for the humongous code generated by Internet Assistant, I have ended up including many of the features that waste space -- fonts, color, links.  I do not include default fonts in the generation.  My coding has its basis in about 30 lines of code where Hans Herber (see Related below) showed us that it could be done and how simple it can be.

Related

Excel to HTML Specifications and Syntax checking (most have downloads available)

HTML information on Microsoft sites

HTML information on non MS sites

Stripping out the Garbage from MS conversions to HTML

Eliminating the round tripping code, and font changes, especially those that are unnecessary and take up lots of space in coding.

File Input/Output

Font List

Web Queries

Web Queries via Excel from the MS KB

Other MS KB articles related to HTML


This page was introduced on July 2, 2000. 

[My Excel Pages -- home]    [INDEX to my site and the off-site pages I reference] 
[Site Search -- Excel]     [Go Back]    [Return to TOP

Please send your comments concerning this web page to: David McRitchie mailto:DMcRitchie@msn.com.