drgovyk64676 2014-10-19 07:29
浏览 113
已采纳

如何使用PHPExcel在excel文件中放入大数字(超过15位数)?

I'm using PHPExcel and need to put a 50 digits number ($cellData) in a cell. I'm using PHPExcel and prefer to solve my problem with that, but I have no resistance to work with another library.

I first did this:

$objPHPExcel->getActiveSheet()
            ->SetCellValue('A1', $cellDate);

But it changes the number representation to scientific notation. So I Change it to this:

$objPHPExcel->getActiveSheet()
            ->getStyle('A1')
            ->getNumberFormat()
            ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

$objPHPExcel->getActiveSheet()
            ->SetCellValue('A1', $cellDate);

It had no effect. finally I did this:

$objPHPExcel->getActiveSheet()
            ->getCell('A1')
            ->setValueExplicit($cellDate, PHPExcel_Cell_DataType::TYPE_STRING);

It solves my problem, but adds a single quote before my number which is undesirable. How can I have my whole number, with no change in representation and no additional character?

  • 写回答

1条回答 默认 最新

  • dongzouqie4220 2014-10-19 08:48
    关注

    I found that final solution works. I mean this one:

    $objPHPExcel->getActiveSheet()
                ->getCell('A1')
                ->setValueExplicit($cellDate, PHPExcel_Cell_DataType::TYPE_STRING);
    

    But, I was watching my final excel file in LibreOffice Calc and it shows a single quote. When I load my final excel file in Microsoft Office, there were no additional character.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?