1、设置表格高度、宽度
代码:
$objPHPExcel
->getActiveSheet()->getRowDimension(
‘6‘
)->setRowHeight(30);//行高
$objPHPExcel
->getActiveSheet()->getColumnDimension(
‘A‘
)->setWidth(15);//列宽
2、合并单元格
代码:
$objPHPExcel
->getActiveSheet()->mergeCells(
‘A1:P1‘
);
3、设置单元格样式(水平/垂直居中):
代码:
$objPHPExcel
->getActiveSheet()->getStyle(
‘A1‘
)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel
->getActiveSheet()->getStyle(
‘A1‘
)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
4、给特定单元格中写入内容:
代码:
$objPHPExcel
->getActiveSheet()->setCellValue(
‘A1‘
,
‘Hello Baby‘
);
注意:上方代码中有类引用静态属性的操作,在TP3.2框架内需要在PHPExcel_Style_Alignment前打上\,才能使用。
时间: 2024-10-06 00:38:37