Last active
April 29, 2016 07:02
-
-
Save tecoholic/c1d03955e2f0f5a3ae6c636fd56e2bc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
include("db_con.php"); | |
?> | |
<html> | |
<head><title>PHP: Parse and Retrieve Data from XLSX Files | SPYROZONE.NET</title> | |
<meta charset="utf-8"> | |
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">--> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<!-- jQuery --> | |
<script src="js/jquery-2.1.4.min.js"></script> | |
<link rel="stylesheet" href="css/bootstrap.min.css"> | |
<link rel="stylesheet" href="css/bootstrap-theme.min.css"> | |
<script src="js/bootstrap.min.js"></script> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> | |
<script>2014 | |
</script> | |
<!-- Font Awesome --> | |
<link rel="stylesheet" href="css/font-awesome.min.css"> | |
<!-- Custom CSS --> | |
<link rel="stylesheet" href="css/owl.carousel.css"> | |
<link rel="stylesheet" href="style.css"> | |
<link rel="stylesheet" href="css/responsive.css"> | |
<!-- Google Fonts --> | |
<link href='http://fonts.googleapis.com/css?family=Titillium+Web:400,200,300,700,600' rel='stylesheet' type='text/css'> | |
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700,300' rel='stylesheet' type='text/css'> | |
<link href='http://fonts.googleapis.com/css?family=Raleway:400,100' rel='stylesheet' type='text/css'> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> | |
<style> | |
<!--- | |
a{text-decoration:none;color:#0000FF;} | |
a:hover{text-decoration:underline;color:#0000FF;} | |
a:visited{text-decoration:none;color:#0000FF;} | |
a:active{text-decoration:none;position: relative;top: 1px;} | |
h1{font-family: "Arial","Verdana","Lucida Sans Unicode"; font-size: 16pt; line-height:150%; margin-top:20; margin-bottom:0 ;text-align:center;} | |
h2{font-family: "Arial","Verdana","Lucida Sans Unicode"; font-size: 12pt; font-weight: bold; text-decoration: underline; line-height:150%; margin-top:40; margin-bottom:10 } | |
h3{font-family: "Arial","Verdana","Lucida Sans Unicode"; font-size: 11pt; line-height:150%; margin-top:20; margin-bottom:0} | |
ul{font-family: "Arial","Verdana","Lucida Sans Unicode"; font-size: 11pt;word-spacing: 0; line-height: 150%; margin-top: 0; margin-bottom: 0} | |
p{font-family: "Arial","Verdana","Lucida Sans Unicode"; font-size: 11pt } | |
#datacontent{margin-left:20pt} | |
#footer{ font-family: "Arial","Verdana","Lucida Sans Unicode"; font-size: 10pt; line-height:150%; margin-top:40; margin-bottom:0;text-align:center} | |
#xlsxTable{font-family: "Arial","Verdana","Lucida Sans Unicode";font-size: 11pt;margin: 15px;text-align: left;border-collapse: collapse;} | |
#xlsxTable th{padding: 8px;font-weight: normal;font-size: 13px;color: #039;background: #b9c9fe;} | |
#xlsxTable td{padding: 8px;background: #e8edff;border-top: 1px solid #fff;color: #669;} | |
#xlsxTable tbody tr:hover td{background: #d0dafd;} | |
//---> | |
</style> | |
</head> | |
<body> | |
<nav class="navbar navbar-inverse navbar-fixed-top"> | |
<!-- <nav class="navbar navbar-default">--> | |
<div class="container-fluid"> | |
<!-- Brand and toggle get grouped for better mobile display --> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> | |
<span class="sr-only">Toggle navigation</span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<!--<a class="navbar-brand" href="#">Kobster</a>--> | |
</div> | |
<div class="navbar-header"> | |
<a class="navbar-brand" href="#"> | |
<img alt="Kobster.com" src="C:\xampp\htdocs\Kobster_Project\Images\kobster.jpg"> | |
</a> | |
</div> | |
<!-- Collect the nav links, forms, and other content for toggling --> | |
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> | |
<ul class="nav navbar-nav"> | |
<!-- <li class="active"><a href="#">Home <span class="sr-only">(current)</span></a></li>--> | |
<li><a href="index.php"><span class="glyphicon glyphicon-home"></span>Home</a></li> | |
<li><a href="#"><span class="glyphicon glyphicon-user"></span>About</a></li> | |
</ul> | |
<!--<form class="navbar-form navbar-right" role="search"> | |
<div class="form-group"> | |
<input type="text" class="form-control" placeholder="Search"> | |
</div> | |
<button type="submit" class="form-control btn btn-default" style=""><i class="glyphicon glyphicon-search"></i></button>--> | |
<!--<button type="submit" class="btn btn-default">Submit</button>--> | |
</form> | |
<ul class="nav navbar-nav navbar-right"> | |
<!-- <li><a href="#">Link</a></li>--> | |
<li class="dropdown"> | |
<a href="" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Suppling Products <span class="caret"></span></a> | |
<ul class="dropdown-menu"> | |
<li><a href="#">Office Suppliers</a></li> | |
<li><a href="#">Electronics</a></li> | |
<li><a href="#">Constraction</a></li> | |
<li><a href="#">Hospital & Management</a></li> | |
<li role="separator" class="divider"></li> | |
<li><a href="#">Careers</a></li> | |
</ul> | |
</li> | |
<li role="presentation" class="dropdown"> | |
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false"> | |
<span class="glyphicon glyphicon-user"></span> <?php echo $_SESSION["name"]; ?><span class="caret"></span> | |
</a> | |
<ul class="dropdown-menu"> | |
<li><a href="account_activity.php?key=view_profile" target="i_frame"><span class="glyphicons glyphicon glyphicon-sunglasses"></span> View Profile</a></li> | |
<li><a href="account_activity.php?key=edit_profile" target="i_frame"><span class="glyphicons glyphicon glyphicon-scissors"></span> Edit Profile</a></li> | |
<li><a href="account_activity.php?key=change_password" target="i_frame"><span class="glyphicon glyphicon-lock"></span> Change Password</a></li> | |
<li><a href="logout.php" target="_parent"><span class="glyphicon glyphicon-off"></span> Logout</a></li> | |
</ul> | |
</li> | |
</ul> | |
</div><!-- /.navbar-collapse --> | |
</div><!-- /.container-fluid --> | |
</div> | |
</nav> | |
</div> | |
<!---------------------------------------------------------------------------------> | |
<!--<div id="datacontent"> | |
<form method="post" enctype="multipart/form-data"> | |
<p>File: <input type="file" name="file" /><input type="submit" value="Parse" /></p> | |
</form> | |
</div>--> | |
<br/> | |
<br/> | |
<br/> | |
<div class="navbar navbar-default navbar-static-top"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<a class="navbar-brand" href="#">Customer File Uploader</a> | |
</div> | |
</div> | |
</div> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-lg-12"> | |
<form method="post" enctype="multipart/form-data"> | |
<div class="form-group"> | |
<label for="file">Select a file to upload</label> | |
<input type="file" name="file"> | |
<p class="help-block">first three columns mandatory for Brand, Product type, Product code Only xslx file with maximum size of 15 Kb is allowed.</p> | |
</div> | |
<input type="submit" class="btn btn-lg btn-primary" value="Upload"> | |
</form> | |
</div> | |
</div> | |
</div> <!-- /container --> | |
<?php | |
if((!empty($_FILES["file"])) && ($_FILES['file']['error'] == 0)) { | |
$limitSize = 15000; //(15 kb) - Maximum size of uploaded file, change it to any size you want | |
$fileName = basename($_FILES['file']['name']); | |
$fileSize = $_FILES["file"]["size"]; | |
$fileExt = substr($fileName, strrpos($fileName, '.') + 1); | |
if (($fileExt == "xlsx") && ($fileSize < $limitSize)) { | |
require_once "simplexlsx.class.php"; | |
$getWorksheetName = array(); | |
$xlsx = new SimpleXLSX( $_FILES['file']['tmp_name'] ); | |
$getWorksheetName = $xlsx->getWorksheetName(); | |
echo '<h2>File Info:</h1><ul>'; | |
echo '<li><b>File Name:</b> '.$fileName.'</li>'; | |
echo '<li><b>File Size:</b> '.($fileSize/1000).' kb</li></li>'; | |
$dataArray=array(); | |
echo '<h2>Display data in table format:</h2> | |
<div id="datacontent">'; | |
for($j=1;$j <= $xlsx->sheetsCount();$j++){ | |
echo '<h3>Worksheet Name: '.$getWorksheetName[$j-1].'</h1>'; | |
?> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>Image</th> | |
<th>Name of the Product</th> | |
<th>Description</th> | |
<th>Price</th> | |
<th>Quantity</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
list($cols,) = $xlsx->dimension($j); | |
//Prepare table | |
foreach( $xlsx->rows($j) as $k => $r) { | |
$query = "select * from product WHERE Pro_brand LIKE '%$r[0]%' AND Pro_name LIKE '%$r[1]%'"; | |
$run_query = mysqli_query($con,$query); | |
while($row = mysqli_fetch_array($run_query)) | |
{ | |
?> | |
<tr> | |
<td class="image"> | |
<?php | |
echo "<img src=\"upload/".$row['Image']."\" alt=".$row['Pro_name']." class='img-responsive'>"; | |
?> | |
</td> | |
<td class="name"> | |
<?php | |
echo $row['Pro_name']; | |
?> | |
</td> | |
<td class="description"> | |
<?php | |
echo $row['Description']; | |
?> | |
</td> | |
<td class="price"> | |
<?php | |
echo $row['Price']; | |
?> | |
</td> | |
<td class="quantity"> | |
<input class="form-control" type="number" min=0 max=100 /> | |
</td> | |
</tr> | |
<?php | |
// close the mysql loop | |
} | |
// close the row loop | |
} | |
// close the sheet loop | |
} | |
?> | |
</tbody> | |
</table> | |
<?php | |
/* | |
for( $i = 0; $i < $cols; $i++) | |
//Display data | |
echo $trOpen.'>'.( (isset($r[$i])) ? $r[$i] : ' ' ).$trClose; | |
if($k!=0) | |
array_push($dataArray,$r[0]); | |
//$temp=array_push($dataArray,$r[1]); | |
//array_push($dataArray,$r[2]); | |
echo '</tr>'; | |
echo $tbClose; | |
} | |
echo '</table>'; | |
var_dump($dataArray); | |
} | |
echo '</div> | |
<h2>Display as Array:</h2> | |
<div id="datacontent" style="overflow: auto; height: 400px; width: 550px; border: 1px #008080 solid;">'; | |
echo '<h3>$xlsx->getWorksheetName()</h1>'; | |
echo '<pre>'; | |
print_r($xlsx->getWorksheetName()); | |
echo '</pre>'; | |
for($j=1;$j <= $xlsx->sheetsCount();$j++){ | |
echo '<h3>$xlsx->rows('.$j.')</h1>'; | |
echo '<pre>'; | |
print_r( $xlsx->rows($j) ); | |
echo '</pre>'; | |
echo '<h3>$xlsx->rowsEx('.$j.')</h1>'; | |
echo '<pre>'; | |
print_r( $xlsx->rowsEx($j) ); | |
echo '</pre>'; | |
} | |
echo ' </div> | |
</div> | |
<hr>'; | |
}else{ | |
echo '<script>alert("Sory, this demo page only allowed .xlsx file under '.($limitSize/1000).' Kb!\nIf you want to try upload larger file, please download the source and try it on your own webserver.")</script>'; | |
} | |
} | |
*/ | |
?> | |
<div id="footer">© 2012++ Kobster EShop | http://www.kobster.com<br>All Rights Reserved</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment