This image is the file I wish to importI tried to import my excel file in MySQL, and I was able to do it but I want to remove certain rows and start importing from E4 instead of A1 cell. I only need some columns like the ones highlighted in yellow. This is my code, I only got this through a tutorial and want to make some difference.
if(isset($_POST['import_mandate']))
{
$filename = $_FILES['import-file']['name'];
$file_ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed_ext = ['Xls','xlsx','csv'];
if(in_array($file_ext, $allowed_ext))
{
$inputFileName = $_FILES['import-file']['tmp_name'];
/** Load $inputFileName to a Spreadsheet object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
$data = $spreadsheet->getActiveSheet()->toArray();
foreach($data as $row)
{
$nycid = $row['4'];
$lastname = $row['5'];
$firstname = $row['6'];
$grade = $row['10'];
$adbn = $row['12'];
$pldbn = $row['13'];
$stype = $row['18'];
$mb = $row['19'];
$language = $row['20'];
$ig = $row['21'];
$gsize = $row['22'];
$freq = $row['23'];
$dur = $row['24'];
$provider = $row['28'];
$mandatequery = "INSERT INTO mandates (nycid, lastname, firstname, grade, adbn, pldbn, stype, mb, language, ig, gsize, freq, dur, provider) VALUES ('$nycid', '$lastname', '$firstname', '$grade', '$adbn', '$pldbn', '$stype', '$mb', '$language', '$ig', '$gsize', '$freq', '$dur', '$provider')";
$query_run = mysqli_query($con,$mandatequery);
$msg = true;
}
if(isset($msg))
{
$_SESSION['message'] = "Successfully Imported!";
header("Location: mandates.php");
exit(0);
}
else
{
$_SESSION['message'] = "Not Imported!";
header("Location: mandates.php");
exit(0);
}
}
else
{
$_SESSION['message'] = "Invalid File!";
header("Location: mandates.php");
exit(0);`enter code here`
}
Is there any way I can have some code that will allow me to only get data from E4 cell of my excel file?
To access specific parts of the spreadsheet rather than the whole sheet, you can use . You can then specify
E4
as the start point. To make sure you get all the rows, use...
$endRow = $spreadsheet->getActiveSheet()->getHighestRow();
This can be used to specify the end of the range to fetch...
$data = $spreadsheet->getActiveSheet()->rangeToArray('E4:X' . $endRow);
(Not sure if X is the right range for the end column, you can adjust this as required.)
One thing to note is that as this starts at column E, this columns value will be in the 0 element of the array, so you may need to adjust the way you access the data.
Just as an alternative - you could just skip the first couple of rows in the array of all of the data (you can use to chop of the rows you don't want.)
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.