Every once in a while I encounter a problem with something so blindingly simple that
- I can’t imagine I haven’t tried it before, and
- I can’t believe no one else has documented the problem either.
ColdFusion 9 and later has a tag called <cfspreadsheet> which makes it dead simple to read, update, or create an Excel file. Want to plug the results of a query into a spreadsheet? Literally one tag with just three parameters.
There’s also function GetTempFile() that will create a guaranteed unique file on the server that you can then manipulate.
The obvious solution if you want to create a spreadsheet to download is to create a temp file, write to it with cfspreadsheet, then serve it up.
<cfset filename=GetTempFile(GetTempDirectory()) >
<cfspreadsheet action="write" overwrite="true" filename="#filename#" query="myquery">
<cfheader name="Content-disposition" value="attachment;filename=MyFile.xls">
<cfcontent type="application/msexcel" file="#filename#">
<cffile action="delete" file="#filename#">
It turns out this won’t work. You’ll get a Null Pointer Exception in the logs. Not because of anything you’d expect, though…it turns out that cfspreadsheet is relying on the file extension, and since GetTempFile() gives you a file ending in .tmp instead of .xls, it isn’t sure what to do with the file.
Solution: Find some other way to name your temporary file, and give it an .xls extension.
Last week, the webcomic XKCD ran a strip, Umwelt. Or perhaps it would be better to describe it as several comic strips.
As explained in the mouseover text, the title refers to the idea that because animals have different senses, each animal effectively inhabits a different reality. This can philosophically be extended to human perceptions.
As an art project, it’s the best use of browser-sniffing I’ve ever seen.
A lot of web developers have forgotten the lessons of IE6, and just as they used to build desktop websites coded only for one engine, now they’re coding mobile sites specifically for Webkit, even when other browsers would be perfectly capable of rendering the designs they want.
This is exactly the sort of thing that gave IE6 such a stranglehold on the web for so many years (and as much as we’d like it to be, it’s not dead yet), with Netscape/Mozilla and Opera completely marginalized until Firefox managed to break through. It’s not quite so bad because two companies are driving WebKit (Apple & Google) rather than just one (Microsoft), but let’s try to learn from history this time around instead of repeating it.
Call for action on Vendor Prefixes – The Web Standards Project
The Web Standards Project is a grassroots coalition fighting for standards which ensure simple, affordable access to web technologies for all.
Originally posted on Google+