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

php 复制代码
    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;
    }
相关推荐
跨界混迹车辆网的Android工程师37 分钟前
实现Android图片手势缩放功能的完整自定义View方案,结合了多种手势交互功能
android·交互
wyjcxyyy42 分钟前
打靶日记-PHPSerialize
android
Fine姐43 分钟前
The Network Link Layer: 无线传感器中Delay Tolerant Networks – DTNs 延迟容忍网络
开发语言·网络·php·硬件架构
hotlinhao6 小时前
php版的FormCreate使用注意事项
php·crmeb
安卓开发者12 小时前
Android RxJava 组合操作符实战:优雅处理多数据源
android·rxjava
阿华的代码王国12 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端
一条上岸小咸鱼12 小时前
Kotlin 基本数据类型(三):Booleans、Characters
android·前端·kotlin
Jerry说前后端12 小时前
RecyclerView 性能优化:从原理到实践的深度优化方案
android·前端·性能优化
鱼鱼说测试12 小时前
Jenkins+Python自动化持续集成详细教程
开发语言·servlet·php
alexhilton13 小时前
深入浅出着色器:极坐标系与炫酷环形进度条
android·kotlin·android jetpack