php中导出数据到excel时数字变为科学计数的解决方法
在数据导出到excel时数字格式不对,一般分为以下两种情况。
1、excel单元格设置长度不够
解决方法:
复制代码 代码如下:
//在excel.php文件中
$objActSheet = $objPHPExcel->getActiveSheet();
// 设置 栏目名称
$objActSheet->setCellValue("b1", "卡号");
// 设置列的宽度
$objActSheet->getColumnDimension('b')->setWidth(20);//改变此处设置的长度数值
2、字符被excel理解成数字了,一般就是把那个字段设置成文本 或者想办法加入一些空格一类的。
解决方法:
复制代码 代码如下:
//添加数据处,主要是把要显示数据以chunk_split()函数处理以下,此函数的具体用法可以自己查看
$objActSheet->setCellValue ( "b$i", chunk_split("123456789 ",4," ") );//当然,如果不想让用户看到数字间有空格,那就把要分割的字段值设大一些,如例子中的4设为大于等于9的即可。
我导出EXcel的主要代码的前面部分:
复制代码 代码如下:
if(count($data)>40000){
$filename_type='csv';
}else{
$filename_type='xls';
}
header("Content-Type: application/vnd.ms-excel");
Header("Accept-Ranges:bytes");
Header("Content-Disposition:attachment;filename=".$filename.".".$filename_type); //$filename导出的文件名
header("Pragma: no-cache");
header("Expires: 0");
if($filename_type=='xls'){
echo 'xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
';
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
