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;
    }
相关推荐
用户9272472502199 分钟前
PHP+JS+CSS+JSON 单页新闻系统实现方案
php
AirDroid_cn19 分钟前
OPPO手机怎样被其他手机远程控制?两台OPPO手机如何相互远程控制?
android·windows·ios·智能手机·iphone·远程工作·远程控制
尊治19 分钟前
手机电工仿真软件更新了
android
Ashlee_code3 小时前
什么是Web3?金融解决方案
开发语言·金融·架构·eclipse·web3·区块链·php
The Future is mine3 小时前
Python实现文件夹中文件名与Excel中存在的文件名进行对比,并进行删除操作
excel
xiangzhihong83 小时前
使用Universal Links与Android App Links实现网页无缝跳转至应用
android·ios
车载应用猿4 小时前
基于Android14的CarService 启动流程分析
android
没有了遇见4 小时前
Android 渐变色实现总结
android
雨白7 小时前
Jetpack系列(四):精通WorkManager,让后台任务不再失控
android·android jetpack
Sally璐璐8 小时前
IPSAN 共享存储详解:架构、优化与落地实践指南
开发语言·php