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;
    }
相关推荐
薿夜5 小时前
SpringSecurity(三)
android
zh_xuan10 小时前
Android Hilt实现依赖注入
android·hilt
freshman_y11 小时前
Qtcreator怎么新建安卓项目?编写一个五子棋游戏APP?
android·qt
时寒的笔记11 小时前
js逆向7_案例惠nong网
android·开发语言·javascript
肯多洛夫斯基12 小时前
安卓工控屏静默连WiFi全攻略
android
极梦网络无忧13 小时前
Android无障碍服务实现抖音直播间界面监控(场控助手核心原理)
android
城数派13 小时前
2000-2025年我国省市县三级逐8天日间地表温度数据(Shp/Excel格式)
数据库·arcgis·信息可视化·数据分析·excel
call me by ur name14 小时前
ERNIE 5.0 Technical Report论文解读
android·开发语言·人工智能·机器学习·ai·kotlin
dog25014 小时前
细看高维空间中距离度量失效
开发语言·php
kerli14 小时前
Compose 组件:Box 核心参数及其 Bias 算法
android·前端