php生成excel或php生成csv

一、php生成excel

使用phpexcel类文件生成

 

二、php生成csv

<?php
$action ="make";
if ($action=='make'){
$fp = fopen("demo_csv.csv","a"); //打开csv文件,如果不存在则创建
$title = array("First_Name","Last_Name","Contact_Email","Telephone"); //第一行数据

$data_1 = array("42343","423432","4234","4234");
$data_2 = array("4234","Last_Name","Contact_Email","Telephone");

$title = implode(",",$title); //用 ' 分割成字符串
$data_1 = implode(",",$data_1); // 用 ' 分割成字符串
$data_2 = implode(",",$data_2); // 用 ' 分割成字符串

$data_str =$title."\r\n".$data_1."\r\n".$data_2."\r\n"; //加入换行符
fwrite($fp,$data_str); // 写入数据
fclose($fp); //关闭文件句柄
echo "生成成功";
}
echo "<br>";
echo "<a href='?action=make'>生成csv文件</a>";
?>

你可能感兴趣的:(Excel)