Reading CSV file - cells with large text strings getting truncated

Topics: User Forum
Oct 29, 2013 at 9:25 PM
I am using PHPExcel v1.7.9 with PHP v5.3.1.

I am trying to read data from a CSV file that has cells which contain large text strings. I am able to read all of the data expected from the file successfully, but all of the large text strings are all being truncated at 32,767 bytes.

It looks like the CSV reader is using the PHP fgetcsv call to read each row of data, and is also using a zero for the length parameter which should not limit the maximum line length.

Does anybody have any insight as to why text data read from a CSV file would be getting truncated at a fixed size? Is this due to some underlying PHP setting or is there a default cell size in PHPExcel that I need to override to read in large strings?

Here is a summary of the PHP logic I'm using to read in the CSV file:
$inputFileType = 'CSV';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setDelimiter("\t"); 
$objReader->setEnclosure('');
$objPHPExcel = $objReader->load($fullPath);
$objWorksheet = $objPHPExcel->getActiveSheet();
foreach ($objWorksheet->getRowIterator() as $row) {
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false);
    foreach ($cellIterator as $cell) {
        $cell_value = $cell->getValue();
    }
}
When $cell_value is set to one of the large text strings it is always truncated at 32,767 bytes.

Any ideas?
Oct 31, 2013 at 3:56 PM
From what I've read PHP doesn't enforce a limit on the length of any string data. The max size is based off of the amount of memory available to PHP, which is well over the 32K limit I'm seeing.

I've been reviewing the PHPExcel code to try and identify any potential sources of the 32k limit but have been unable to identify anything so far.

The fgetcsv function that PHPExcel uses to read the next line of data from the CSV file includes a parameter that can be used to limit line length, but in the PHPExcel CSV logic this is being set to 0 which designates unlimited size. Plus, I know the line length isn't being limited because I am reading in multiple cells with text on the same row (and they are all being truncated to 32K).

PHPExcel also potentially calls some string handling and character encoding functions like str_replace, iconv, and mb_convert_encoding, but all of these PHP functions should preserve the string length and don't include options for limiting length.

Has anybody encountered issues with text (or other) data being truncated in size when read in from a CSV file?