HTML Writer should not use "_convertNbsp", when markup in cell

Topics: Developer Forum, User Forum
Feb 2, 2012 at 8:53 AM
Edited Feb 2, 2012 at 8:57 AM

Hi folks

I put this on the tracker:
 and just wanna put it here as tracker strips out Formating and Indentation

_/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/

Version 1.7.2

When there's Html markup in a cell, this code shouldnot be used:
PHPExcel\Writer\HTML.php Line 1010+

Markup like:
<h3>Tank you</h3>
       <li>Your time</li>
       <li>Your work</li>
will become:
 <h3>Thank you</h3><br/><ul><br/>&nbsp;&nbsp;&?nbsp;&nbsp;<li>For:<br/>&nbsp;&nbsp?;&nbsp;&nbsp;<ul><br/>&nbsp;&nbsp;&?nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;?<li>Hohe Energiedichte</li><br/>&nbsp;&nbsp;?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp?;<li>Your time</li><br/>&nbsp;&nbsp;&nbsp;&nb?sp;&nbsp;&nbsp;&nbsp;&nbsp;<li>Your work</li><br/>&nbsp;&nbsp;&nbsp;&nb?sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n?bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&?nbsp;&nbsp;&nbsp;</ul><br/>&nbsp;&n?bsp;&nbsp;&nbsp;</li><br/></ul><br/?>

### Solution(for me) ###
if($cellData == strip_tags($cellData)){
$cellData = $this->_convertNbsp($cellData);
$cellData = str_replace("\n", '<br/>', $cellData);


Feb 2, 2012 at 9:12 AM

Version 1.7.2 is a pretty ancient version of PHPExcel, 2 years old to be precise - 1.7.6 is the latest, with 1.7.7 only a week away from production release - and no longer contains the specific code that you're talking about.... so I'm not going to go back and patch old versions.

Additionally, HTML markup in a spreadsheet cell isn't handled as markup by Excel itself, it's simply a string of data, so I see no reason to put in a lot of logic to try and represent something that doesn't exist in Excel/Open Office/Gnumeric/etc. If this is critical to you, then you should build your own custom HTML writer to handle markup in Excel strings

The HTML->Rich Text Run helper that's on the roadmap for this year's releases may be of some help to you

Feb 2, 2012 at 10:22 AM

Sure it's an old Version, can not switch to newer version for now ;-)
But, good to hear it's no longer used.

As for "HTML markup in a spreadsheet cell isn't handled as markup by Excel itself"
Im are talking about


and this file will be looked at in the browser, so the markup should be valid.
It is not about " to handle markup in Excel"


Feb 2, 2012 at 10:32 AM

Just looked at latest version:

version    1.7.6, 2011-02-27

Line 1041+

// Converts the cell content so that spaces occuring at beginning of each new line are replaced by &nbsp;
// Example: " Hello\n to the world" is converted to "&nbsp;&nbsp;Hello\n&nbsp;to the world"
$cellData = preg_replace("/(?m)(?:^|\\G) /", '&nbsp;', $cellData);

// convert newline "\n" to '<br>'
$cellData = nl2br($cellData);

So my point still stands, this will create invalid markup when saved to a html file.