Styling issues when generating an xls from HTML

A few notes to self on generating .xls files from HTML tables, particularly with CSS.

It appears that excel only has a particular ‘range’ of hex numbers you can use (at least for background colours). I was trying to use #eeeeee; for a while (which is obviously fine for HTML and for creating a PDF), but I couldn’t use that as a value in excel as the colours just weren’t displaying. Perhaps the colour was too close to white?

In any event, once I chose a darker colour (#bbbbbb) the background colour appeared fine!

Another issue was that HTML allows you to specifiy multiple CSS classes such as:

<table>
	<thead>
		<tr>
			<th class="sortOpt1 highlight">STUDIO</th>

This wasn’t working for me, so for that <th> I added an inline style:

<table>
	<thead>
		<tr>
			<th class="sortOpt1" style="background-color:##bbbbbb;">STUDIO</th>

If anyone is interested in the code to actually launch the open/save dialogue window, here it is:

<cfheader name="Content-Disposition" value="attachment; filename=studioDailyReport_#dateFormat(now(), 'yyyymmdd')#.xls">
<cfcontent type="application/msexcel">
<!--- output HTML data here --->
Post a Comment or Leave a Trackback

3 Comments

  1. October 19, 2007 at 8:54 am | Permalink

    Another Excel annoyance – it will automatically format certain values, unless you force them to a string by adding x:str to cell/row/table and specifying the xmlns.

    Example:

    12345678900000000000

  2. October 19, 2007 at 8:55 am | Permalink

    <html xmlns:x=”urn:schemas-microsoft-com:office:excel”>
    <table><tr><td x:str>12345678900000000000</td></tr></table>

  3. October 20, 2007 at 9:42 am | Permalink

    Ah I’ve wanted a way around that one.

    Thanks Peter :)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*