php 怎么把数据导出到excel表格
昨天项目里有个新需求,客户希望些数据能导出成为Excel表格,始用PHP原生输入Excel表格,发现效是很理想,于是找到一个比较著名的库:PHPExcel。下面是一个简单的demo,分享给大家,希望可以帮到有同样需求的朋友。
网页链接
PHP实现把mysql数据库中的表的数据导出到excel
php 据导出到excel表格有多法,比如使用 phpExcel 等,代码是直接通过 header 生成 excel 文件的代码示例:
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=xls_region.xls");
$cfg_dbhost = 'localhost';
$cfg_dbname = 'testdb';
$cfg_dbuser = 'root';
$cfg_dbpwd = 'root';
$cfg_db_language = 'utf8';
// END
//链接数据库
$link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname);
//选择编码
mysql_query("set names ".$cfg_db_language);
//users表
$sql = "desc users";
$res = mysql_query($sql);
echo "";
//导出表头(也就是表中拥有的字段)
while($row = mysql_fetch_array($res)){
$t_field[] = $row['Field']; //Field中的F要大写,否则没有结果
echo "".$row['Field']."";
}
echo "";
//导出100条数据
$sql = "select * from users limit 100";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)){
echo "";
foreach($t_field as $f_key){
echo "".$row[$f_key]."";
}
echo "";
}
echo "";
?>
php如何把mysql数据库导入到excel表格
如果你要求的excle不是很复杂 .可以用html的table表格来.因为excle的性可以打开xml文档.所以你可用html文件来当做excle文件.
如果比较复杂 ,就要使用phpexcle了
这个是网页自动导出的基本思路
如果只是导出几个少数的表和内容
你可以使用phpmyadmin的导出功能.能够实现导出excle文档.
php怎么把数据表中的数据导出到excel表中
如果你要求的excle不是很复杂 .可以用html的table表格来.因为excle的性可以打开xml文档.所以你可用html文件来当做excle文件.
如果比较复杂 ,就要使用phpexcle了
这个是网页自动导出的基本思路
如果只是导出几个少数的表和内容
你可以使用phpmyadmin的导出功能.能够实现导出excle文档.
PHP怎样将查询出来的数据导出成excel表格?
if($_POST['oksubmit']){
$filename="导文件名.xls";
header ('Content-type: application/x-msexcel');
header ("Content-Disposition: attachment; filename=$filename" );
echo "学\t";
echo "姓名\t\n";
for($i=0;$i<10;$i ){
echo $i."\t";
echo "姓名".$i."\t\n";
}
}
?>