您好,登錄后才能下訂單哦!
這篇文章主要介紹了PHPExcel如何導(dǎo)出2003和2007的excel文檔,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
具體如下:
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="訪問來(lái)源"; $k4="IP"; $k5="訪問時(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; /*----------寫入內(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; }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“PHPExcel如何導(dǎo)出2003和2007的excel文檔”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。