I am exporting data to Excel by making an erb template for the xls file. This is following the procedure recommended in Railscast 362 for making properly encoded exports.
The output opens fine in Excel for Mac 2011, but in Excel 2007 characters like é appear as é because the UTF-8 encoded file is being interpreted by Excel as Latin1.
According to this answer Excel 2007 will correctly interpret an UTF-8 file if it starts with the right Byte Order Mark (BOM).
Taking at a look at the hex version of the output it seems that indeed it doesn’t have a BOM.
There are a number of sources (like this Plataformatec blog post) that explain how to add a BOM when rendering the data inline in the controller:
BOM = "\377\376"
BOM + Iconv.conv('utf-16le', 'utf8', data)
My question is – is there a way of getting the template correctly interpreted by Excel 2007? Or should I go back to rendering the data in the controller?