PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 23, 2022

[FIXED] How can I read German characters (äöü߀) in Excel via PHPExcel?

 October 23, 2022     php, phpexcel, utf-8     No comments   

Issue

I'm 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 in the German characters from the Excel sheet correctly?


Solution

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

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

won't work, because the characters are already UTF-8 and you're assuming they're ISO-8859-1



Answered By - Mark Baker
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing