Good news : I have answer to coding to support import Excel file to auto insert Excel data into PHPExcel+HTML input form (parse this response Excel data into desired fields) with my full source code.
I have answer credit with
link.
1. excelimport.xlsx (Excel file)
Download Link
2. excelimport.php (PHP Code)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
h2 {display: inline;}
</style>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="myform1" id="myform1">
<h2 for="myfile1">Select files : </h2><input type="file" name="excelFile" id="excelFile" /><br><br>
<h2 for="fname">First name : </h2><input type="text" id="fname" name="fname"><br><br>
<h2 for="lname">Last name : </h2><input type="text" id="lname" name="lname"><br><br>
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#excelFile").on("change",function(e){
e.preventDefault();
var formData = new FormData($("#myform1")[0]);
$.ajax({
url: 'read_excel.php',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false
}).done(function(data){
console.log(data);
$("#fname").val(data.A2);
$("#lname").val(data.B2);
});
});
});
</script>
</body>
</html>
3. read_excel.php (PHP Code)
<?php
header("Content-type:application/json; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Asia/Bangkok');
require_once("PHPExcel/Classes/PHPExcel.php");
?>
<?php
if(isset($_FILES['excelFile']['name']) && $_FILES['excelFile']['name']!=""){
$tmpFile = $_FILES['excelFile']['tmp_name'];
$fileName = $_FILES['excelFile']['name'];
$_fileup = $_FILES['excelFile'];
$info = pathinfo($fileName);
$allow_file = array("csv","xls","xlsx");
if($fileName!="" && in_array($info['extension'],$allow_file)){
$objPHPExcel = PHPExcel_IOFactory::load($tmpFile);
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
$v=1;
$json_data = array();
foreach ($cell_collection as $cell) {
$column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
$json_data["$column$row"] = $data_value;
$v++;
}
if(isset($json_data)){
$json= json_encode($json_data);
if(isset($_GET['callback']) && $_GET['callback']!=""){
echo $_GET['callback']."(".$json.");";
}else{
echo $json;
}
}
}
}
?>
I use PHPExcel library to download with
link.