How can I read German characters (äöüß €) in Excel using PHPExcel?

I am reading this excel file:

alt text

with PHPExcel , but it looks like this:

alt text

I am using this code:

$objReader = PHPExcel_IOFactory::createReaderForFile("data/".$file_name);
$objReader->setLoadSheetsOnly(array(0));
$objPHPExcel = $objReader->load("data/".$file_name);

echo '<table border="1">';
for ($row = 1; $row < $number_of_rows; $row++) {
    echo '<tr>';
    for ($column = 0; $column < $number_of_columns; $column++) {
        $value = $objPHPExcel->setActiveSheetIndex(0)->getCellByColumnAndRow($column, $row)->getValue();
        echo '<td>';
        $newValue = iconv("ISO-8859-1", "UTF-8", $value); //has no effect
        // echo $newValue . '&nbsp;';
        echo $value . '&nbsp;';
        echo '</td>';
    }
    echo '</tr>';
}
echo '</table>';
die; 

How can I read German characters from an Excel sheet correctly?

+3
source share
1 answer

PHPExcel uses UTF-8 internally, so it will display all characters correctly if your html page is set to UTF-8

$newValue = iconv("ISO-8859-1", "UTF-8", $value); //has no effect 

will not work because the characters are already UTF-8 and you think that they are ISO-8859-1

+1
source

Source: https://habr.com/ru/post/1782437/


All Articles