今天有用户反馈导出excel出现错误,于是看了下错误日志,发现如下报错: 未经允许严禁转载 Fatal error: Uncaught exception PHPExcel_Exception with message excel!J97 - Formula Error: An unexpected error occured in ?xxx\PHPExcel\Cell.php on line 3
今天有用户反馈导出excel出现错误,于是看了下错误日志,发现如下报错:
未经允许严禁转载
Fatal error: Uncaught exception ‘PHPExcel_Exception’ with message ‘excel!J97 -> Formula Error: An unexpected error occured’ in ?xxx\PHPExcel\Cell.php on line 307本文来自leo108's blog
可以看到是在处理J97这个单元格的时候出现了“算式错误”
PHPExcel出现Formula Error的解决方案
于是先从数据库中定位出错的单元格,发现是一个以“=”开头的字符串采集者烂JJ
在excel中一个单元格如果是以“=”开头,则说明这个单元格是根据其他单元格的值算出来的,“=”后面必须跟着一个合法的表达式
未经允许严禁转载
而那个字符串是用户的输入,很明显不应该是一个合法的表达式,所以应该在代码中过滤掉本文来自http://leo108.com
方法很简单,在“=”前面加一个半角的单引号就可以了,所以修改后的代码如下:PHP
if(strpos($value,'=') === 0){ $value = "'".$value; } $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($x,$y, $value);
PHPExcel

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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools
