overweight symbols

Oct 24, 2008 at 11:19 AM
Edited Oct 24, 2008 at 11:22 AM
I have to print all data from excel table. Code:$0$objReader = PHPExcel_IOFactory::createReader('Excel5');$0$0$objPHPExcel = $objReader->load("features.xls");$0$0$columns = $objPHPExcel->getActiveSheet()->getColumnDimensions();$0$0foreach($objPHPExcel->getActiveSheet()->getRowDimensions() as $rows)$0$0$0$0foreach($columns as $col)$0$0{$0$0$value = $objPHPExcel->getActiveSheet()->getCell($col->getColumnIndex().$rows->getRowIndex())->getValue();$0$0if (gettype($value)=="object")$0$0$0$0$value = $value->getPlainText();$0$0}$0$0echo $value;$0$0}$0$0echo "</br>";$0$0}$0$0And result of getPlainText() have some overweight symbols. For example, if in excel file I have such text "111  ( 222  ) " with blue text color in the bracket result of the getPlainText() function will be "111В (В 222В В )В ". Why this?$0$0$0$0$0$0
Developer
Oct 24, 2008 at 2:12 PM
Can you upload the file somewhere, or send me the file?
Oct 24, 2008 at 4:14 PM
Edited Oct 24, 2008 at 4:39 PM
http://content.files.mail.ru/Y6CHVO/d927a50948ad325b9c4f27104fa2e64c$0There are input file, script and phpexcel classes :)$0$0$0$0
Developer
Oct 25, 2008 at 12:42 AM
String values returned by PHPExcel are always UTF-8 encoded. For example, when you do like this you get UTF-8 encoded string:

$value = $objPHPExcel->getActiveSheet()->getCell($col->getColumnIndex().$rows->getRowIndex())->getValue();
if (gettype($value)=="object") {        
    $value = $value->getPlainText();
}
// $value is UTF-8 encoded string

If you need to output the text on a web page, you should specify UTF-8 encoding for your web page.
Try this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Note that the above may not work if your server is sending HTTP headers specifying a different character set. In that case you may try this instead:

header('Content-Type: content=text/html;charset=utf-8');

Tip: Use LiveHTTPHeaders extension for Firefox 2 to check HTTP headers sent from the server.

The "В"s you are seing are "CYRILLIC CAPITAL VE" and stem from "NO-BREAK SPACE" characters between your digits so I guess you are using Windows-1251 encoding. If you change to UTF-8 it will be ok. If, for some reason, it is not possible for you to change the encoding, then you will have to convert the strings:

$value = iconv('UTF-8', 'CP1251', $value); // convert to CP1251
or
$value = mb_convert_encoding($value, 'CP1251', 'UTF-8'); // convert to CP1251

Additional note:
If you always want only the plain text of the Rich-Text strings, then you may use this (which removes all formatting):

$objReader->setReadDataOnly(true);

You can then skip the step where you use getPlainText()

Oct 25, 2008 at 8:21 AM
Thank you very much