maatwebsite lost precision when export long integer data
Maatwebsite would lost precision when export long integer data, no matter string or int storaged in database. Implementing \Maatwebsite\Excel\Concerns\WithCustomValueBinder can solve this issue in your export class. You should change dataTypeForValue method like following.
/** Bind value to a cell.
*
* @param Cell $cell Cell to bind value to
* @param mixed $value Value to bind in cell
*
* @return bool
*/
public function bindValue(Cell $cell, $value)
{
// sanitize UTF-8 strings
if (is_string($value)) {
$value = StringHelper::sanitizeUTF8($value);
} elseif (is_object($value)) {
// Handle any objects that might be injected
if ($value instanceof DateTimeInterface) {
$value = $value->format('Y-m-d H:i:s');
} elseif (!($value instanceof RichText)) {
$value = (string) $value;
}
} // Set value explicit
$cell->setValueExplicit($value, static::dataTypeForValue($value)); // Done!
return true;
} /**
* DataType for value.
*
* @param mixed $pValue
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public static function dataTypeForValue($pValue)
{
// Match the value against a few data types
if ($pValue === null) {
return DataType::TYPE_NULL;
} elseif ($pValue === '') {
return DataType::TYPE_STRING;
} elseif ($pValue instanceof RichText) {
return DataType::TYPE_INLINE;
} elseif ($pValue[0] === '=' && strlen($pValue) > 1) {
return DataType::TYPE_FORMULA;
} elseif (is_bool($pValue)) {
return DataType::TYPE_BOOL;
} elseif (is_float($pValue) || is_int($pValue)) {
return DataType::TYPE_NUMERIC;
} elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) {
$tValue = ltrim($pValue, '+-');
if (is_string($pValue) && $tValue[0] === '0' && strlen($tValue) > 1 && $tValue[1] !== '.') {
return DataType::TYPE_STRING;
} elseif ((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) {
return DataType::TYPE_STRING;
} return DataType::TYPE_STRING;
} elseif (is_string($pValue)) {
$errorCodes = DataType::getErrorCodes();
if (isset($errorCodes[$pValue])) {
return DataType::TYPE_ERROR;
}
} return DataType::TYPE_STRING;
}
The only one different is in line 60, author return DataType::TYPE_NUMERIC
maatwebsite lost precision when export long integer data的更多相关文章
- C#,NPOI,Export Generic T Data
1.Nuget 下载NPOI; Install-package NPOI -version 2.4.1 2.下载EF install-package entityframework -version ...
- NetSuite SuiteScript 2.0 export data to Excel file(xls)
In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward: Collec ...
- Export SQLite data to Excel in iOS programmatically(OC)
//For the app I have that did this, the SQLite data was fairly large. Therefore, I used a background ...
- Delphi Data Types
http://docwiki.embarcadero.com/RADStudio/XE6/en/Delphi_Data_Types Integer Data Types Type Descriptio ...
- PE Header and Export Table for Delphi
Malware Analysis Tutorial 8: PE Header and Export Table 2. Background Information of PE HeaderAny bi ...
- Data Mover Script Templates
Datamover is probably the best way to export and import data between PeopleSoft databases and the sc ...
- module.exports与exports,export和export default
还在为module.exports.exports.export和export default,import和require区别与联系发愁吗,这一篇基本就够了! 一.首先搞清楚一个基本问题: modu ...
- module.exports,exports,export和export default,import与require区别与联系【原创】
还在为module.exports.exports.export和export default,import和require区别与联系发愁吗,这一篇基本就够了! 一.首先搞清楚一个基本问题: modu ...
- 工具函数判断data为整型字符串
/** * 如果data是整型字符串,则转为整型,否则原样返回 * @param {*} data 整型字符串 */ export const stringToInt = (data) => { ...
随机推荐
- python map函数、filter函数、reduce函数
1.map函数:map(func,可迭代对象): ①func可以是自定义的函数,也可以是功能简单的匿名函数(通过lambda定义) ②处理逻辑:表示将传入的可迭代对象依次循环,将每个元素按照传入的fu ...
- ES数据库搜索
1.倒排索引 1.倒排索引和正向索引 在全文搜索里,文档数据离不开搜索,而搜索离不开索引(没有索引搜索会很低效),倒排索引(Inverted index)是全文搜索系统里最高效的索引方法和数据结构,E ...
- 06_Python基础课程
学于黑马和传智播客联合做的教学项目 感谢 黑马官网 传智播客官网 微信搜索"艺术行者",关注并回复关键词"软件测试"获取视频和教程资料! b站在线视频 Pyth ...
- 五天一体_企业权限管理(SSM整合)
学于黑马程序员和传智播客联合做的教学项目 感谢 黑马程序员官网 传智播客官网 个人根据教程的每天的工作进度的代码和资料 密码:cti5 b站在线视频 微信搜索"艺术行者",关注并回 ...
- Python Tuple(元组) len()方法
描述 Python 元组 len() 函数计算元组元素个数.高佣联盟 www.cgewang.com 语法 len()方法语法: len(tuple) 参数 tuple -- 要计算的元组. 返回值 ...
- PHP fgetc() 函数
定义和用法 fgetc() 函数从打开的文件中返回一个单一的字符. 语法 fgetc(file) 参数 描述 file 必需.规定要检查的文件. 提示和注释 注释:该函数处理大文件非常缓慢,所以它不用 ...
- bzoj 3436小K的农场
3436: 小K的农场 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 2327 Solved: 1105 [Submit][Status][Discu ...
- SpringBoot学习之整合Mybatis
本博客使用IDEA开发工具,通过Maven构建SpringBoot项目,初始化项目添加的依赖有:spring-boot-starter-jdbc.spring-boot-starter-web.mys ...
- 数据结构C语言实现----快速排序
快速排序算法 首先看下面这个例子: 我们取第一个元素为基准元素: 之后,从右边开始与基准元素挨个比较,如果比基准元素大,右指针往左移,如果比基准元素小,就与左指针指的元素交换(因为左指针永远停留在一 ...
- 重学c#系列——异常续[异常注意事项](七)
前言 对上节异常的补充,也可以说是异常使用的注意事项. 正文 减少try catch的使用 前面提及到,如果一个方法没有实现该方法的效果,那么就应该抛出异常. 如果有约定那么可以按照约定,如果约定有歧 ...