Home Backend Development PHP Tutorial 解决php中导出到excel时数目字变为科学计数

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

Jun 13, 2016 pm 01:02 PM
excel gt

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

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


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

1

2

3

4

5

6

//在excel.php文件中

$objActSheet = $objPHPExcel->getActiveSheet();

// 设置 栏目名称

$objActSheet->setCellValue("b1", "卡号");

// 设置列的宽度

$objActSheet->getColumnDimension('b')->setWidth(20);//改变此处设置的长度数值

Copy after login


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

1

2

//添加数据处,主要是把要显示数据以chunk_split()函数处理以下,此函数的具体用法可以自己查看

$objActSheet->setCellValue ( "b$i", chunk_split("123456789 ",4," ") );//当然,如果不想让用户看到数字间有空格,那就把要分割的字段值设大一些,如例子中的4设为大于等于9的即可

Copy after login

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to filter more than 3 keywords at the same time in excel How to filter more than 3 keywords at the same time in excel Mar 21, 2024 pm 03:16 PM

How to filter more than 3 keywords at the same time in excel

What should I do if the frame line disappears when printing in Excel? What should I do if the frame line disappears when printing in Excel? Mar 21, 2024 am 09:50 AM

What should I do if the frame line disappears when printing in Excel?

How to type subscript in excel How to type subscript in excel Mar 20, 2024 am 11:31 AM

How to type subscript in excel

How to change excel table compatibility mode to normal mode How to change excel table compatibility mode to normal mode Mar 20, 2024 pm 08:01 PM

How to change excel table compatibility mode to normal mode

How to set superscript in excel How to set superscript in excel Mar 20, 2024 pm 04:30 PM

How to set superscript in excel

Where to set excel reading mode Where to set excel reading mode Mar 21, 2024 am 08:40 AM

Where to set excel reading mode

How to use the iif function in excel How to use the iif function in excel Mar 20, 2024 pm 06:10 PM

How to use the iif function in excel

How to read excel data in html How to read excel data in html Mar 27, 2024 pm 05:11 PM

How to read excel data in html

See all articles