php - Encoding correctly CSV files for PHPexcel -


i have json, decode it, write in csv file php, convert csv .xls aid of phpexcel

the goal export json excel file correctly. having trouble encoding , excel mac 2011 not support utf-8 csv files: link if preview (spacebar) on mac looks encoded. trouble excel.

first code csv:

$file_csv = fopen('files/file.csv', 'w'); 

then json:

$response_data = json_decode($connection->response['response'], true); foreach ($response_data $value)   {   //take data have 10 strings here in reality   $text_lang = $value['lang'];   $date = $value['date'];   //insert csv   $details = array($text_lang, $date );   fputcsv($file_csv, $details); }; fclose($file_csv); 

now if import csv excel have trouble utf-8. if convert text editor e.g. textmate utf-16le, , import excel smooth.

and phpexcel code create .xls from here:

$objreader = phpexcel_iofactory::createreader('csv'); $objphpexcel = $objreader->load('files/file.csv');   $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel5'); $objwriter->save('files/summary.xls'); 

the summary.xls broken on utf-8 , when opening requires repaired.


my first attempt convert above file.csv utf-16le in php see if ok excel. used iconv before fputcsv , excel showed chinese words...

now want encode csv file utf-16le , load phpexcel. used following lines , didn't work. because .csv had created incov partially (?) utf-8 , utf-16le.

$objreader->setinputencoding('utf-16le'); $objphpexcel = $objreader->load('file.csv'); 

the goal render data json .xls (or .xlxs) document without encoding problems on excel.

$objreader->setinputencoding('');  $objphpexcel = $objreader->load('file.csv'); 

this worked me.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -