php 怎么把数据导出到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 用PHPExcel往数据库导入大量数据
用set_time_limit(0);这样就避免了程序执行30秒自动停止了,可以一直执行
PHP实现把mysql数据库中的表的数据导出到excel
phpmyadmin导出选项中有excel类型。你安装个phpmyadmin