Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $reader = PHPExcel_IOFactory::createReader('Excel2007');
- $reader->setReadDataOnly(true);
- $file = isset($_FILES["uploadexcel"]['tmp_name']) ? $_FILES["uploadexcel"]['tmp_name'] : '';
- $objPHPExcel = $reader->load($file);
- $objWorksheet = $objPHPExcel->getActiveSheet();
- $header=true;
- if ($header) {
- $highestRow = $objWorksheet->getHighestRow();
- $highestColumn = $objWorksheet->getHighestColumn();
- $headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null,true,true,true);
- $headingsArray = $headingsArray[1];
- $r = -1;
- $namedDataArray = array();
- /**/$required=['category_1','language','f_n','publishers','cost','cost_currency'];
- for ($row = 2; $row <= $highestRow; ++$row) {
- $dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null,true,true,true);
- if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
- ++$r;
- /**/ $row_check[$r]=[];
- foreach ($headingsArray as $columnKey => $columnHeading) {
- /**/ if(in_array($columnHeading,$required) && is_null($dataRow[$row][$columnKey])){
- /**/ $row_check[$r][]=$columnHeading;
- /**/ }
- $namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
- }
- }
- }
- } else {
- //excel sheet with no header
- $namedDataArray = $objWorksheet->toArray(null, true, true, true);
- }
- echo '<pre>';
- /**/var_export($row_check);
- // a row that passes will have an empty subarray (e.g. keys 1,8,10,16)
- // otherwise, the subarray will list all failing cells by columnname
- print_r($namedDataArray);
- exit;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment