Can't read google contacts csv properly

Topics: Developer Forum, User Forum
Feb 16, 2014 at 4:28 PM
Edited Feb 16, 2014 at 4:30 PM
I'm having an difficulty reading my csv file from google. These are my problem
  1. PHPExcel can't get the first value of A1. It is "Name". but It always return bool (false)
  2. PHPExcel getValue() return some character between real character : for example : string(23) "Family Name", It can't be 23 of length ?
  3. Everytime it read an UTF-8 String, it truncates content. For example : The correct string : "A Chương TMA", it returns : "A", that's all
    Any Ideas ?
Feb 16, 2014 at 7:17 PM
Without having any idea of what's in the file, I can't explain why you're getting what you're getting; take a look at what you're receiving from Google and see what it really contains
Feb 16, 2014 at 11:51 PM
I'm sorry because I didn't upload the file. This is my file. Please take a look at this. Thanks so much.
Feb 17, 2014 at 8:47 AM
It seems that there are error after calling public static function SanitizeUTF8($value). iconv return false.

Any ideas ?

Feb 17, 2014 at 9:22 AM
Looking at the file, it's encoded UCS-2 Little-endian, so you'd need to set the charset accordingly when reading it
Feb 17, 2014 at 9:27 AM
I Tried to set the encoding: Here is what I've got : iconv(): Detected an incomplete multibyte character in input string
    $reader = \PHPExcel_IOFactory::createReaderForFile($file) ;
    $worksheet = $reader->setInputEncoding('UCS-2LE')->load($file)->getActiveSheet()->toArray(null , false , false , true) ;
    echo "<pre>" ;
    var_dump($worksheet) ;
This is my code

Feb 17, 2014 at 9:30 AM
It also has a BOM marker in the first few bytes that would need to be skipped before reading, and your system needs to support UCS2-LE.
Feb 17, 2014 at 9:32 AM
So do I have to install anything ?
Feb 17, 2014 at 9:36 AM
Rather than setting input encoding to UCS-2LE, try setting it to UTF-16LE which should then be recognised by the CSV Reader.
Feb 17, 2014 at 9:39 AM
Not working either . iconv(): Detected an incomplete multibyte character in input string. Any Ideas ?
Feb 17, 2014 at 9:43 AM
Everything return false except the first string.
array(410) {
array(37) {
string(9) "Name"
Feb 17, 2014 at 10:26 AM
I knew how to fix this.

Thanks MarkBaker
Feb 17, 2014 at 12:01 PM
Care to share?
Feb 17, 2014 at 2:56 PM
Actually I have to convert the file to UTF8 like you said. I tried to convert it to UTF8 using the editor and it works great. Or in php, I can't find any function that convert the whole file so I convert the whole content and write it back in that file and it works. Hope that help anybody has the same problem like me.