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

如何使用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.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀