本文目录一览:

PHP如何导出当前页面中的表格至Excel

1.

这属于php的技术;

2.

php可以用PHPExcel直接导出成excel文件;

代码如下:

require_once("../lib/excelcreator.class.php");

$myxls

=

new

ExcelCreator

("中文Excel");

$aTableHead

=

'

Row

ss:AutoFitHeight="0"

CellData

ss:Type="String"Name3/Data/Cell

CellData

ss:Type="String"Surname3/Data/Cell

/Row';

$aTableBody

=

'

Row

ss:AutoFitHeight="0"

CellData

ss:Type="String"Schwarz3/Data/Cell

CellData

ss:Type="String"Oliver3/Data/Cell

/Row';

$aTableBottom

=

'

Row

ss:AutoFitHeight="0"

CellData

ss:Type="String"123/Data/Cell

CellData

ss:Type="String"Peter3/Data/Cell

/Row';

$workSheet

=

$myxls-createWorkSheet

(

"中文sheet1",

$aTableHead,

$aTableBody,

$aTableBottom

);

echo

$myxls-createExcel

(

$workSheet

);

php导出数据到excel 格式设置

$name = iconv("utf-8","gbk",'二级学院列表');;

header("Content-Type: application/vnd.ms-excel");

header("Content-Disposition: attachment; filename=$name.xls");

//第三行的 name.xls这个xls可以自己改,不过大数据的导出建议使用专业的类,如phpexcel.

php 怎么把数据导出到excel表格

php 把数据导出到excel表格有多种方法,比如使用 phpExcel 等,以下代码是直接通过 header 生成 excel 文件的代码示例:

?php

 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 "tabletr";

 //导出表头(也就是表中拥有的字段)

 while($row = mysql_fetch_array($res)){

  $t_field[] = $row['Field']; //Field中的F要大写,否则没有结果

  echo "th".$row['Field']."/th";

 }

 echo "/tr";

 //导出100条数据

 $sql = "select * from users limit 100";

 $res = mysql_query($sql);

 while($row = mysql_fetch_array($res)){

  echo "tr";

  foreach($t_field as $f_key){

   echo "td".$row[$f_key]."/td";

  }

  echo "/tr";

 }

 echo "/table";

?