From 62bf1b7a936cdc9bdb966f622f6c5f6f26db0d55 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 11 Dec 2012 17:54:23 +0000 Subject: [PATCH] Bugfix: (teso) Work item 18551 - Rich Text containing UTF-8 characters creating unreadable content with Excel5 Writer --- Classes/PHPExcel/Shared/String.php | 4 ++-- Classes/PHPExcel/Writer/Excel5/Worksheet.php | 4 ++-- changelog.txt | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Classes/PHPExcel/Shared/String.php b/Classes/PHPExcel/Shared/String.php index 0b5f955..3e495e8 100644 --- a/Classes/PHPExcel/Shared/String.php +++ b/Classes/PHPExcel/Shared/String.php @@ -443,10 +443,10 @@ class PHPExcel_Shared_String $data .= self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8'); } else { - $data = pack('vC', $ln, 0x08); + $data = pack('vC', $ln, 0x09); $data .= pack('v', count($arrcRuns)); // characters - $data .= $value; + $data .= self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8'); foreach ($arrcRuns as $cRun){ $data .= pack('v', $cRun['strlen']); $data .= pack('v', $cRun['fontidx']); diff --git a/Classes/PHPExcel/Writer/Excel5/Worksheet.php b/Classes/PHPExcel/Writer/Excel5/Worksheet.php index 730e739..3983f74 100644 --- a/Classes/PHPExcel/Writer/Excel5/Worksheet.php +++ b/Classes/PHPExcel/Writer/Excel5/Worksheet.php @@ -424,7 +424,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter if ($cVal instanceof PHPExcel_RichText) { // $this->_writeString($row, $column, $cVal->getPlainText(), $xfIndex); $arrcRun = array(); - $str_len = strlen($cVal->getPlainText()); + $str_len = PHPExcel_Shared_String::CountCharacters($cVal->getPlainText(), 'UTF-8'); $str_pos = 0; $elements = $cVal->getRichTextElements(); foreach ($elements as $element) { @@ -437,7 +437,7 @@ class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter } $arrcRun[] = array('strlen' => $str_pos, 'fontidx' => $str_fontidx); // Position FROM - $str_pos += strlen($element->getText()); + $str_pos += PHPExcel_Shared_String::CountCharacters($element->getText(), 'UTF-8'); } $this->_writeRichTextString($row, $column, $cVal->getPlainText(), $xfIndex, $arrcRun); } else { diff --git a/changelog.txt b/changelog.txt index 5ab739c..6899e33 100644 --- a/changelog.txt +++ b/changelog.txt @@ -43,6 +43,7 @@ Fixed in develop branch: - Bugfix: (MBaker) Work item 18844 - cache_in_memory_gzip "eats" last worksheet line, cache_in_memory doesn't - Bugfix: (Progi1984) Work item GH-22 - Sheet View in Excel5 Writer - Bugfix: (amironov) Work item GH-82 - PHPExcel_Worksheet::getCellCollection() may not return last cached cell +- Bugfix: (teso) Work item 18551 - Rich Text containing UTF-8 characters creating unreadable content with Excel5 Writer --------------------------------------------------------------------------------