PHP code, which verifies if the folder exists and then reads the Excel data. The problem that I have is these are students and at the time of printing they print 1 to 1 for example: the name is printed, then the last name, etc. Nose how to put the code to enter it into the database. The students can be more than 1. I imagine that it could be to create an array and then separate them to enter it in the INSERT. but when creating the array where I print the getValue it would fill in itself and only the last student would be saved.
Do not know if there will be a way to separate the records by row name.
<?php
require '../vendor/autoload.php';
use PhpOffice\PhpSpreadSheet\SpreadSheet;
use PhpOffice\PhpSpreadSheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
$nombre = $_FILES['archivo']['name'];
$guardado = $_FILES['archivo']['tmp_name'];
if(!file_exists('archivos')) {
mkdir('archivos',0777,true);
if(file_exists('archivos')) {
if(move_uploaded_file($guardado, 'archivos/' .$nombre)) {
$ruta = 'archivos/' .$nombre;
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xls");
$spreadsheet = $reader->load($ruta);
$sheet = $spreadsheet->getActiveSheet();
foreach ($sheet->getRowIterator(9) as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
if (!is_null($cell)) {
$value = $cell->getValue();
echo $value;
}
}
}
echo "Archivo guardado con exito";
}else{
echo "Archivo no se pudo guardar";
}
}
}else{
if(move_uploaded_file($guardado, 'archivos/' .$nombre)) {
$ruta = 'archivos/' .$nombre;
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xls");
$spreadsheet = $reader->load($ruta);
$sheet = $spreadsheet->getActiveSheet();
foreach ($sheet->getRowIterator(10) as $row) {
$cellIterator = $row->getCellIterator("D","K");
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
if (!is_null($cell)) {
$value = $cell->getValue();
echo $value . '</br>';
}
}
}
}else{
echo "Archivo no se pudo guardar";
}
}
?>