PHPExcel可是个好东东,功能强大,下面这是一个phpExcel简易中文帮助手册,列举了各种属性,以及常用的操作方法,是每一个都用实例加以说明,希望对大家有所帮助。
引用PHPExcel
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
//或者include 'PHPExcel/Writer/Excel5.php'; 用于输出.xls的
$objPHPExcel = new PHPExcel(); //创建一个实例
也可用下面这种方式
设置当前的sheet
$objPHPExcel->setActiveSheetIndex(0);
设置sheet的标题
$objPHPExcel->getActiveSheet()->setTitle('Simple');
设置单元格宽度
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
设置单元格高度
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(40);
合并单元格
$objPHPExcel->getActiveSheet()->mergeCells('A18:E22');
拆分单元格
$objPHPExcel->getActiveSheet()->unmergeCells('A28:B28');
设置保护cell,保护工作表
$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
$objPHPExcel->getActiveSheet()->protectCells('A3:E13', 'PHPExcel');
设置格式
$objPHPExcel->getActiveSheet()->getStyle('E4')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('E4'), 'E5:E13' );
设置加粗
$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
设置水平对齐方式(HORIZONTAL_RIGHT,HORIZONTAL_LEFT,HORIZONTAL_CENTER,HORIZONTAL_JUSTIFY)
$objPHPExcel->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
设置垂直居中
$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
设置字号
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
设置边框
$objPHPExcel->getActiveSheet()->getStyle('A1:I20')->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
设置边框颜色
插入图像
设置单元格背景色
$objPHPExcel->getActiveSheet(0)->getStyle('A1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet(0)->getStyle('A1')->getFill()->getStartColor()->setARGB('FFCAE8EA');
最后输入浏览器,导出Excel