-
Notifications
You must be signed in to change notification settings - Fork 4.2k
OOCalc parsing links inside cells error. #139
Comments
Something like: $fetchTextFromChildren = function( SimpleXmlElement $el ) use( &$fetchTextFromChildren )
{
$result = '';
if ( $el->count() )
{
foreach ( $el as $subElement ) {
$result .= $fetchTextFromChildren( $subElement );
}
}
else {
$result = (string) $el;
}
return $result;
};
$allCellDataText = $fetchTextFromChildren( $cellDataText ); |
Hm. seems that isset($dataValue->a) is always false cause $allCellDataText "should" always be a string after implode. I check if we can replace the loop and check by a xpath query. line: 538 /PHPExcel/Classes/PHPExcel/Reader/OOCalc.php $allCellDataText = implode($dataArray, "\n");
// echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
switch ($cellDataOfficeAttributes['value-type']) {
case 'string' :
$type = PHPExcel_Cell_DataType::TYPE_STRING;
$dataValue = $allCellDataText;
if (isset($dataValue->a)) {
$dataValue = $dataValue->a;
$cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
$hyperlink = $cellXLinkAttributes['href'];
}
break; |
I'm having pretty much the same issue with email links. libreOffice automatically created links for email addresses: <office:body>
<office:spreadsheet>
<table:table table:name="Sheet1" table:style-name="ta1">
<table:table-column table:style-name="co1" table:default-cell-style-name="Default" />
<table:table-row table:style-name="ro1">
<table:table-cell office:value-type="string">
<text:p>
<text:a xlink:href="mailto:some@email.com" xlink:type="simple">some@email.com</text:a>
</text:p>
</table:table-cell>
</table:table-row>
</table:table>
<table:named-expressions />
</office:spreadsheet>
</office:body> You can see that libreOffice puts the text:a within a text:p. My test case was basically this: <?php
/** Include PHPExcel */
require_once '../Classes/PHPExcel.php';
if (!file_exists("email.ods")) {
exit(1);
}
$objPHPExcel = PHPExcel_IOFactory::load("email.ods");
foreach ($objPHPExcel->getAllSheets() as $s) {
foreach ($s->getRowIterator() as $r) {
foreach ($r->getCellIterator() as $c) {
echo "| {$c->getValue()},{$c->getCalculatedValue()},{$c->getFormattedValue()} |";
}
echo "\n";
}
} And it outputs the following:
Tested with PHPExcel 1.7.9 & PHP 5.4.4-15.1 |
Hello. I have this same issue. The link says to place this in Classes\PHPExcel\Reader\OOCalc.php, after line 487. if (isset($cellDataText->p) && isset($cellDataText->p->a)) {
$cellDataText->p = $cellDataText->p->a;
} Since I'm handling dependencies with composer, I can't edit anything inside the vendor directory. |
I have cell in *.ods file, which actually contains this structure:
->p->span->a
, wherea
contains link or email. My file origin from LibreOffice Calc.Accordings to ec9256a there was attempt to fix same bug, but there is hardcoded
->p->span(s)
structure. How about to create more complex indiferrent to structure recursive algoritm?The text was updated successfully, but these errors were encountered: