作者:乔山办公网日期:
返回目录:excel表格制作
生成excel都会使用e68a84e8a2ade799bee5baa6334phpExcel类,介绍在生成excel列名超过26列大于Z时的解决办法,这是phpExcel类中的方法,代码如下:
复制代码 代码如下:
public static function stringFromColumnIndex($pColumnIndex = 0)
{
// Using a lookup cache adds a slight memory overhead, but boosts speed
// caching using a static within the method is faster than a class
static,
// though it's additional memory overhead
static $_indexCache = array();
if (!isset($_indexCache[$pColumnIndex])) {
// Determine column string
if ($pColumnIndex < 26) {
$_indexCache[$pColumnIndex] = chr(65 + $pColumnIndex);
} elseif ($pColumnIndex < 702) {
$_indexCache[$pColumnIndex] = chr(64 + ($pColumnIndex / 26)) . chr(65 +
$pColumnIndex % 26);
} else {
$_indexCache[$pColumnIndex] = chr(64 + (($pColumnIndex - 26) / 676)) .
chr(65 + ((($pColumnIndex - 26) % 676) / 26)) . chr(65 + $pColumnIndex %
26);
}
}
return $_indexCache[$pColumnIndex];
}
将列的数字序号转成字母使用,代码如下:
复制代码 代码如下:
PHPExcel_Cell::stringFromColumnIndex($i); // 从o开始
将列的字母转成数字序号使用,代码如下:
复制代码 代码如下:
PHPExcel_Cell::columnIndexFromString('AA');
三个方案:zd
1、数字版字符串前加一个单引号
2、数字字符串前加空字符
3、强制指定这字符串型权数据$objActSheet->setCellValueExplicit('A5', '847475847857487584',PHPExcel_Cell_DataType::TYPE_STRING);
非要一次执行完成?!
把1w条数据分成5次,每次导出2k条,然后刷新页面,接着将导出的数据追加到excel表格中。
之前碰到过身份证号码被缩略的,解决方法就是在后面加个单引号,这样它就不会按数字来做科学缩略