简体   繁体   中英

Column data is duplicated in PHPExcel

I have a weird bug with PHPExcel .

I'm uploading a file with a column with a custom format of 000-0000000 which generated numbers as XXX-XXXXXXX (X being numbers), but when I read the file I get the column value as XXXXXXXXX-XXXXXXXXX where the numbers between the - are the same, meaning the column value is being duplicated.

This is the way I'm reading the file:

    $objReader      = PHPExcel_IOFactory::createReaderForFile($file);
    $objPHPExcel    = $objReader->load($file);
    $objReader->setReadDataOnly(true);
    $sheetData      = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
    $result         = array();
    $errors         = array();
    $i              = 1;

    foreach($sheetData as $row){

        if($has_header == "1" && $i == 1){
            $i++;
            continue;
        }

       die(print_r($row));
    }

This happens for the entire file, anyone happen to know why?

I've verified that the data in the file is actually as I expect by saving it as csv file as viewing with notepad. The actual file is xls format

While the PHPExcel format handler makes every effort to handle most regular Excel format masks, it isn't perfect outside the basics of decimals, thousands separator, percentages, dates, accounting, scientific, fractions, etc. Your custom mask of 000-0000000 falls outside of these basic formats, and while the PHPExcel format handler should be capable of handling something like this, it's entirely possible that you have found a bug in the code.

The code that should handle this format mask is in the _complexNumberFormatMask() method of the PHPExcel_Style_NumberFormat class, which should be called whenever formatting a number to a complex format such as yours.

However, this code for handling complex number formats was added in PHPExcel version 1.7.9: previous versions would return a string where "the numbers between the - are the same", so please check that you aren't using an earlier version of PHPExcel, because the tests I've just run a few minutes ago suggest that this is working correctly for your mask in version 1.7.9.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM