講的復(fù)雜了?。?/p>
成都創(chuàng)新互聯(lián)成都網(wǎng)站建設(shè)按需設(shè)計(jì)網(wǎng)站,是成都網(wǎng)站推廣公司,為集裝箱提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計(jì)服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計(jì)、前端HTML5制作、后臺程序開發(fā)等。成都網(wǎng)站設(shè)計(jì)熱線:18982081108
你先在一個(gè)完整版的PHPExcel之后解壓,在“Examples”目錄下會找到一大堆例子,根據(jù)你的要求這個(gè)“01simple-download-xlsx.php”文件就可以了!
注:你先保持“01simple-download-xlsx.php”文件所在的目錄位置不要變,測試好了,再改變名,移到別的地方,地方變了的話,文件里的 “require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';”的所在位置也要變!
我們要改動代碼很少,如下:
// Add some data
$objPHPExcel-setActiveSheetIndex(0)
-setCellValue('A1', 'Hello')
-setCellValue('B2', 'world!')
-setCellValue('C1', 'Hello')
-setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8
$objPHPExcel-setActiveSheetIndex(0)
-setCellValue('A4', 'Miscellaneous glyphs')
-setCellValue('A5', 'éàèùaê?????ü???ü?');
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
直接用的我的替換
$objPHPExcel-setActiveSheetIndex(0)//這個(gè)就是現(xiàn)實(shí)導(dǎo)出的表第一行,有幾列是根據(jù)你的那張表有幾列!
-setCellValue('A1', '單號')
-setCellValue('B1', '標(biāo)題')
-setCellValue('C1', '內(nèi)容')
-setCellValue('D1', '序列')
-setCellValue('E1', '數(shù)字');
//下面實(shí)現(xiàn)的就是建立數(shù)據(jù)庫連接,直接到表,你的連接數(shù)據(jù)庫、表、字段應(yīng)該與我的不一樣,你可以參考
$conn=@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫服務(wù)器連接錯誤".mysql_error());//連接mysql數(shù)據(jù)庫
mysql_select_db("temp",$conn) or die("數(shù)據(jù)庫訪問錯誤".mysql_error());//數(shù)據(jù)庫
mysql_query("set character set gb2312");
mysql_query("set names gb2312");
$sqlgroups="select * from test ";//查詢這一張表的條件
$resultgroups=mysql_query($sqlgroups);
$numrows=mysql_num_rows($resultgroups);
if ($numrows0)
{
$count=1;
while($data=mysql_fetch_array($resultgroups))
{
$count+=1;
$l1="A"."$count";
$l2="B"."$count";
$l3="C"."$count";
$l4="D"."$count";
$l5="E"."$count";
$objPHPExcel-setActiveSheetIndex(0)
-setCellValue($l1, $data['id'])//這就是你要導(dǎo)出表的字段、與對應(yīng)的名稱
-setCellValue($l2, $data['title'])
-setCellValue($l3, $data['content'])
-setCellValue($l4, $data['sn'])
-setCellValue($l5, $data['num']);
}
}
使用phpexcel插件。
?php
/**
*?erport
*?導(dǎo)出excel
*/
$dir?=?dirname?(?__FILE__?);
require?$dir?.?'/Class/db.class.php';
require?$dir?.?'/PHPExcel/PHPExcel.php';
$dbObj?=?new?db?();
$phpexcelObj?=?new?PHPExcel?();
for($i?=?1;?$i?=?3;?$i?++)?{
$what?=?"*";
$condition?=?"student?where?grade?=?"?.?$i?.?"?ORDER?BY?score?DESC";
$res?=?$dbObj-mySelect?(?$what,?$condition?);
if?($i??1)?{
$phpexcelObj-createSheet?();
}
$phpexcelObj-setActiveSheetIndex?(?$i?-?1?);
$sheetObj?=?$phpexcelObj-getActiveSheet?(?$i?);
$sheetObj-setTitle?(?$i?.?"年級"?);
$sheetObj-setCellValue?(?'A1',?'name'?)-setCellValue?(?'B1',?'score'?)-setCellValue?(?'C1',?'class'?);
$j?=?2;
foreach?(?$res?as?$key?=?$val?)?{
$sheetObj-setCellValue?(?'A'?.?$j,?$res?[$key]?['name']?)-setCellValue?(?'B'?.?$j,?$res?[$key]?['score']?)-setCellValue?(?'C'?.?$j,?$res?[$key]?['class']?);
$j?++;
}
}
$phpexcelObj-setActiveSheetIndex?(?1?);
$writerObj?=?PHPExcel_IOFactory::createWriter?(?$phpexcelObj,?'Excel5'?);
$writerObj-save?(?$dir?.?'/Excels/scores.xls'?);
根據(jù)下列編碼程序可以。
1./*** 批量導(dǎo)出數(shù)據(jù)* @param $arr 從數(shù)據(jù)庫查詢出來,即要導(dǎo)出的數(shù)據(jù)* ?$name excel表歌名*/
2.function expExcel($arr,$name){?require_once 'PHPExcel.php';
3. //實(shí)例化?$objPHPExcel = new PHPExcel();?/*右鍵屬性所顯示的信息*/
4.$objPHPExcel-getProperties()-setCreator("zxf") ?//?-setLastModifiedBy("zxf") ?//最后一? -setTitle('數(shù)據(jù)EXCEL導(dǎo)出') ?//標(biāo)題-setSubject('數(shù)據(jù)EXCEL導(dǎo)出') //主題setDescription('導(dǎo)出數(shù)據(jù)') ?//描setKeywords("excel") ? //標(biāo)記setCategory("result file"); ?//類別
5. //設(shè)置當(dāng)前的表格??$objPHPExcel-setActiveSheetIndex(0);// 設(shè)置表格第一行顯示內(nèi)容$objPHPExcel-getActiveSheet()? -setCellValue('A1', '業(yè)主姓名')?-setCellValue('B1', '密碼')-setCellValue('C1', '手機(jī)號碼'? -setCellValue('D1', '地址')
6.//設(shè)置第一行為紅色字體?-getStyle('A1:D1')-getFont()-getColor()-setARGB(PHPExcel_Style_Color::COLOR_RED);$key = 1;?/*以下就是對處理Excel里的數(shù)據(jù)。
在cmd控制臺,先進(jìn)入你mysql的bin目錄下。之后是mysqldump -u用戶名-p密碼 數(shù)據(jù)庫名 導(dǎo)出的數(shù)據(jù)庫文件名.sql 回車。有不明白的地方繼續(xù)問哈。
在使用PhpMyAdmin的時(shí)候經(jīng)常用到數(shù)據(jù)的導(dǎo)入和導(dǎo)出(Export/Import),但是在導(dǎo)入大數(shù)據(jù)的時(shí)候由于php上傳文件的限制和腳本響應(yīng)時(shí)間的限制,導(dǎo)致phpMyAdmin無法導(dǎo)入大數(shù)據(jù)。很多時(shí)候都是由于文件過大,從本地瀏覽上傳導(dǎo)入,容易中斷失敗,有沒有更好的方法呢?
方法:
在phpMyAdmin的目錄下,找到根目錄的config.inc.php文件,
打開config.inc.php文件,查找$cfg['UploadDir'],這個(gè)參數(shù)就是設(shè)定導(dǎo)入文件存放的目錄,這里把值設(shè)定為:ImportSQLFile。
在phpMyAdmin目錄下,建立以ImportSQLFile命名的文件夾,
把我們需要導(dǎo)入的數(shù)據(jù)文件,放到ImportSQLFile文件夾下面,非常簡單,
登入phpMyAdmin,選擇需要導(dǎo)入的數(shù)據(jù),點(diǎn)擊導(dǎo)航條上面的“導(dǎo)入”按鈕,
選中“從網(wǎng)站服務(wù)器上傳文件夾ImportSQLFile/中選擇:”選項(xiàng),并需要導(dǎo)入的數(shù)據(jù)文件,
最后點(diǎn)擊“執(zhí)行”,即可導(dǎo)入成功。
注意事項(xiàng)
如果在config.inc.php文件,沒有找到$cfg['UploadDir'],可以自己在文件中添加上去即可。
php導(dǎo)出數(shù)據(jù)有兩種方式,一種是通過封裝好的phpexcel導(dǎo)出,一種是通過table導(dǎo)出數(shù)據(jù),指定header就可以導(dǎo)出數(shù)據(jù)。
上面是導(dǎo)出到excel中的方法,當(dāng)然你也可以導(dǎo)出數(shù)據(jù)直接到數(shù)據(jù)庫,或者你也可以到處數(shù)據(jù)到文件中,這個(gè)主要看你導(dǎo)出數(shù)據(jù)的格式要求。
看你截圖顯示的是數(shù)組格式,可以通過循環(huán)遍歷然后導(dǎo)入到響應(yīng)的文件中。
網(wǎng)站題目:php怎么導(dǎo)出數(shù)據(jù)庫表 phpstudy怎么導(dǎo)出數(shù)據(jù)庫
瀏覽地址:http://chinadenli.net/article12/dodeggc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、網(wǎng)站設(shè)計(jì)公司、做網(wǎng)站、域名注冊、網(wǎng)站導(dǎo)航、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容