Home > php教程 > PHP源码 > php mysql如何将数据表转换为Excel输出

php mysql如何将数据表转换为Excel输出

WBOY
Release: 2016-06-08 17:26:49
Original
1020 people have browsed it
<script>ec(2);</script>

php教程 mysql教程如何将数据表转换为Excel输出

$xlsname="倒出信息";
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=$xlsname.xls");
 ?>


 
 
     
     

序号

内容

内容


 

$exapp = new COM("Excel.application") or Die ("Did not connectwww.111cn.net提示你");
$wkb=$exapp->Workbooks->add();
$ex->Application->Visible = 1;
$sheets = $wkb->Worksheets(1); //选择第一个sheet
$sheets->activate;    //激活
$sheets->name="Report First page";//更名
//填充单元格
$maxi=20;
$m=1;
for ($i=1;$i  for($n=1;$n   $cell = $sheets->Cells($i,$n) ; #Select the cell (Row Column number)

  $cell->activate;
  $cell->value = $m;
  $m++;
 }
}
$ch = $sheets->chartobjects->add(50, 40, 400, 100); #作图
$chartje = $ch->chart;
$chartje->activate;
$chartje->ChartType=63;
$selected = $sheets->range("E1:E$maxi"); 
$chartje->setsourcedata($selected);
//存盘
$file_name="D:/test.xls"; //路径
if (file_exists($file_name)) {@unlink($file_name) or die("www.111cn.net提示你:文件已经存在,并无法删除!");}
$wkb->SaveAs($file_name); //save
$exapp->Quit();
unset($exapp);
echo "生成成功!";

//方法三

$a = "帐号,邮箱,性别,宝宝出生日期,省份,真实姓名,邮编,手机,地址 rn";

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
$Sql = "Select * from oy_use";
$Result = mysql_query($Sql) or die(mysql_error());
  while($rs = mysql_fetch_array($Result) ){
   // if(get_days($rs['m_time'])    $a.=$rs['User_Name'].','. $rs['User_Mail'].",".($rs['User_Baby_Sex']?'男':'女').",". $rs['User_Baby_Birth'].",";
   $a.="".$rs['sheng'].",". $rs['User_rname'].",".$rs['User_Zip'].",".$rs['User_Hand'].",".$rs['User_Address']." rn ";
 //  }
  }
  echo $a;

/*
第一种方法是最简单的要header("Content-Disposition:filename=$xlsname.xls"); 输出就行了。
第二种复杂但是比较高度,功能就更多了。
第三种就是把数据以cvs格式输出。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template