[亲测可用]phpexcel自定义单元格样式边框和日期数据类型的解决方法
1、phpexcel为整个表格加边框
第一钟方法:针对整个表格区域
$style_array = array( 'borders' => array( 'allBorders' => array( 'borderStyle' => 'thin', 'color' => array('rgb' => '808080'),//设置边框颜色 ) ) );
第二种方法:针对单个表格区域
$styleArray1 = array( 'borders' => array( 'bottom' => array( 'borderStyle' => 'dotted', 'color' => array('rgb' => '808080'), ), 'top' => array( 'borderStyle' => 'dotted', 'color' => array('rgb' => '808080'), ), 'left' => array( 'borderStyle' => 'dotted', 'color' => array('rgb' => '808080'), ), 'right' => array( 'borderStyle' => 'dotted', 'color' => array('rgb' => '808080'), ), ), );
2、将单元格为日期格式
$one['yqksrq']=(int)($value['yqksrq']/86400) + 25570; $sheet->getStyle($v.'2:'.$v.$total)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat :: FORMAT_DATE_YYYYMMDDSLASH);//
3、字体加粗
$sheet->getStyle($titCol . '1')->getFont()->setBold(true);
4、设置宽度
$sheet->getColumnDimension($titCol)->setWidth($cdarr[$key]);
5、设置居中
$sheet->getStyle($titCol . '1')->getAlignment()->setHorizontal('center');