Excel – ColdFusion XLS “Export” and Character Encoding

character-encodingcoldfusionexcel

I am "exporting" data from a page to Excel using an HTML table. The table looks fine in the browser but in Excel special characters such as apostrophes, trademark symbols, etc. are improperly encoded. If I open the exported file in notepad and save it as ANSII encoded then open it in Excel everything looks fine again.

I tried setting the page encoding in ColdFusion using cfcontent, setencoding, and cfpagedirective with no luck so far. Any suggestions?

EDIT: As a temporary work around, the erroneous characters can be removed by saving the exported file to disk, opening it in Notepad, and then saving it again. Not exactly the best solution for the problem.

As for the strange characters:

® becomes ®

™ becomes â„¢

’ becomes ’

Best Solution

I ran into the same problem with the strange character 'Â' showing up in my Excel spreadsheet when it wasn't there in my HTML page which it came from.

Simply changing the cfcontent from: <cfcontent type="application/vnd.ms-excel> to: <cfcontent type="application/vnd.ms-excel; charset=windows-1252"> fixed the issue for me.