d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Quick Php Help > New To Web
Add Reply New Topic New Poll
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Feb 9 2017 02:48am
so i've got this php file that first creates a csv from an xls then converts it into a 2d array and it prints out good but i dont know how to loop through it
heres is the code
what i want to do is check to see if the key field is in the database and if it isn't then insert it if i can figure out how to loop through the array i can probably figure out the rest

Code
<?php
require_once 'Classes/PHPExcel/IOFactory.php';


$inputFileType = 'Excel5';
$inputFileName = 'Position Accepted Staff by Regi 01302017 - Copy.xls';

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcelReader = $objReader->load($inputFileName);

$loadedSheetNames = $objPHPExcelReader->getSheetNames();

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');

foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
$objWriter->setSheetIndex($sheetIndex);
$objWriter->save($loadedSheetName.'.csv');
}

$file = file_get_contents("Position Accepted Staff by Regi.csv");
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $file));
print_r($data);
?>
Member
Posts: 3,197
Joined: May 4 2013
Gold: 1,457.00
Feb 9 2017 04:47am
foreach
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll