Skip to content
This repository was archived by the owner on Jan 2, 2019. It is now read-only.
This repository was archived by the owner on Jan 2, 2019. It is now read-only.

PHP Excel 1.8.2 Loss of precision when writing numeric strings #1427

@myloveGy

Description

@myloveGy
Q A
Package version 1.8.2
PHP version 7.1.16

Actual Behaviour

When I used PHP Excel to write a large numeric string, I found that the behaviors of 1.8.1 and 1.8.2 were inconsistent. My code is as follows:

$objPHPExcel = new \PHPExcel();
        // Set document properties
        $objPHPExcel->getProperties()
            ->setCreator("REPORTINFO")
            ->setLastModifiedBy("VeryStar")
            ->setTitle("VeryStar REPORTINFO")
            ->setSubject("VeryStar REPORTINFO")
            ->setDescription("VeryStar REPORTINFO")
            ->setKeywords("VeryStar")
            ->setCategory("VeryStar");
        $sheet_num = 1;

        $phpExcelActiveSheet = $objPHPExcel->getActiveSheet();
        $objPHPExcel->setActiveSheetIndex(0)->setTitle('demo');
        $objPHPExcel->getActiveSheet()->getStyle('E')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
        $objPHPExcel->getActiveSheet()->getStyle('G')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
        $phpExcelActiveSheet->setCellValue('A' . $sheet_num, 'PHP Version');
        $phpExcelActiveSheet->setCellValue('B' . $sheet_num, 'System');
        $phpExcelActiveSheet->setCellValue('C' . $sheet_num, 'Excel Version');
        $phpExcelActiveSheet->setCellValue('D' . $sheet_num, 'test value 1');
        $phpExcelActiveSheet->setCellValue('E' . $sheet_num, 'test value 2');
        $phpExcelActiveSheet->setCellValue('F' . $sheet_num, 'test value 3');
        $phpExcelActiveSheet->setCellValue('G' . $sheet_num, 'test value 4');

        $sheet_num++;
        $phpExcelActiveSheet->setCellValue('A' . $sheet_num, PHP_VERSION);
        $phpExcelActiveSheet->setCellValue('B' . $sheet_num, PHP_OS);
        $phpExcelActiveSheet->setCellValue('C' . $sheet_num, '1.8.2');
        $phpExcelActiveSheet->setCellValue('D' . $sheet_num, '898350553311499'."\t");
        $phpExcelActiveSheet->setCellValue('E' . $sheet_num, '898350553311499');
        $phpExcelActiveSheet->setCellValue('F' . $sheet_num, '898350553311491'."\t");
        $phpExcelActiveSheet->setCellValue('G' . $sheet_num, '898350553311491');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $file_name = '/data/demo-1.8.2.xlsx';
        $objWriter->save($file_name);

1.8.2 Write is the following data:
demo-1.8.2.xlsx
1 8 2

The number is found to be rounded up according to the mantissa
But 1.8.1 does not have this problem:
demo-1.8.1.xlsx
1 8 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions