我在这里需要一些帮助,因为我不明白。我正在使用 PHPExcel 读取 XLS 文件,如下所示:
include 'Classes/PHPExcel/IOFactory.php';
$inputFileName = 'precios.xls';
// Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch (Exception $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}
$rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
$array_data = array();
foreach ($rowIterator as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
$rowIndex = $row->getRowIndex();
$array_data[$rowIndex] = array('A' => '', 'B' => '', 'C' => '', 'D' => '', 'E' => '', 'F' => '', 'G' => '');
foreach ($cellIterator as $cell) {
if ('A' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('B' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('C' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('D' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('E' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('F' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('G' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
}
}
}
echo '<pre>';
print_r($array_data);
这会返回类似:
Array
(
[1] => Array
(
[A] => ALGARROBO
[B] => 10800
[C] => 10800
[D] => 16450
[E] => 19150
[F] => 23100
[G] => 23100
)
[2] => Array
(
[A] => ALTO HOSPICIO
[B] => 27950
[C] => 27950
[D] => 39950
[E] => 43900
[F] => 55550
[G] => 55550
)
[3] => Array
(
[A] => ANCUD
[B] => 7000
[C] => 7000
[D] => 10700
[E] => 13250
[F] => 15800
[G] => 15800
)
[4] => Array
(
[A] => ANDACOLLO
[B] => 12950
[C] => 12950
[D] => 18850
[E] => 21650
[F] => 26500
[G] => 26500
)
);
我需要从这里做的并且不明白的是将结果转换为:
1:10.800,6:10.800,12:16.450,18:19.150,24:23.100,30:23.100 // this is an example for first array
1:B,6:C,12:D,18:E,24:F,30:G // the same thing using arrays keys
还要注意数字“。” 对于价值观,任何人都可以给我一些想法或一些示例代码来完成这项工作吗?