dongqi9125 2018-09-20 12:36
浏览 65

如果我有500或1000个字符,PHPExcel在一个单元格中的两种颜色不起作用

## export data into excel using php excel library into yii2 framework ##

<?php
foreach ($data as $key => $value) {
 if ($key == 'other') {
    $objRichText = new \PHPExcel_RichText();
    $lines       = explode("
", $data[$key]);
    $cnt         = 0;
    foreach ($lines as $k => $v) {
        $cnt++;
        if ($k < 50) {
            if (preg_match("/red/", $v)) {
                $run = $objRichText->createTextRun($v);
                $run->getFont()->setColor(new 
   PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED));
            } else {
                $objRichText->createText(addslashes($v));
            }
            //$run[2] = $objRichText->createTextRun('blueaddress ipv6 2405:200:a10:fc00::/64');
            //$run[2]->getFont()->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLUE));
        }
        //$k++;
        $objPHPExcel->getActiveSheet()->SetCellValue('BA' . $cnt, $objRichText);

    }
    /*$objPHPExcel->getActiveSheet()->mergeCells('BA1:BA'.$cnt);

    $cell = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('BA1');
    $style = $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow('BA1');
    $dstCell = \PHPExcel_Cell::stringFromColumnIndex($cell_name) . (string)($rowNo);
    $objPHPExcel->getActiveSheet()->setCellValue($dstCell, $cell->getValue());
    $objPHPExcel->getActiveSheet()->duplicateStyle($style, $dstCell);*/



    //$objPHPExcel->getActiveSheet()->getCell('BA1')->getValue();
    //$objPHPExcel->getActiveSheet()->removeColumn('BA');

    //$objPHPExcel->getActiveSheet()->SetCellValue($cell_name . $rowNo, $objRichText);

    //$data[$key] = implode("
",$lines);
} else {
    $objPHPExcel->getActiveSheet()->SetCellValue($cell_name . $rowNo, $value);
}

$cell_name++;
}

?>

red-admin config t
red-crypto key generate rsa
red-yes
red-1024
black-banner login
black-UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED
black-You must have explicit, authorized permission to access or configure 
black-device
black-Unauthorized attempts and actions to access or use this system may 
black-in civil and/or criminal penalties
black-All activities performed on this device are logged and monitored
black-GCTv20.7
black-banner motd
black-UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED
black-key chain ISIS-KEY
black-key 1
red-key-string clear R4G_IsIs_P33r.2O14
black-accept-lifetime 01:00:00 january 01 2014 infinite
black-send-lifetime 01:00:00 january 01 2014 infinite
black-cryptographic-algorithm HMAC-MD5
black-allow SNMP peer

I am trying to export data into excel.Although my data contains 2 color in a single cell and also it contains lots of characters and lines in a single cell. data is something like this where it says black and red font Should appear in respective color in excel. Above is my data for example. i tried PHPExcel_RichText Object if it exceeds 50 characters it doesn't work then

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型