dtdh11647 2015-07-12 09:56
浏览 42

phpExcel toRichTextObject跳过换行符

I'm unable to get my html text correctly transcripted in my Excel file. I've looked into HTML.php and tried to change the breakTag function to insert " " instead of PHP_EOL (I'm working on a mac) but it does not work either. If I change this function to insert "BBBB" instead I can see that string appearing in my cell, so the function is correctly called. I've also tried the example given in 42richText.php but it does not work either. The three lines are correctly colored but without breakline. Here is my code

$wizard = new PHPExcel_Helper_HTML;
$cellText = $wizard->toRichTextObject('<p>First line</p><p>Second line</p>');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($colText.$Row, $cellText);
$objPHPExcel->getActiveSheet()->getStyle($colText.$Row)->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->mergeCells($colText.$Row.':'.$colText.($Row+ $tableRows));

As keeping newlines is more imported for comprehension than text enrichment I've written a small function to get rid of html tags but keep line breaks:

function getRichTextFromHtml($text){
$text = str_replace("</p>","</p>
", $text);
$text = preg_replace("/(<\/?)(\w+)([^>]*>)/", " ",$text);
$text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
return $text;

}

    $cellText = getRichTextFromHtml('<p>First line</p><p>Second line</p>');
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('H'.$Row, $cellText);
    $objPHPExcel->getActiveSheet()->getStyle('H'.$Row)->getAlignment()->setWrapText(true);
    $objPHPExcel->getActiveSheet()->mergeCells('H'.$Row.':'.'I'.($Row+ $tableRows));

by calling this function I get my lines correctly splitted in my cell but I loose bold and other enrichment...

Can anyone help? Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录