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如何将查询出来的数据导出成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怎么导出excel表格的数据
excel导出网上找个插件。
但是如果excel或者wps是新版的,可以导出为csv,php内置有此方法函数。
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把MYsql数据库数据导出到excel表中?是ph...
昨天项目里有个新需客户希望把一据能导出成为Excel表刚开始用PHP原生输入Excel表格,发现效果不是很理想,于是找到一个比较著名的库:PHPExcel。下面是一个简单的demo,分享给大家,希望可以帮到有同样需求的朋友。
网页链接