php csv导出 在window下office打开正常,但在MAC系统下打开只有一列
csv导出代码:
public function export_csv(){ if(($id = $this->get_input('resultId')) == '') { $this->msg('参数有误'); } $result = call_mod_func('admin/activity_mod', 'get_result', array($id)); $str = "姓名,邮箱,手机,微信号" . PHP_EOL; $str = iconv('utf-8', 'gb2312', $str); //中文转码 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'; //设置文件名 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; }
这段代码
苹果系统下,用excel打开只有一列:
windows系统下,用excel打开有4列:
请问这代码要怎么修改?才能兼容多个系统呢?
【如果用分号分隔的话,就MAC系统下正常,windows下只有一列】
BA-BO
9 years, 8 months ago