setCellValue 是不支持设置数据格式的 下面是方法可有看处
setCellValue($pCoordinate = 'A1', $pValue = null, $returnCell = false)
setCellValueExplicit 是可以设置数据格式 同时支持连贯操作
/**
* Set a cell value
*
* @param string $pCoordinate Coordinate of the cell
* @param mixed $pValue Value of the cell
* @param string $pDataType Explicit data type
* @param bool $returnCell Return the worksheet (false, default) or the cell (true)
* @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified
*/
public function setCellValueExplicit($pCoordinate = 'A1', $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING, $returnCell = false)
{
// Set value
$cell = $this->getCell($pCoordinate)->setValueExplicit($pValue, $pDataType);
return ($returnCell) ? $cell : $this;
}
setCellValueExplicit 支持以下数据格式 目前只发现这些
TYPE_STRING
TYPE_STRING2
TYPE_NULL
TYPE_NUMERIC
TYPE_FORMULA
TYPE_BOOL
TYPE_ERROR
解决 PHPExcel 长数字串显示为科学计数
在excel中如果在一个默认的格中输入或复制超长数字字符串,它会显示为科学计算法,例如身份证号码,解决方法是把表格设置文本格式或在输入前加一个单引号。
对于下面这种修改数据类型未字符串 超长数字依然不能正常显示
->setCellValueExplicit('D1',123456789033,PHPExcel_Cell_DataType::TYPE_STRING);
百分之百可以解决超长数字的办法 就是在值前面加空格
->setCellValue('D1', ' ' . 123456789033);
本文介绍PHPExcel库中setCellValue和setCellValueExplicit方法的区别,详细说明如何通过setCellValueExplicit设置数据格式,并提供了解决PHPExcel中长数字串显示为科学计数法的方法。
546

被折叠的 条评论
为什么被折叠?



