php导了excel单元格部分字设置不同颜色

在这里插入图片描述

    public function exportDataTest(Request $request){
        $filename = time();
        $spreadsheet = new \PHPExcel();
        $spreadsheet->getActiveSheet()->getCell("A1")->setValue('dadada');
        $richText = new \PHPExcel_RichText();
        $styleObj = $richText->createTextRun('红红红');
        $styleObj->getFont()->setColor(new \PHPExcel_Style_Color("FFCC0000")); //设置颜色
        $styleObj = $richText->createTextRun('dadada');
        $styleObj->getFont()->setColor(new \PHPExcel_Style_Color("FF000000")); //设置颜色
        $styleObj = $richText->createTextRun('蓝蓝蓝');
        $styleObj->getFont()->setColor(new \PHPExcel_Style_Color("FF0000FF")); //设置颜色
        $styleObj = $richText->createTextRun('dadada');
        $styleObj->getFont()->setColor(new \PHPExcel_Style_Color("FF000000")); //设置颜色
        $styleObj = $richText->createTextRun('绿绿绿');
        $styleObj->getFont()->setColor(new \PHPExcel_Style_Color("FF12D712")); //设置颜色
        $styleObj = $richText->createTextRun('时光隧道');
        $styleObj->getFont()->setColor(new \PHPExcel_Style_Color("FFFF00FF")); //设置颜色
        $spreadsheet->getActiveSheet()->getCell("B1")->setValue($richText);
        // 导出excel
        ob_end_clean();
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $filename . '.xls');
        header('Cache-Control: max-age=0');
        header('Content-Type: text/html; charset=utf-8');
        //$objWriter = \PHPExcel_IOFactory::createWriter($spreadsheet, 'Excel5');
        $objWriter = \PHPExcel_IOFactory::createWriter($spreadsheet, "Excel2007");
       // $objWriter = IOFactory::createWriter($spreadsheet, 'Xls');
        $objWriter->save('php://output');
        exit;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值