用php如何把查询到的数据导进excel表格中去呢
展开全部
用 PHPExcel 这个类来处理。。
地址 http://phpexcel.codeplex.com/
地址 http://phpexcel.codeplex.com/
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public function public_excel() {
$tpl = $_GET[tpl];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
header("Content-Disposition:filename=".$tpl.".xls"); //输出的表格名称
$formid = 12;
$sql = "select * from v9_".$this->tablename ." order by dataid desc";
$info = $this->db->query($sql);
$datalist = array();
while($row = mysql_fetch_assoc($info)){
$datalist[] = $row;
}
pc_base::load_sys_class('form', '', '');
define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
require CACHE_MODEL_PATH.'formguide_output.class.php';
$formguide_output = new formguide_output($formid);
$forminfos_data = $formguide_output->get($datalist);
$fields = $formguide_output->fields;
echo "<table border='1'><tr>";
foreach($fields as $key=>$val){
echo "<td style=\"vnd.ms-excel.numberformat:@\">".$val['name']."</td>";
}
echo "</tr>";
foreach($datalist as $key=>$val){
echo "<tr>";
foreach($val as $k=>$v){
if($k!='dataid' && $k!='userid' && $k!='username' && $k!='datetime' && $k!='ip'){
echo "<td style=\"vnd.ms-excel.numberformat:@\">".$v."</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
这是我写的程序,你把里面的sql改了应该就能用了
$tpl = $_GET[tpl];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
header("Content-Disposition:filename=".$tpl.".xls"); //输出的表格名称
$formid = 12;
$sql = "select * from v9_".$this->tablename ." order by dataid desc";
$info = $this->db->query($sql);
$datalist = array();
while($row = mysql_fetch_assoc($info)){
$datalist[] = $row;
}
pc_base::load_sys_class('form', '', '');
define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
require CACHE_MODEL_PATH.'formguide_output.class.php';
$formguide_output = new formguide_output($formid);
$forminfos_data = $formguide_output->get($datalist);
$fields = $formguide_output->fields;
echo "<table border='1'><tr>";
foreach($fields as $key=>$val){
echo "<td style=\"vnd.ms-excel.numberformat:@\">".$val['name']."</td>";
}
echo "</tr>";
foreach($datalist as $key=>$val){
echo "<tr>";
foreach($val as $k=>$v){
if($k!='dataid' && $k!='userid' && $k!='username' && $k!='datetime' && $k!='ip'){
echo "<td style=\"vnd.ms-excel.numberformat:@\">".$v."</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
这是我写的程序,你把里面的sql改了应该就能用了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
网上搜一下 绝对搜的到 我看到过好多 呵呵
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询