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的潘潘16 分钟前
受限系统环境下的 WebView 能力演进:车载平台 Web 渲染异常的根因分析与优化实践
android·java·前端·aosp
建军啊20 分钟前
java web常见lou洞
android·java·前端
豆奶dudu35 分钟前
安卓应用签名生成+微信开放平台安卓应用签名
android·微信开放平台
AC赳赳老秦2 小时前
Dify工作流+DeepSeek:运维自动化闭环(数据采集→报告生成)
android·大数据·运维·数据库·人工智能·golang·deepseek
2501_944424122 小时前
Flutter for OpenHarmony游戏集合App实战之记忆翻牌配对消除
android·java·开发语言·javascript·windows·flutter·游戏
2501_944526422 小时前
Flutter for OpenHarmony 万能游戏库App实战 - 设置功能实现
android·javascript·flutter·游戏·harmonyos
m0_748240442 小时前
Laravel5.6核心更新全解析
开发语言·php
冬奇Lab3 小时前
【Kotlin系列11】协程原理与实战(下):Flow与Channel驯服异步数据流
android·开发语言·kotlin
_昨日重现3 小时前
Jetpack系列之Compose Scaffold
android·android jetpack
2501_944424123 小时前
Flutter for OpenHarmony游戏集合App实战之数字拼图打乱排列
android·开发语言·flutter·游戏·harmonyos