# PHPExcel代码的优化
>[success] 1. PHPExcel中的操作基本上都是链式操作
> 2. PHPExcel中的get*返回的都是一个实例
## 优化前代码
~~~
//$phpexcel->getActiveSheet()->setCellValue("C3","易风课堂");
//$phpexcel->getActiveSheet()->getStyle("C3")->getFont()->setSize(20);
//$phpexcel->getActiveSheet()->getStyle("C3")->getFont()->setBold(true);
//$phpexcel->getActiveSheet()->getStyle("C3")->getFont()->getColor()->setARGB('FFFF0000');
//$phpexcel->getActiveSheet()->getStyle('C3')->getFont()->setname("微软雅黑");
//$phpexcel->getActiveSheet()->getStyle("C3")->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
~~~
## 代码优化方式一
~~~
$sheet=$phpexcel->getActiveSheet();
$sheet->setCellValue("C3","易风课堂");
$font=$sheet->getStyle('C3')->getFont();
$font->setSize(20);
$font->setBold(true);
$font->setName("微软雅黑");
$font->getColor()->setRGB("FF0000");
$font->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE)
~~~
## 代码优化方式二
~~~
$sheet=$phpexcel->getActiveSheet();
$sheet->setCellValue("C3","易风课堂");
$font=$sheet->getStyle('C3')->getFont();
$font->setSize(20)->setName("微软雅黑")->setBold(true)->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE)->getColor()->setRGB('FF0000');
~~~