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

Wednesday, October 5, 2022

[FIXED] How to handle Norwegian / Swedish characters in PHPExcel (Getting ? mark in place of special character)

 October 05, 2022     cakephp, php, phpexcel, phpexcelreader     No comments   

Issue

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' );

Solution

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

$objPHPExcel->getActiveSheet ()->SetCellValue ( 'A2', utf8_encode($arOrders[0]['content'] ));


Answered By - Shikha Vyaghra
Answer Checked By - Mary Flores (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