http://www.web008.net

phpexecel自己的使用记录

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

$user_list = $db->fetchAll($user_sql卡塔尔(قطر‎;//数据库查询

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', '在眼线数'卡塔尔(英语:State of Qatar)
->setCellValue('C1', '手机')

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

//循环每一个数据,借使超出手提式有线电话机号码的多少导出,能够在相应的多寡前、后增多一个空格,到达将数据形成字符串的艺术,令execl不是讲其当成科学数据法的不二等秘书诀呈现出来
foreach ($user_list as $k => $v) {
$num=$k+2;
美高梅163888,$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'卡塔尔(英语:State of Qatar)->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)卡塔尔(英语: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;

郑重声明:本文版权归美高梅163888所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。