所以我正在尝试使用 php 从 excel 列表创建一个数组,我的 excel 在 A1:A3 - value1, value2, value3 之间有这些值
我的代码是这样的:
<?php
require_once dirname(__FILE__) . '/includes/libraries/classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load( dirname(__FILE__) . '/Tellimus.xls' );
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
$highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5
$newarray=array();
echo '<table>' . "\n";
for ($row = 1; $row <= $highestRow; ++$row) {
echo '<tr>' . "\n";
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
$column=$objWorksheet->getCellByColumnAndRow($col,$row)->getValue();
echo '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>' . "\n";
$newarray[] = $column;
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
print_r($newarray);
?>
它显示为:Array ( [0] => value1 [1] => [2] => value2 [3] => [4] => value3 [5] => )
我的目标是在每个条目之后获得一个没有空格的数组,如 1 号数组和 3 号数组等等。我怎样才能做到这一点?