ExcelのコンテンツをMYSQLデータベースにアップロードするWebサイトがあります。問題は、無視したい行間にギャップがあることです。ExcelをMySqlデータベースにアップロードするときに行を除外する
これは、これは私のPHPコードです....例として
です:でなければならないの列で
<?php
session_start();
include("excel/Classes/PHPExcel/IOFactory.php");
$connect = mysqli_connect("","","", "");
$ficheiro = $_FILES['fileToUpload'];
$objPHPExcel = PHPExcel_IOFactory::load($ficheiro['tmp_name']);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet){
$highestRow = $worksheet->getHighestRow();
for($row=34; $row<=306; $row++) //I have this for but I want to exclude those lines
{
$worksheet->getCellByColumnAndRow(2,$row)->getValue();
$nif = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(0,$row)->getValue());
$MarcaExploracao = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(1,$row)->getValue());
$NumeroChip = mysqli_real_escape_string($connect, preg_replace('/[^0-9]/','',$worksheet->getCellByColumnAndRow(2,$row)->getValue()));
$Number = ltrim($NumeroChip,'0');
$MarcaAuricular = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(3,$row)->getValue());
$Data_Nascimento = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(4,$row)->getValue());
$ano = substr($Data_Nascimento,0,6);
$anoValido = preg_replace('/[^0-9]/', '', $ano);
$idade = date('Y')-$anoValido;
//$unixDate = ($Data_Nascimento - 25569) * 86400;
//$Data_Nascimento = gmdate("Y-m-d", $unixDate);
$sql = "INSERT INTO animal(NIF,MarcaExploracao,numerochip,MarcaAuricular,Data_Nascimento,id_utilizador,ano,idade) VALUES(".$nif.", '".$MarcaExploracao."', '".$Number."', '".$MarcaAuricular."', '".$Data_Nascimento."',{$_SESSION['id_utilizador']},'".$anoValido."','".$idade."')";
mysqli_query($connect,$sql);
}
}
?>
<script>
alert("Excel adicionado");
self.location="InserirOvelhas.php";
</script>
@RiggsFollyあなたは私を助けることができますか? – Jose