0

I have a issue when trying to export data from database to excel using PHPExcel. The issue is when there is some norwegian characters in the string. Firstly when I tried entering the data directly, all the the letetrs after the norwegian characters were getting removed. Then I used utf8_decode('dokument pärm'), which is giving the output as "dokument p?rm".

My question is how to include the norwegian and swedish characters and remove '?' marks. Thanks in advance!!!

Code:

require_once '../libs/PHPExcel.php';
/* Set of other includes */

$objPHPExcel = new PHPExcel ();
$objPHPExcel->setActiveSheetIndex ( 0 );

// collecting data from database and saved to $arOrders[0]['content'], say "dokument pärm";

$objPHPExcel->getActiveSheet ()->SetCellValue ( 'A2', utf8_decode($arOrders[0]['content'] ));
$objWriter = new PHPExcel_Writer_Excel2007 ( $objPHPExcel );
header ( 'content-type: application/vnd.ms-excel;' );
header ( 'Content-Disposition: attachment; filename="Report.xlsx"' );
$objWriter->save ( 'php://output' );
Anand Garg
  • 124
  • 1
  • 8
  • please add your code – Abdallah Alsamman Sep 12 '15 at 08:17
  • Use UTF-8 for every string value that you set in PHPExcel. If necessary use [iconv()](http://www.php.net/manual/en/function.iconv.php) to convert strings to UTF-8..... don't use [utf8_decode()](http://www.php.net/manual/en/function.utf8-decode.php) to convert to UTF-8, because that's not what the function does – Mark Baker Sep 12 '15 at 08:37

1 Answers1

0

I guess you need utf8_encode(), instead of utf8_decode:

$objPHPExcel->getActiveSheet ()->SetCellValue ( 'A2', utf8_encode($arOrders[0]['content'] ));
Sjon
  • 4,989
  • 6
  • 28
  • 46