CSV是(逗号分隔值)的英文缩写,通常都是纯文本文件,建议使用WORDPAD或是记事本(NOTE)来开启,再则先另存新档后用EXCEL开启,也可以直接使用excel打开,和excel文件一样.
php生成excel文件(csv)参考代码如下:
- <?php
- header("Content-type:application/vnd.ms-excel");
- header("Content-Disposition:attachment;filename= www.phpfensi.com test_data.xls");
-
- echo "姓名"."t";
- echo "年龄"."t";
- echo "学历"."t";
- echo "n";
- echo "张三"."t";
- echo "25"."t";
- echo "本科"."t";
- ?>
下面这种方法是从一个项目中摘取的(只支持1997-2003),t是Tab,代码如下:
- <?php
-
-
-
-
- public function excel(){
-
- header("Content-type:application/vnd.ms-excel;");
-
- header("Content-Disposition:filename=lamp_dtype.xls");
- $exc .= "类型名称t宿舍类别t宿舍面积t容纳人数t月租/人t备注tn";
- $dtype = D('dtype');
-
- $datas = $dtype->select();
-
- foreach($datas as $data){
- $exc .="{$data['name']}t{$data['type']}t{$data['area']}t{$data['capacity']}t{$data['rent']}t{$data['remark']}tn";
- }
-
- $exc =iconv("UTF-8","GB2312",$exc);
- echo $exc;
-
-
-
- exit();
- }
- ?>
|