PHPExcel 2003 및 2007 excel 문서 인스턴스 내보내기
10553 단어 phpexcel
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();
// ( , )
$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=" ";
$k2=" ";
$k3=" ";
$k4="IP";
$k5=" ";
$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;
/*---------- -------------*/
$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');
//
$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') { // 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 { // 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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
php 그룹을 excel로 내보내기이것은 제가ci의helpers 아래에 보조 함수로 썼습니다. 코드는/applications/helpers/export_로 저장됩니다excel_helper.php하면 돼요....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.