drgovyk64676
drgovyk64676
2014-10-19 07:29

如何使用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 dongzouqie4220 7年前

    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.

    点赞 评论 复制链接分享