1个回答
展开全部
下载phpexcel
require '/api/PHPExcel.php';//加载phpexcel
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getDefaultStyle()->getFont()->setName( '微软雅黑');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(14);
$objPHPExcel->getActiveSheet()->getStyle("A1:L1")->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
$objPHPExcel->getActiveSheet()->getStyle("A1:L1")->getFont()->setBold(TRUE);
$objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFill()->getStartColor()->setARGB('FF6FA0EC');
$ths=array('A1','B1');
$objPHPExcel->getActiveSheet()->setCellValue('A1', '用户名');
$objPHPExcel->getActiveSheet()->setCellValue('B1', '密码');
$objPHPExcel->getActiveSheet()->getColumnDimension( 'A')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension( 'B')->setWidth(12);
$size=count($passwords);
if($passwords){
for($i=0;$i<$size;$i++){
$objPHPExcel->getActiveSheet()->setCellValue("A".($i+2), $lists[$i]['username']);
$objPHPExcel->getActiveSheet()->setCellValue("B".($i+2), $lists[$i]['mima']);
}
}
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('Excel表');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$outputFileName = "fileaname";//文件名字
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.iconv('UTF-8','GB18030',$outputFileName).'.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
//$objWriter->save(DT_ROOT.'file/cache/');
$objWriter->save('php://output');
require '/api/PHPExcel.php';//加载phpexcel
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getDefaultStyle()->getFont()->setName( '微软雅黑');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(14);
$objPHPExcel->getActiveSheet()->getStyle("A1:L1")->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
$objPHPExcel->getActiveSheet()->getStyle("A1:L1")->getFont()->setBold(TRUE);
$objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFill()->getStartColor()->setARGB('FF6FA0EC');
$ths=array('A1','B1');
$objPHPExcel->getActiveSheet()->setCellValue('A1', '用户名');
$objPHPExcel->getActiveSheet()->setCellValue('B1', '密码');
$objPHPExcel->getActiveSheet()->getColumnDimension( 'A')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension( 'B')->setWidth(12);
$size=count($passwords);
if($passwords){
for($i=0;$i<$size;$i++){
$objPHPExcel->getActiveSheet()->setCellValue("A".($i+2), $lists[$i]['username']);
$objPHPExcel->getActiveSheet()->setCellValue("B".($i+2), $lists[$i]['mima']);
}
}
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('Excel表');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$outputFileName = "fileaname";//文件名字
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.iconv('UTF-8','GB18030',$outputFileName).'.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
//$objWriter->save(DT_ROOT.'file/cache/');
$objWriter->save('php://output');
更多追问追答
追问
为什么你的phpexcel路径这么神奇,,,不是在class里面的么
追答
路径是根据你放的位置未定的,可以修改的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询