Rails Excel 2007 export: Add Byte Order Mark to .erb template -


i exporting data excel making erb template xls file. following procedure recommended in railscast 362 making encoded exports.

the output opens fine in excel mac 2011, in excel 2007 characters é appear é because utf-8 encoded file being interpreted excel latin1.

according this answer excel 2007 correctly interpret utf-8 file if starts right byte order mark (bom).

taking @ @ hex version of output seems indeed doesn’t have bom.

there number of sources (like this plataformatec blog post) explain how add bom when rendering data inline in controller:

bom = "\377\376" bom + iconv.conv('utf-16le', 'utf8', data) 

my question – there way of getting template correctly interpreted excel 2007? or should go rendering data in controller?

i don't know why excel makes hard, do.

i tried using code myself when ran encoding problem. couldn't figure out how apply working with. did workaround instead.

i downloaded csv file indicated in railscast. opened file textwrangler, encodes properly. then, copied , pasted contents blank excel document (which reads text, , thus, not mess encoding). following that, selected column data fell under, , in menubar selected "data -> text columns". selected delimited list , entered comma delimiter (it defaults tab). finished , voila, there formatted excel doc.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -