快捷搜索:
来自 计算机编程 2019-12-01 04:19 的文章
当前位置: 67677新澳门手机版 > 计算机编程 > 正文

phpexecel本身的施用记录

$user_sql = "select * from `table`";

$user_list = $db->fetchAll($user_sql卡塔尔(英语:State of Qatar);//数据库查询

require_once dirname(__FILE__卡塔尔国 . '/../../class/PHPExcel.php';//加载phpexcel.php,根据自个儿项指标门径调度

$objPHPExcel = new PHPExcel();

$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");

//设置标题名称
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '编号')
->setCellValue('B1', '在眼线数'卡塔尔国
->setCellValue('C1', '手机')

->setCellValue('D1', '记录时间'卡塔尔;  

//循环种种数据,如若遇上手提式有线电电话机号码的多少导出,能够在对应的多寡前、后增多二个空格,到达将数据形成字符串的格局,令execl不是讲其当成科学数据法的方法展现出来
foreach ($user_list as $k => $v) {
$num=$k 2;
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$num, $v['id'])
->setCellValue('B'.$num, $v['online'])

->setCellValue('C'.$num, ' '.$v['phone_num'].' ')
->setCellValue('D'.$num, date('Y-m-d H:i:s',$v['dateline']));
}

$objPHPExcel->getActiveSheet(卡塔尔国->getColumnDimension('C'卡塔尔国->setWidth(20卡塔尔(قطر‎;//对某列单元格设置宽度

// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('sheet1');

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

$time_name = '在线人数'.date('YmdHis',time(卡塔尔(英语:State of Qatar)卡塔尔(قطر‎.'.xls';//设置下载时文件的暗中同意名

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename='$time_name'");
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 = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
die;

本文由67677新澳门手机版发布于计算机编程,转载请注明出处:phpexecel本身的施用记录

关键词: