Just a minor thing that I learned yesterday. As you might know, creating a pseudo Excel document is really easy using HTML. However, when you start to play around with idea, you will quickly notice that standard break tags (<br />) will create a new cell in the next row rather than creating a line break within the current cell. To get around this, all you have to do is add some Microsoft proprietary CSS to the BR tag:
<br style="mso-data-placement:same-cell;" />
Now, just to see a quick little example in action:
<!--- Store Excel-HTML output. ---> <cfsavecontent variable="strData"> <table border=".5pt"> <thead> <tr> <th> Degree </th> <th> Year </th> </tr> </thead> <tbody> <tr valign="top"> <td> Highschool Diploma <br style="mso-data-placement:same-cell;" /> Hackley School </td> <td> 1998 </td> </tr> <tr valign="top"> <td> Bachelor of Science in Computer Science <br style="mso-data-placement:same-cell;" /> Tufts University </td> <td> 2002 </td> </tr> </tbody> </table> </cfsavecontent> <!--- Set header for file attachment. ---> <cfheader name="content-disposition" value="attachment; filename=data.xls" /> <!--- Stream the content. ---> <cfcontent type="application/excel" variable="#ToBinary( ToBase64( strData ) )#" />
Running this code, we immediately get prompted to save this Excel file:
Notice that the line breaks within the first column did not create new cells. Again, a minor note but hugely useful when you want to whip together a quick little pseudo Excel file using HTML.
Want to use code from this post? Check out the license.