#### 1. 问题描述 --- 一个项目中用到了需要将用户信息导出到 Excel ,最初写完测试是正常的,如下图所示 ![](https://img.itqaq.com/art/content/4af23d126f48d1518948ce3b32195bf9.png) 在后来的某一天,导出手机号突然出现了报错,如下图所示 ![](https://img.itqaq.com/art/content/d26d095d7c5de3fdbfe411dddf06764d.png) 通过提示我们将问题定位在了 B 列 4867 行。 这是因为在 excel 中,单元格中的值如果是以 “=” 开头,则说明这个单元格是根据其他单元格的值算出来的,“=” 后面必须跟着一个合法的表达式。所以,解决方案就是这个单元格的值不让它以 “=” 开头 ``` # Formula Error: An unexpected error occurred 公式错误:发生意外错误 {"code":0,"msg":"用户手机号!B4867 -> Formula Error: An unexpected error occurred"} ``` #### 2. 解决方法 --- 找到将值写入到单元格的那行代码,修改前: ```php $sheet->setCellValueByColumnAndRow(2, $start, $value); ``` 修改后: ```php if ( $value && strpos($value, '=') === 0 ) { // 在 = 前面加个单引号 $value = "'" . $value; } $sheet->setCellValueByColumnAndRow(2, $start, $value); ``` 现在 Excel 表格就可以正常导出了 ![](https://img.itqaq.com/art/content/117f1a3960931012782f004d5fc50551.png)