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:

1
2
3
4
<table>
  <thead>
      <tr>
          <th class="sortOpt1 highlight">STUDIO</th>

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

1
2
3
4
<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:

1
2
3
<cfheader name="Content-Disposition" value="attachment; filename=studioDailyReport_#dateFormat(now(), 'yyyymmdd')#.xls">
<cfcontent type="application/msexcel">
<!--- output HTML data here --->

Comments