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