我需要在excel表中查找表的列数...下面的代码是我的例程...可以任何人告诉我如何计算PHPExcel中的列值???这个例程计算精确...但它显示结果,如字母...就像它有5列,它显示E ..我怎么能显示数字而不是字母的计数值....提前感谢:)
$file_name = htmlentities($_POST['file_name']);
$sheet_name = htmlentities($_POST['sheet_name']);
$number_of_columns = htmlentities($_POST['number_of_columns']);
$number_of_rows = htmlentities($_POST['number_of_rows']);
$objReader = PHPExcel_IOFactory::createReaderForFile("data/" . $file_name);
$objReader->setLoadSheetsOnly(array($sheet_name));
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("data/" . $file_name);
$highestColumm = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
$highestRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
echo 'getHighestColumn() = [' . $highestColumm . ']<br/>';
echo 'getHighestRow() = [' . $highestRow . ']<br/>';
echo '<table border="1">';
foreach ($objPHPExcel->setActiveSheetIndex(0)->getRowIterator() as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
echo '<tr>';
foreach ($cellIterator as $cell) {
if (!is_null($cell)) {
$value = $cell->getCalculatedValue();
echo '<td>';
echo $value . ' ';
echo '</td>';
}
}
echo '</tr>';
}
echo '</table>';
答案 0 :(得分:2)
您可以使用PHPExcel内置函数将'E'
之类的列名转换为5
之类的列号:
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumm);