Operating system-PHP CSV Export under Window Office open normally, but only one column opens under Mac system

Source: Internet
Author: User

CSV Export code:

Public Function Export_csv () {if ($id = $this->get_input (' resultid ') = = = ") {$this->msg (' parameter is incorrect ');        } $result = Call_mod_func (' admin/activity_mod ', ' Get_result ', Array ($id)); $str = "name, email, phone, number".        Php_eol;  $str = Iconv (' utf-8 ', ' gb2312 ', $str);            Chinese transcoding foreach ($result [' Rows '] as $row) {$name = Iconv (' utf-8 ', ' gb2312 ', $row [' name ']);            $email = $row [' email '];            $mobile = $row [' Mobile '];            $weixinid = Iconv (' utf-8 ', ' gb2312 ', $row [' Weixinid ']); $str. = $name. ',' . $email. ',' . $mobile. ',' . $weixinid.        Php_eol; } $filename = Date (' Ymd ', gettime ()).  '. csv ';        Set the file name header ("Content-type:text/csv");        Header ("Content-disposition:attachment;filename=". $filename);        Header (' cache-control:must-revalidate,post-check=0,pre-check=0 ');        Header (' expires:0 ');        Header (' Pragma:public ');    Echo $str; }

This piece of code
Under Apple System, open only one column in Excel:

Under Windows System, there are 4 columns open in Excel:

How do I change this code? To be compatible with multiple systems?
"If separated by semicolons, it is normal under the Mac system, only one column under Windows"

Reply content:

CSV Export code:

Public Function Export_csv () {if ($id = $this->get_input (' resultid ') = = = ") {$this->msg (' parameter is incorrect ');        } $result = Call_mod_func (' admin/activity_mod ', ' Get_result ', Array ($id)); $str = "name, email, phone, number".        Php_eol;  $str = Iconv (' utf-8 ', ' gb2312 ', $str);            Chinese transcoding foreach ($result [' Rows '] as $row) {$name = Iconv (' utf-8 ', ' gb2312 ', $row [' name ']);            $email = $row [' email '];            $mobile = $row [' Mobile '];            $weixinid = Iconv (' utf-8 ', ' gb2312 ', $row [' Weixinid ']); $str. = $name. ',' . $email. ',' . $mobile. ',' . $weixinid.        Php_eol; } $filename = Date (' Ymd ', gettime ()).  '. csv ';        Set the file name header ("Content-type:text/csv");        Header ("Content-disposition:attachment;filename=". $filename);        Header (' cache-control:must-revalidate,post-check=0,pre-check=0 ');        Header (' expires:0 ');        Header (' Pragma:public ');    Echo $str; }

This piece of code
Under Apple System, open only one column in Excel:

Under Windows System, there are 4 columns open in Excel:

How do I change this code? To be compatible with multiple systems?
"If separated by semicolons, it is normal under the Mac system, only one column under Windows"

Is this a difficult question? No one answered ....

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.