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 Getting Started with Macros page
The
generated code will be about one third the size of the humongous 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 for an HTML Table 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.
Conditional Formatting was not going to be originally included in the conversion but after several years it is available now, using
some functions modified from Chip Pearson's original
“Conditional Formatting Colors” (VBA coding) -- an example of generated results can
be seen on my Conditional Formatting page. Some CSS (Cascading Style Sheets) code made the
addition of (black) borders possible so a fairly decent rendering in HTML
beyond really simple tables has resulted; nevertheless, the purpose
is to generate HTML code to be pasted in your own HTML coding, though
you can, of course, change the heading material to generate a complete
HTML page.
The Excel save as, save as webpage and HTML wizards on the other hand 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.
Subroutines included in the code, each calls the generalized XL2HTML_Main
XL2HTML ,
converts selection on an Excel sheet to an HTML Table
The selection to be converted may comprise the entire page.
XL2HTMLX (extended)
, converts selection on an Excel sheet to an HTML Table, 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.
XL2HTMLm, Multiple areas w/o headers based on marksepareas
Each area selected will generate a separate HTML Table.
XL2HTMLs, output multiple selected sheets
Each worksheet in a group of selected worksheets will generate a separate HTML Table.
A brief look into what HTML is, limitations, etc. (#HTML)
- In HTML multiple spaces are the equivalent of a single space. All multiple spaces
will be reduced to a single space. To guarantee an extra single space one must
code (non-breaking space).
- HTML is very good a determining it's own widths required for columns and the
width of a table.
- HTML does not print more than one page wide. Scrolling allows you
to view more to the right, and printing in Landscape allows you to print more
of the width than as Portrait.
on the screen.
What these macros do
'Original coding and concept is based 28 lines of code from
'http://www.herber.de/mailing/020598v.txt [archived copy]
' Hans W. Herber * Microsoft Excel MVP
'Major changes D.McRitchie, 1998-08- msgbox, close,
' http://www.mvps.org/dmcritchie/excel/xl2htmlx.txt
' Shading option, Column & ROW headings and will use center 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
for Chr(10)
'rev. 2000-07-03 for Center Across Selection (cell format)
'rev. 2001-08-11 multiple sheets, entire used content from each
'rev. 2001-08-11 for optional output dataset name in parameters
'rev. 2002-07-25 to right align numbers by default
'rev. 2002-08-24 to not right align empty cells
'rev. 2003-02-09 multiple areas (snake cols) see xl2HTMLa
' prob. not compatible with multiple sheets
'rev. 2003-09-07 TR align/bgcolor, TD left or right alignment space
'rev. 2003-09-07 Extra space for cells with A160, fix yesterday's alignment
'rev. 2003-09-25 TR align gets alignment required by majority in row
'rev. 2004-08-21 Change Shell invoking Internet Explorer
'rev. 2005-07-26 Conditional Formatting added: font/interior color, bold, italic
'rev. 2005-12-30 addition of (black) borders with css see my font.htm page
'rev. 2006-03-12 provide for cells larger than 1024 chars (.value instead of .text)
'rev. 2006-07-05 correction if lastcell is a merged cell
Changes to Shell invoking Internet Explorer
Have had to change the coding invoking Internet Explorer as older version no longer work,
note it is now “Explorer” intead of “IExplore”:
Dim RC As Long
'typical value of filename c:\temp\xl2test.txt
RC = Shell("Explorer " & filename, 1)
'the following continues to work for notepad
Shell "notepad " & filename
'the following is an Excel alternative
ActiveWorkbook.FollowHyperlink(filename)
Comparison of Generated File sizes (#comparison)
The file generated from XL2HTML is 57 KB with color fonts and background and limited
font sizing. Compare to the Excel generated Save As HTML size of 217 KB
with all of its round tripping code which preserves Excel's formulas etc.
You may examine the files and their generated HTML below.
Interpretation of Table:
Starting with the color sheet of the Excel file, using XL2HTML macro you will get a 57 KB file,
if you edit that 57 KB file in Front Page and save it you still have a 57 KB file, but
if you paste from Excel into Font Page to create your HTML it becomes a whooping 840 KB
HTML file (14.7 times a large as if you used XL2HTML). If you would like to
try your own tests these files are found in the folder
http://www.mvps.org/dmcritchie/excel/xl2html/ -- Naturally a typical HTML
would not simply consist of only a table. I am using Excel 2000, and Front Page 2002
in the above. The examples have merged cells involving both columns and rows and
single color cell in a row and all cells in a row with same color to make things
more interesting for conversions.
A conversion of the color sheet was attempted by Nvu which
provided 234 KB file, which was a terrible rendition and lost merged cells,
borders, and all color
(view result). In fairness you can't
paste HTML table with Firefox as browser into Excel, you have to
stick with Microsoft IE and Office Products for round tripping things.
Color, background and images not printing (#color)
Colors for Printing and Print Preview are controlled in IE from the setting under Internet Options, Advanced, “Printing”.
There is an option in Front Page that you would want to make sure you have turned on.
Tools, Page Options, HTML Source (tab),
[x] Preserve existing HTML
If you do any editing with Front Page you want to keep an eye on the
META tags in your HTML Headers, if they indicate
Front Page as the generator then you know Front Page has done
something more to your code than you probably wanted. I rarely
use FP to edit the code, it likes to stick in <DIV> and other things
when you paste code. I mostly uses NotePad (view source from IE),
HTML-Kit (for syntax checking), and Front Page (for spelling).
Preparation of an Excel file for conversion using XL2HTML
,
or XL2HTMLX
(#preparation)
Macro Code « http://www.mvps.org/dmcritchie/excel/code/xl2htmlx.txt
« Macro Code
Instructions to install a macro are on my Getting Started with Macros page
- Icons and shapes will not be reproduced. Remember this is
only a tool to create a small simple TABLE without all the space wasting bells and whistles.
- Hyperlinks will not be generated for =HYPERLINK(...,...) nor from
such things as www.abc.com presented instead of http://www.abc.com in order
to keep generated HTML small. Also consider the difficulties of
parsing HYPERLINK worksheet statements and determining what would be
wanted in HTML for such statements as:
=HYPERLINK("""" & A1 & "!" & B1 & """,""" & A1 & "!" & B1 & """")
=IF(D1=0,"David McRitchie",HYPERLINK("DMcRitchie%20%6Dsn.com","DavidMcRitchie"))
- The program does not change point size but will recognize color, bold, and italic,
so you might change some descriptive headings accordingly. See example:
Shortcut Keys in Excel 2000
, which was
created to extend but not replace information already found in Shortcut Keys in Excel 95.
- The program displays text rather than values. By displaying text you
see all of the formatted commas and periods. It also means that if you run the macro
while in the formula view, it will report the formulas because that is what you see.
If there are extra spaces you won't see them because multiple spaces are seen as a single space
in HTML. You could replace spaces with the non-breaking ( ) space character (&#160;) by substitution but
you'd defeat the real beauty of how HTML works left to it's own formatting devices.
- Since XL2HTML/XL2HTMLX will handle merged cells, it would be advantageous
to merge cells across columns so as not to interfere with the adjustment
of column widths. If you merge a cell across 3 columns those three columns
will occupy at least as much space as is required by any cell in the column or
any merged cell in the columns of merged cells.
- Merged columns can be hard to work with in Excel though, so this may be easier
to work with both the Excel and conversion to HTML. Use Center Across Selection in the format, cells, alignment and make sure Merged cells is not on. This will be recognized by XL2HTMLx.
- Use of Alt+Enter as a line break, CHR(10), to wrap cell is now recognized
by XL2HTMLx and will produce an HTML <BR> tag which will cause lines to
break within a cell at that point. In HTML
all cells are wrapped, but only when necessary to fit width of display, where
a line breaks would otherwise be determined by HTML.
Experiment by widening and narrowing window
  | A | B | C | D | E | F | G | H | I | J | K |
1 | Sample without merging cells |
| | |
Sample merging cells | | |
Sample merging cells |
2 | 3006 | 6d nails | 0.99 |
| 3006 | 6d nails | 0.99 | |
3006 | 6d nails | 0.99 |
3 | 3008 | 8d nails | 0.99 |
| 3008 | 8d nails | 0.99 | |
3008 | 8d nails | 0.99 |
Center Across Selection (Format,cells,alignment)
| A | B | C | D | E | F | G | H | I | J | K |
6 |
Center Across Selection |
|
Center Across Selection | x |
| Center Across Selection |
x |
7 | 3006 | 6d nails | 0.99 |
| 3006 | 6d nails | 0.99 | |
3006 | 6d nails | 0.99 |
8 | 3008 | 8d nails | 0.99 |
| 3008 | 8d nails | 0.99 | |
3008 | 8d nails | 0.99 |
in this example B6:C6,F6,J6 are empty; there is an "x" in G6 and K6
Note: HTML representation will not match Excel when HTML wraps or the content
exceeds the width of the affected cells in Excel. In Excel the content
may overlap adjacent empty cells but remain centered on the involved center across cells.
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.
See toolbars.htm for help in installing
toolbar buttons
in support of these 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 realized 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"
RC = Shell("Explorer " & "c:\temp\billsweb\composite.html",1)
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.
Material on Favorites, sorting bookmarks in favorites, exporting a bookmark file from
favorites has been moved to Favorites.
Acknowledgments
My main interest in converting Excel to HTML was to generate efficient coding of an HTML Table.
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. After being shown that macro code could generate an HTML table,
and becoming more familiar with VBA, it was simply a matter of time before incorporating
features in generation of HTML tables related to working on a mainframe creating and using
macros to help generate
DCF (Document Composition Language), and GML (Generalized Markup Language) documents.
HTML Specifications and Syntax & Link checking
(most have downloads available)
- HTML 4.01 Specification«, the
page I reference the most is the elements«.
Actually
I keep a copy on my HD see top of the specification for obtaining a zip file copy.
W3C Search
- HTML Interesting Information strictly HTML
(no Excel information at this link).
-
HTML-Kit
« (#html-kit),Chaminda Wickremasinghe (Chami), provides a free editor and
includes David Raggett's "Tidy HTML", which together provide a power editor, and
syntax checker.
HTML-Kit has it's own
newsgroups
[
news://html-kit.com/chami.public.htmlkit.misc] and
tutorials.
Learning the terminology of different menus and toolbars is covered very nicely in
HTML Kit: A User Manual (pdf) by Paul Strickberger part of
SUL Web Publishing Guidelines collection.
Using HTML-Kit with Firefox: edit, preferences, save, [x] Windows file format – so you use CRLF (or is it LF) instead of CR.
Support Documents [Help].
Favicon generators (for usage see favicon in wikipedia)
Screen Capturing software: SnagIt (payfor), PicPic (free for non-commercial use),
Free screen capture alternatives include Screenshot Captor, MWSnap at Mirek's Free Windows Software. Extensions for Firefox users include:
FireShot (Firefox extension) (1,352 KB),
Screengrab (86KB).
- Email from Excel and from HTML (email.htm)
- Make 100s of HTML files from skeletal code (make100s)
- Nvu - The Complete Web Authoring System WYSIWYG « (#nvu), A complete Web Authoring System for Linux Desktop users, as well as Microsoft Windows and Macintosh users to rival programs like FrontPage and Dreamweaver.
Nvu (pronounced N-view, for a "new view") makes managing a web site a snap. Now anyone can create web pages and manage a website with no technical expertise or knowledge of HTML. This means
you can copy and paste to create your HTML and see what you are doing
when you do it. Nvu is based on the Mozilla Composer code base.
In other words Nvu (/\) is just as bad as any other WYSIWYG renditions.
- HTML considerations for disabilities
- Spelling and Grammar Checking (related to maintaining good documents - not related to HTML or Excel)
- Translation of web pages ...
- Broken Links, identification
- Mail Merge, using Excel as the database
to print from Microsoft Word. Section on use of mailto: in HTML and in generating
email from a Excel spreadsheet.
HTML Conversions, to and from (other than Excel)
HTML information on Microsoft sites
HTML information on non MS sites
-
Charlie's VBA to Excel
to HTML code HomePage Converts an Excel
range to an HTML Table, Charles Balch, most formatting is preserved.
Font size, row & column height are ignored. Creates a smaller file
than the Internet Assistant in XL95/XL97 and Save As in XL2000 (Tools --> ...). Designed to convert
an Excel spreadsheet and automatically place it on the server using FTP. Of particular interest to teachers in putting grades out to the internet see examples of
the macros output in any link to grades
in Charlie's CIS Home Page
[href="http://cis.balch.org/cis/cis.html] -- note no passwords are used but the identity of each student is hidden in the coded name field, also of interest are his World Wide Web/HTML Information and
Reading Room links at the bottom of his CIS Home page. Code also works
well in Excel 2000.
- Daily Dose of Excel » HTML in Cells II, Dick Kusleika, create formatted text in a cell like
This is a test
from HTML notations in a cell like:
<html>This <string>is</strong> <font color='red'><em>a</em> test</font>
Note if you use this be advised that my XL2HTML for simplicity of generated HTML does not process multiple font colorations within a cell.
-
How to create formatted messages in Microsoft Outlook
Three methods to send formatted messages in Outlook. Remember that
Outlook 97 cannot handle HTML format messages, and that rich-text (RTF)
works only with Outlook and the Exchange client and requires a setting not
just on the message format, but also a setting for each recipients. Message-ID: <3c7475ac_1@newsa.ev1.net>
- Sending a range as the body of an Outlook message, Daniel Klan
XL2HTMLa (areas) version which handles multiple area.
will print shaded headings, and center each table. (new 2003-92-09). An Excel solution that
creates pictures of the areas into another sheet can be seen in Ron de Bruin's
Printing non-contiguous areas on one page
I have created an XL2HTMLX (extended) version which adds the grey shaded Column and Row headers.
IExplore is then invoked for a review and the example (coding) can be copied from view source into a permanent web page. As the actual purpose is to generate as little code as possible you will have to right justify any cells including numeric cells that you want right justified in your HTML code. The coding for the XL2HTMLX is based on Hans Herber's simple version.
Email from Excel and from HTML
An archived reply that creates an HTML file using a previously defined user function
to format the table row, based on the XL2HTML and XL2HTMLX above.
Very complex formula applied by default to thousands of cells.
Repeating Top Row(s) in HTML (when printed) using
<TH>...</TH>
Harald Staff has provided a macro to create a .GIF file
by taking a picture on the Excel spreadsheet.
Tom Ogilvy posted some support MS KB links for XL97 and one for XL5/95 on
1999-10-30
look at the entire thread in Google Usenet Archived postings.
For XL97 users the
Internet Assistant Wizard Update for Excel is newer than both SR-1 and SR-2
and fixes a potential serious problem; in addition, if you do not install this
newer file, the wizard will not work properly with FrontPage 98
I use a much less automated method than Charles Balch to transfer my web pages to
my website using WS-FTP LE. See details
Webbify Excel (oldlink),
Dermot Balson -- Update websites from Excel, Download files without web queries,
An Excel web browser, An excel web server.
HTML Writers Guild, valuable resources
from an organization of Web authors
HTML-Kit on the Web, Resources, Links
and Tutorials available to HTML writers.
Spider Web Woman Designs -- Resources,
some links to HTML, Front Page, and similar resources.
Symbols for HTML and Excel use«, and
Unicode symbols.
WWW -- Internet starting points, University of Leicester (Uk).
InformIT.com : Design & Creative Media > Web Design, will take awhile to go through this to see if it is worthwell, but
it was mentioned on LockerGnome [LG 2004-01-29]
HTML lists of links (#linklists)
HTML Things that look interesting
CSS - Cascading Style Sheets (#css)
- See Font Information on my site, also see my Colors page. Colored borders (bordercolor) in HTML tables.
- CSS Creator,
{Create CSS layout-based Web sites} If you know a little HTML and have no clue what CSS is about, this is a great learning tool. If you know CSS, this is a nice sandbox to do experiments. The tool creates CSS based on your preferences for fonts, headers, paragraphs, etc. The only major thing it can't do is create layouts without tables, which is a challenge for many. After you complete the CSS creator, it produces CSS code to insert into your Web site AND it lets you enter the URL of your Web site to see how it would look.[Meryl]
[LG 2003-09-03].
- CSS Examples, VisiBone Style Sheet Examples [Commercial]
- CSS Level 1 and CSS-P Quick Reference Chart (1)
- More CSS creation links [LG 20031009].
- Free Programming Tutorials,
some html, css, vba, etc, etc.
JavaScript (#JavaScript)
XML references for possible future use (#xml)
Stripping out the Garbage from MS conversions to HTML (#filter)
Eliminating the round tripping code, and font changes, especially those that
are unnecessary and take up lots of space in coding.
- The Office 2000 HTML Filter 2.0 (Download Center) will remove all Office 2000 extra formatting tags from an HTML file.
(link removed for Msohtmf2.aspx)
Microsoft apparently never wants you to directly link to something on their site,
wants you to always have to use at least 3 clicks and exposure to some kind of ads, so
when the above breaks again, and it will, you can do your own search for the HTML Filter
and perhaps this link will help with a search -- it will also turn up varous usages so
you might want to try it even if the link above is still working.
--
http://search.office.microsoft.com/result.aspx?qu=html%20filter
- PureText Home Page, strips all formatting out of
the clipboard so you can paste plain text. Invoke with Window+V shortcut or with [PT] on taskbar next to clock.
- Save A Range To Clean HTML: A discussion of some of the options surrounding the conversion of worksheet ranges to HTML tables with my optimal solution to producing lean download-friendly web output from Excel. -- Rob Bruce
File Input/Output
Output statement
To create in your Options, General, "default file location" directory. (untested)
Open "Test.txt" For Output As #1
To create file in a specific directory
filename = "c:\temp\XL2test.htm"
If optOutputFile <> "" Then filename = optOutputFile
Open filename For Output As #1
Print #1, "<html><head><meta NAME=""robots"" CONTENT=""noi" & "ndex,nofollow"">"
Close #1
Shell "notepad " & filename
To create the file in the same path as the open workbook:
Dim fPath As String
fPath = ThisWorkbook.Path & Application.PathSeparator
Open fPath & "Text.txt" For Output As #1
Font List
Utilities (#utilities)
Search & Replace Utilities that work with HTML (#replace)
- Handy File Find and Replace v1.2 [361k] W9x/2k/XP FREE,
can search strings combinations, and replace, it also creates an HTML file of files found.
Works with RegExpr (Regular Expressions).
[LockerGnome 2002-04-12],
failed to produce the HTML Report /\
- ReplaceEm, uses RegExpr, look complicated, but if you were going to keep more than one copy of a site this would be ideal for customizing each site. (mirror-sites) /\
- InfoRapid Search & Replace,
3.1f, pure text search of html, permitting replace in the html.
(watch out looks like replace is automatic and not shown)
HTML -- compare (#compare)
Looking for free HTML comparisons, to be tested.
HTML -- syntax (#syntax)
Web Queries (#webquery)
Web Queries via Excel from the MS KB
Other MS KB articles related to HTML
Wiki (#wiki)
Just collecting some resources for now, expect this to become a major topic
on my web pages in future, or at least to have a place to start and maintain Wikis,
because the group effort is interesting (perhaps a bit scary too). (wiki)
- HTML to Wiki Converter - tables [online], converts the HTML table tags into their wiki equivalents, which were developed by Magnus Manske and are used in Wikipedia, the free encyclopedia, and all other wikis running on MediaWiki.
- html2wiki - Convert HTML text to wiki markup [documentation]
- Convert wiki markup to HTML
- Copy & Paste Excel to Wiki Converter, Created by Shawn M. Douglas
- I think I added an XL to WIKI in my macros, if not something easy to do.
XML and XUL Resources (#xul)
- XULPlanet.com, The XML User Interface Language (XUL) is a markup language for describing user interfaces. With XUL you can create rich, sophisticated cross-platform web applications easily.
Just collecting some resources for now, expect this to become a major topic
on my web pages in future.
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
send email comments
Copyright © 1997 - 2009, F. David McRitchie, All Rights Reserved