我使用PHPExcel类读取xls文件,然后尝试插入db。但是当我显示行和列的最高索引值时,它会显示列字段的错误结果。我有数据索引'R',但代码显示$ highestColumn = J和$ highestColumnIndex = 10。但最高行索引是正确的。我的代码如下:
<?php
$filename="test.xls";
require_once '../Classes/PHPExcel/IOFactory.php';
if (!file_exists($filename))
{
echo "Not Exist!";
}
$objPHPExcel = PHPExcel_IOFactory::load($filename);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestDataColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
echo $highestColumn;
echo "<br/>";
echo $highestColumnIndex;
?>
我的xls文件列索引格式如下:
有什么想法吗?