This is a creation in Article, where the information may have evolved or changed.
Previously input Excel when UTF8 always garbled or use other ways to convert UTF8 to GBK to show, hehe, in fact, is the output of CSV, later group of friends said need Utf8bom Excel to normal identification UTF8, today tested a bit, very cool, Save several lines of code than before.
BOM Information Reference:
http://zh.wikipedia.org/wiki/bit sequence notation
Golang implementation:
package main import ("OS" "Encoding/csv") func main () {f, err: = OS. Create ("Haha2.xls") if err! = Nil {panic (err)} defer F.close () f.writestring ("\XEF\XBB\XBF")//write Into UTF-8 BOM w: = csv. Newwriter (f) w.write ([]string{"number", "Name", "Age"}) W.write ([]string{"1", "Zhang San", "23°c"}) w.write ([]string{"2", "John Doe", "24"}) W.write ([]string{"3", "Harry", "+"}) w.write ([]string{"4", "Zhao Liu", "+"}) W.flush ()}
PHP Implementation:
<?php$datas = Array (Array (1, "Zhang San", +), Array (2, "John Doe", ","), Array (3, "Harry", +), array (4, "Zhao Liu", 26),); Header ("Content-type:application/vnd.ms-excel"), Header ("Content-disposition:filename=". Date (' Ymdhis '). ". XLS "); $fp = fopen (' Php://output ', ' W '), Fwrite ($fp, Pack ("H6", "EFBBBF")), $head = Array ("number", "Name", "Age"), Fputcsv ($fp, $head); foreach ($datas as $r) {fputcsv ($fp, $r);} Fclose ($FP);