博客
关于我
解决 PHPExcel 长数字串显示为科学计数
阅读量:165 次
发布时间:2019-02-28

本文共 1397 字,大约阅读时间需要 4 分钟。

转载自:http://www.netingcn.com/phpexcel-big-number-display.html

解决 PHPExcel 长数字串显示为科学计数

在excel中如果在一个默认的格中输入或复制超长数字字符串,它会显示为科学计算法,例如身份证号码,解决方法是把表格设置文本格式或在输入前加一个单引号。

使用PHPExcel来生成excel,也会遇到同样的问题,解决方法有三种:
1、设置单元格为文本

$objPHPExcel = new PHPExcel();$objPHPExcel->setActiveSheetIndex(0);$objPHPExcel->getActiveSheet()->setTitle('Simple');//设置A3单元格为文本$objPHPExcel->getActiveSheet()->getStyle('A3')->getNumberFormat()	->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);//也可以设置整行或整列的style/*//E 列为文本$objPHPExcel->getActiveSheet()->getStyle('E')->getNumberFormat()	->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);//第三行为文本$objPHPExcel->getActiveSheet()->getStyle('3')->getNumberFormat()	->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);*/

更多的格式可以在PHPExcel/Style/NumberFormat.php中找到。注意:上述的设置对长数字字符串还是以文本方式来显示科学计数法的结果,原因可能php在处理大数字时采用的科学计数法。

2、在设置值的时候显示的指定数据类型

$objPHPExcel = new PHPExcel();$objPHPExcel->setActiveSheetIndex(0);$objPHPExcel->getActiveSheet()->setTitle('Simple');$objPHPExcel->getActiveSheet()->setCellValueExplicit('D1',                                 123456789033,                                  PHPExcel_Cell_DataType::TYPE_STRING);

3、在数字字符串前加一个空格使之成为字符串

$objPHPExcel = new PHPExcel();$objPHPExcel->setActiveSheetIndex(0);$objPHPExcel->getActiveSheet()->setTitle('Simple');$objPHPExcel->getActiveSheet()->setCellValue('D1', ' ' . 123456789033);

推荐使用第二、三种,第一种没有根本解决问题。

你可能感兴趣的文章
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>