php動態(tài)數(shù)據(jù)excel,php動態(tài)語言

php 怎么把數(shù)據(jù)導(dǎo)出到excel表格

php 把數(shù)據(jù)導(dǎo)出到excel表格有多種方法,比如使用 phpExcel 等,以下代碼是直接通過 header 生成 excel 文件的代碼示例:

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、敘州網(wǎng)絡(luò)推廣、重慶小程序開發(fā)公司、敘州網(wǎng)絡(luò)營銷、敘州企業(yè)策劃、敘州品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供敘州建站搭建服務(wù),24小時服務(wù)熱線:18982081108,官方網(wǎng)址:muchs.cn

?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?配置

//鏈接數(shù)據(jù)庫

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

//導(dǎo)出表頭(也就是表中擁有的字段)

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

$t_field[]?=?$row['Field'];?//Field中的F要大寫,否則沒有結(jié)果

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

}

echo?"/tr";

//導(dǎo)出100條數(shù)據(jù)

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

?

怎么使用php把表格中的數(shù)據(jù)導(dǎo)入到excel中

下面是我寫的一個PHP導(dǎo)出數(shù)據(jù)到CSV問價的函數(shù),你到時候直接調(diào)用就行了

/**

*?導(dǎo)出CSV文件

*?@param?string?$fileName 文件名字

*?@param?string|array?$data?導(dǎo)出數(shù)據(jù),csv格式的字符串|數(shù)值數(shù)組

*?@param?string?$to_encoding?目標(biāo)轉(zhuǎn)換編碼

*?@param?string?$from_encoding?當(dāng)前編碼

*/

function?exportCSV($fileName?=?'',?$data?=?'',?$to_encoding?=?'gb2312',?$from_encoding?=?'utf-8')?{

$fileName?=?empty($fileName)???date('YmdHis')?:?$fileName;

//?文件標(biāo)簽

Header("Content-type:?application/octet-stream");

header("Content-type:?application/vnd.ms-excel;?charset=$from_encoding");

Header("Content-Disposition:?attachment;?filename=$fileName.csv");

$str?=?'';

if($data)?{

if(is_array($data))?{

foreach?($data?as?$v)?{

if(is_array($v))?{

foreach?($v?as?$vo)?{

$str?.=?(is_numeric($vo)???"'".$vo?:?$vo."").",";

}

$str?=?trim($str,?",")."\r\n";

}?else?{

$str?.=?(is_numeric($v)???"'".$v?:?$v).",";

}

}

$str?=?trim($str,?",")."\r\n";

}?else?{

$str?=?$data;

}

}

echo?mb_convert_encoding($str,?"gb2312",?"utf-8");

exit;

}

PHP導(dǎo)出100萬數(shù)據(jù)到excel

php導(dǎo)出數(shù)據(jù)excel有專門的庫,當(dāng)導(dǎo)出少量數(shù)據(jù)的時候速度很快,但是當(dāng)數(shù)據(jù)量大的時候就會存在服務(wù)器內(nèi)存不夠之類的。

所以在導(dǎo)出大量數(shù)據(jù)的時候就應(yīng)該分頁查詢數(shù)據(jù),避免服務(wù)器宕機(jī)。正好PHP提供了fputcsv函數(shù)可以將數(shù)據(jù)寫入到csv文件中。

這樣我們就可以使用PHP對數(shù)據(jù)進(jìn)行分頁查詢,再寫入到csv文件中。

php導(dǎo)出數(shù)據(jù)到excel 格式設(shè)置

$name = iconv("utf-8","gbk",'二級學(xué)院列表');;

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

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

//第三行的 name.xls這個xls可以自己改,不過大數(shù)據(jù)的導(dǎo)出建議使用專業(yè)的類,如phpexcel.

php怎么生成動態(tài)的表格,表頭和數(shù)據(jù)都是動態(tài)的

可以先放把表頭信息放到一個集合里,

然后把數(shù)據(jù)放入一個二維數(shù)組或二維的容器里

例如 :

后臺

String[] tis = {"7.1","7.2","7.3"};

ListString[] data = new ArrayListString[]();

data.add(new String[]{"1","2","3"});

data.add(new String[]{"4","5","6"});

data.add(new String[]{"7","8","9"});

request.setAttribute("tis", tis);

request.setAttribute("data", tis);

Jsp:

table

!-- 表頭 --

tr

c:forEach items="tis" var="ti"

td${ti}/td

/c:forEach

/tr

!-- 數(shù)據(jù) --

c:forEach items="data" var="ds"

tr

c:forEach items="ds" var="d"

td$27dcoex/td

/c:forEach

/tr

/c:forEach

/table

php?把數(shù)據(jù)庫中的數(shù)據(jù)?輸出到?Excel

方法一:

?php

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

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

$tx='表頭';

echo

$tx."\n\n";

//輸出內(nèi)容如下:

echo

"姓名"."\t";

echo

"年齡"."\t";

echo

"學(xué)歷"."\t";

echo

"\n";

echo

"張三"."\t";

echo

"25"."\t";

echo

"本科"."\t";

?

方法二:

PHPEXCEL

類庫,功能強大,支持win

Excel2003

,Win

Excel2007.下載類庫,里邊有例子

標(biāo)題名稱:php動態(tài)數(shù)據(jù)excel,php動態(tài)語言
文章路徑:http://muchs.cn/article36/hcjjsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站收錄、小程序開發(fā)、用戶體驗、域名注冊云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)