I'm not sure I undestand the second dimension of the three dimensional array that I created in $rowData
.
test.xlsx
contains 3 row and 2 columns of string values.
Also count($rowData)
returns 12, not 6.
<?php
// Include PHPExcel_IOFactory
include '../PHPExcel/Classes/PHPExcel/IOFactory.php';
$inputFileName = 'c:\DOCS\test.xlsx';
// 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());
}
// Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
echo $highestRow . "<br/>";
$highestColumn = $sheet->getHighestColumn();
echo $highestColumn. "<br/>";
// Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++){
// Read a row of data into an array
$rowData[$row-1] = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row);
echo $row . "<br/>";
// Insert row data array into your database of choice here
}
echo $rowData[0][0][0] . "<br/>";
echo $rowData[0][0][1] . "<br/>";
echo $rowData[1][0][0] . "<br/>";
echo $rowData[1][0][1] . "<br/>";
echo $rowData[2][0][0] . "<br/>";
echo $rowData[2][0][1] . "<br/>";
?>