devofash Posted October 23, 2009 Share Posted October 23, 2009 Hi Guys I am using phpexcelreader to read excel files and displaying records as html http://sourceforge.net/projects/phpexcelreader/ It works all fine but what I want to do is search through that excel and display a particluar record. for example I want the details of a person with acc id 65. Here is my code: ExcelRead.php <html> <head> <style type="text/css"> table { border-collapse: collapse; } td { border: 1px solid black; padding: 0 0.5em; } </style> </head> <body> <table> <?php // include class file include 'Excel/reader.php'; // initialize reader object $excel = new Spreadsheet_Excel_Reader(); // read spreadsheet data $excel->read('book1.xls'); // iterate over spreadsheet cells and print as HTML table $x=1; while($x<=$excel->sheets[0]['numRows']) { echo "\t<tr>\n"; $y=1; while($y<=$excel->sheets[0]['numCols']) { $cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : ''; echo "\t\t<td>$cell</td>\n"; $y++; } echo "\t</tr>\n"; $x++; } ?> </table> </body> </html> book1.xls Acc No First Middle Last Email 123 Person 1 Middle name 1 Last name 1 email 1 32 Person 2 Middle name 2 Last name 2 email 2 445 Person 3 Middle name 3 Last name 3 email 3 65 Person 4 Middle name 4 Last name 4 email 4 I would really appreciate any help. Thanks Quote Link to comment Share on other sites More sharing options...
purpleshadez Posted October 23, 2009 Share Posted October 23, 2009 I use this class a fair bit, it has some really nice touches. This is an idea of how I would do it. You could make a html form with a text box then use the variable provided for the search. You could also use a select input so you could search each colummn in the spreadsheet. Hope this helps. <html> <head> <style type="text/css"> table { border-collapse: collapse; } td { border: 1px solid black; padding: 0 0.5em; } </style> </head> <body> <table> <?php // include class file include 'Excel/reader.php'; // This could be post or get data from a form if you need to make it look for something other than id 65. $search_var = 65; // initialize reader object // Use the construct to read the file FALSE means php will not get the cell format data such as font color etc.. $excel = new Spreadsheet_Excel_Reader('book1.xls', FALSE); // get total number of rows in spreadsheet $tot = $excel -> rowcount($sheet_index = 0); // don't really need this bit but it makes it easier to follow in big scripts $cells = $excel -> sheets[0]['cells']; // Start the loop on the first row for ($row = 1; $row <= $tot; $row++) { // the number 1 in $cells[$row][1] relates to the colummn as this is a multi dimentional array. // You could make this a variable so you have more adaptable search options if($cells[$row][1] == $search_var) { echo "\t<tr>\n"; echo "\t\t<td>" . $cells[$row][1] . "</td><td>" . $cells[$row][2] . "</td>/n"; // etc... echo "\t</tr>\n"; } } ?> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
devofash Posted October 23, 2009 Author Share Posted October 23, 2009 Thanks so much.... it works like a charm =) Quote Link to comment Share on other sites More sharing options...
purpleshadez Posted October 23, 2009 Share Posted October 23, 2009 No worries for the record, you can get some more info about this class using this link: http://code.google.com/p/php-excel-reader/wiki/Documentation Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.