Tuesday, 18 July 2017

Data read from excel file in php

This is a example of read data from excel file in php. In this example all
data read from excel file and these data shows in html table.

Screenshot 1: Excel file data





Screenshot 2: Data show as html table





Click to download from here.




<?php  
  include 'excel_reader.php';   // include the class  
 // creates an object instance of the class, and read the excel file data  
 $excel = new PhpExcelReader;  
 $excel->read('demo.xls');  
 //returns a HTML table with excel rows and columns data  
 function sheetData($sheet) {  
  $html = '<table style="border-collapse: collapse;">';   // begin html table  
  $x = 1;  
  while($x <= $sheet['numRows']) {  
   $html .= "<tr>\n";  
   $y = 1;  
   while($y <= $sheet['numCols']) {  
    $cell = isset($sheet['cells'][$x][$y]) ? $sheet['cells'][$x][$y] : '';  
    $html .= "<td style='border: 1px solid black; padding: 0 0.5em;'>$cell</td>\n";  
    $y++;  
   }   
   $html .= "</tr>\n";  
   $x++;  
  }  
  return $html .'</table>';   // ends and returns the html table  
 }  
 $sheets = count($excel->sheets);    // gets the number of sheets  
 $excel_data = '';             // to store the the html tables with data of each sheet  
 // traverses the number of sheets and sets html table with each sheet data in $excel_data  
 for($i=0; $i<$sheets; $i++) {  
  $excel_data .= '<h4>Sheet '. ($i + 1) .' (<em>'. $excel->boundsheets[$i]['name'] .'</em>)</h4>'. sheetData($excel->sheets[$i]) .'<br/>';   
 }  
 ?>  
 <?php  
   echo $excel_data;  // displays tables with excel file data  
 ?>  

No comments:

Post a Comment

How to create an visitor counter in PHP | hit counter

Total page view in the php. This count hit in the page. <?php session_start(); if(isset($_SESSION['page_view'])){...