澳门在线威尼斯官方 > 澳门在线威尼斯官方 > 澳门在线威尼斯官方phpexecel自己的使用记录

原标题:澳门在线威尼斯官方phpexecel自己的使用记录

浏览次数:119 时间:2019-12-13

->setCellValue('D1', '记录时间');  

$time_name = '在线人数'.date('YmdHis',time()).'.xls';//设置下载时文件的默认名

$user_list = $db->fetchAll($user_sql);//数据库查询

// 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

require_once dirname(__FILE__) . '/../../class/PHPExcel.php';//加载phpexcel.php,根据自己项目的路径调整

$objPHPExcel = new PHPExcel();

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

$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);//对某列单元格设置宽度

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

//循环每个数据,如果遇到手机号码的数据导出,可以在对应的数据前、后添加一个空格,达到将数据变成字符串的方式,令execl不是讲其当成科学数据法的方式显示出来
foreach ($user_list as $k => $v) {
$num=$k+2;
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$num, $v['id'])
->setCellValue('B'.$num, $v['online'])

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

// 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');

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

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
die;

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

$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");

本文由澳门在线威尼斯官方发布于澳门在线威尼斯官方,转载请注明出处:澳门在线威尼斯官方phpexecel自己的使用记录

关键词:

上一篇:PHP技师应当如何保证与时俱进

下一篇:没有了