博客
关于我
解决 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);

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

你可能感兴趣的文章
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 cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>