php - 使用我的代码,我如何使用 php 获取某些行和列的数据而不是工作表上的每个数据
问题描述
我有一个工作代码,可以从头到尾检索 excel 表中的每个数据。我希望我的代码从某个点开始检索数据,而不仅仅是从第一行开始,例如我希望循环遍历数据从第 1 行第 2 列向下,而不是第 1 行第 1 列。现在,我的代码只检索行,没有列。如何使用我的代码在结果中指定列。谢谢
<?php
require_once('db_config.php');
require_once('library/php-excel-reader/excel_reader2.php');
require_once('library/SpreadsheetReader.php');
if (isset($_POST["import"]))
{
$allowedFileType = ['application/vnd.ms-excel','text/xls','text/xlsx','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
if(in_array($_FILES["file"]["type"],$allowedFileType)){
$targetPath = 'uploads/'.$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);
$Reader = new SpreadsheetReader($targetPath);
$sheetCount = count($Reader->sheets());
for($i=0;$i<$sheetCount;$i++)
{
$Reader->ChangeSheet($i);
foreach ($Reader as $Row)
{
$name = "";
if(isset($Row[0])) {
$name = mysqli_real_escape_string($mysqli,$Row[0]);
}
$description = "";
if(isset($Row[1])) {
$description = mysqli_real_escape_string($mysqli,$Row[1]);
}
if (!empty($name) || !empty($description)) {
$query = "insert into tbl_info(name,description) values('".$name."','".$description."')";
$result = mysqli_query($mysqli, $query);
if (! empty($result)) {
$type = "success";
$message = "Excel Data Imported into the Database";
} else {
$type = "error";
$message = "Problem in Importing Excel Data";
}
}
}
}
}
else
{
$type = "error";
$message = "Invalid File Type. Upload Excel File.";
}
}
?>
我希望我的代码从某个点循环,比如说第二行或第三行,而不是一行中的每个数据