PHPExcel導(dǎo)出2003和2007的excel文檔功能示例
本文實(shí)例講述了PHPExcel導(dǎo)出2003和2007的excel文檔功能。分享給大家供大家參考,具體如下:
require_once 'common/excel/PHPExcel.php';
require_once 'common/excel/phpExcel/Writer/Excel2007.php';
require_once 'common/excel/phpExcel/Writer/Excel5.php';
include_once 'common/excel/phpExcel/IOFactory.php';
$objExcel = new PHPExcel();
//設(shè)置屬性 (這段代碼無(wú)關(guān)緊要,其中的內(nèi)容可以替換為你需要的)
$objExcel->getProperties()->setCreator("andy");
$objExcel->getProperties()->setLastModifiedBy("andy");
$objExcel->getProperties()->setTitle("Office 2003 XLS Test Document");
$objExcel->getProperties()->setSubject("Office 2003 XLS Test Document");
$objExcel->getProperties()->setDescription("Test document for Office 2003 XLS, generated using PHP classes.");
$objExcel->getProperties()->setKeywords("office 2003 openxml php");
$objExcel->getProperties()->setCategory("Test result file");
$objExcel->setActiveSheetIndex(0);
$i=0;
//表頭
$k1="編號(hào)";
$k2="推廣代碼";
$k3="訪問(wèn)來(lái)源";
$k4="IP";
$k5="訪問(wèn)時(shí)間";
$objExcel->getActiveSheet()->setCellValue('a1', "$k1");
$objExcel->getActiveSheet()->setCellValue('b1', "$k2");
$objExcel->getActiveSheet()->setCellValue('c1', "$k3");
$objExcel->getActiveSheet()->setCellValue('d1', "$k4");
$objExcel->getActiveSheet()->setCellValue('e1', "$k5");
//debug($links_list);
foreach($links_list as $k=>$v) {
$u1=$i+2;
/*----------寫(xiě)入內(nèi)容-------------*/
$objExcel->getActiveSheet()->setCellValue('a'.$u1, $v["id"]);
$objExcel->getActiveSheet()->setCellValue('b'.$u1, $v["num"]);
$objExcel->getActiveSheet()->setCellValue('c'.$u1, $v["referer"]);
$objExcel->getActiveSheet()->setCellValue('d'.$u1, $v["ip"]);
$objExcel->getActiveSheet()->setCellValue('e'.$u1, $v["dateline"]);
$i++;
}
// 高置列的寬度
$objExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
$objExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
$objExcel->getActiveSheet()->getColumnDimension('C')->setWidth(70);
$objExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$objExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
$objExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&BPersonal cash register&RPrinted on &D');
$objExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objExcel->getProperties()->getTitle() . '&RPage &P of &N');
// 設(shè)置頁(yè)方向和規(guī)模
$objExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
$objExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$objExcel->setActiveSheetIndex(0);
$timestamp = time();
if($ex == '2007') { //導(dǎo)出excel2007文檔
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="links_out'.$timestamp.'.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
} else { //導(dǎo)出excel2003文檔
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="links_out'.$timestamp.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《PHP數(shù)組(Array)操作技巧大全》、《php排序算法總結(jié)》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
php獲取數(shù)組元素中頭一個(gè)數(shù)組元素值的實(shí)現(xiàn)方法
這篇文章主要介紹了php獲取數(shù)組元素中頭一個(gè)數(shù)組元素值的實(shí)現(xiàn)方法,較為詳細(xì)的分析了數(shù)組操作中reset、next、current等函數(shù)的用法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12
關(guān)于Laravel Service Provider開(kāi)發(fā)設(shè)置延遲加載時(shí)遇到的問(wèn)題詳解
這篇文章主要給大家介紹了關(guān)于Laravel Service Provider開(kāi)發(fā)設(shè)置延遲加載時(shí)遇到的問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起看看吧。2018-01-01
php檢測(cè)apache mod_rewrite模塊是否安裝的方法
這篇文章主要介紹了php檢測(cè)apache mod_rewrite模塊是否安裝的方法,通過(guò)對(duì)apache mod_rewrite模塊相關(guān)函數(shù)的檢測(cè)實(shí)現(xiàn)該檢測(cè)功能,需要的朋友可以參考下2015-03-03
php中array_pad()函數(shù)用法及實(shí)例
在本篇文章里小編給大家整理的是一篇關(guān)于php中array_pad()函數(shù)用法及實(shí)例內(nèi)容,有興趣的朋友們可以跟著學(xué)習(xí)下。2021-08-08
php基礎(chǔ)知識(shí):類(lèi)與對(duì)象(3) 構(gòu)造函數(shù)和析構(gòu)函數(shù)
php基礎(chǔ)知識(shí):類(lèi)與對(duì)象(3) 構(gòu)造函數(shù)和析構(gòu)函數(shù)...2006-12-12

