解决php中导出到excel时数目字变为科学计数

WBOY
Release: 2016-06-13 13:02:03
Original
1007 people have browsed it

解决php中导出到excel时数字变为科学计数

遇到数据导出到excel时数字格式不对,一般分为以下两种情况


1、excel单元格设置长度不够,解决方法如下:

//在excel.php文件中
$objActSheet = $objPHPExcel->getActiveSheet();
// 设置 栏目名称
$objActSheet->setCellValue("b1", "卡号");
// 设置列的宽度
$objActSheet->getColumnDimension('b')->setWidth(20);//改变此处设置的长度数值
Copy after login


2、字符被excel理解成数字了,一般就是把那个字段设置成文本 或者想办法加入一些空格一类的,我的解决方案如下:

//添加数据处,主要是把要显示数据以chunk_split()函数处理以下,此函数的具体用法可以自己查看
$objActSheet->setCellValue ( "b$i", chunk_split("123456789 ",4," ") );//当然,如果不想让用户看到数字间有空格,那就把要分割的字段值设大一些,如例子中的4设为大于等于9的即可

Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!