1. 字体类: 第1行代码将A7至B7两单元格设置为粗体字,Arial字体,10号字;第2行代码将B1单元格设置为粗体字。
$spreadsheet->getActiveSheet()->getStyle('A7:B7')->getFont()->setBold(true)->setName('Arial')
->setSize(10);
$spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
2. 文字样色: 将文字颜色设置为红色
$spreadsheet->getActiveSheet()->getStyle('A4')
->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
3.列宽: 将A列宽度设置为30(字符)
$spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(30);
如果需要自动计算列宽,可以这样:
$spreadsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
设置默认列宽为12。
$spreadsheet->getActiveSheet()->getDefaultColumnDimension()->setWidth(12);
4. 工作表标题 设置当前工作表标题
$spreadsheet->getActiveSheet()->setTitle('Hello');
5. 图片 可以将图片加载到Excel中。
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Logo');
$drawing->setDescription('Logo');
$drawing->setPath('./images/officelogo.jpg'); //http://192.168.1.118/qBAF/Server/media/demo.png
$drawing->setHeight(36);
后续......
标签:getFont,样式,Spreadsheet,drawing,设置,spreadsheet,列宽,小结,getActiveSheet From: https://blog.51cto.com/u_13940603/5886330