How to view Excel file second sheet? - php

Basically, I have create a page to view xlxs file on browser. It works fine but the problem is this php code only can show one sheet.
What I am trying to achieve:
Display Excel spreadsheets in table format on browsers using PHP Excel Reader
Check how many sheets are in the .xls document, get the sheet name and display the amount of buttons accordingly
The buttons must be able to allow the user to traverse between different sheets of one document
Code:
<?php
if($the1['file_type']=='excel'){
require_once "Classes/PHPExcel.php";
$reader= PHPExcel_IOFactory::createReaderForFile($the1['path'].'/'.$the1['file_name']);
$excel_Obj = $reader->load($the1['path'].'/'.$the1['file_name']);
$worksheet=$excel_Obj->getSheet('0');
$lastRow = $worksheet->getHighestRow();
$columncount = $worksheet->getHighestDataColumn();
$columncount_number=PHPExcel_Cell::columnIndexFromString($columncount);
echo "<table border='1'>";
for($row=0;$row<=$lastRow;$row++){
echo "<tr>";
for($col=0;$col<=$columncount_number;$col++){
echo "<td>";
echo $worksheet->getCell(PHPExcel_Cell::stringFromColumnIndex($col).$row)->getValue();
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
mysqli_query($con,"update file1 set status='read' where file_name='$id'");
}
?>

Use setActiveSheetIndex(sheet number) to specify worksheet 0 (1st worksheet), 1 (2nd worksheet), 2 (third worksheet) and so on. For example
$sheetindex=1; // use the 2nd sheet
$worksheet = $excel_Obj->setActiveSheetIndex($sheetindex);

Related

Print book Titles with corresponding images covers

The file data is a list of book titles, and links to their cover images (hosted on Wikipedia). novels.txt and covers.txt.
Read in both files, and create a table
Each row should include the title of the book on the left, and an embedded image tag.
Here's my code.
//load file
$covers = file("covers.txt", FILE_IGNORE_NEW_LINES);
$novels = file("novels.txt",FILE_IGNORE_NEW_LINES);
//print table header
print "<table
<tr>
<th>Book</th>
<th>Cover</th>";
foreach($novels as $i=>$novel){
print "<tr>
<td>$novel</td>
<td>$covers[$i]</td>
</tr>";
"</table>";
}
It is printing out the title of the book with the corresponding URL instead of the image. How do i get it to print out the image?

How to create .csv text to table in PHP

Hello any ideas or suggestion how to make conversion my .csv text to table?
Check this link for reference: http://vis.stanford.edu/wrangler/app/
You can browse your .csv with fgetcsv and use foreach to browse the array returned. You simply displays the result.
Here is an exemple :
// Open the file with PHP
$oFile = fopen('PATH_TO_FILE', 'w');
// Get the csv content
$aCsvContent = fgetcsv($oFile);
// HTML Table
echo '<table>';
// Browse your csv line per line
foreach($aCsvContent as $aRow) {
// New table line
echo '<tr>';
// Browse your line cell per cell
foreach($aRow as $sContent) {
// New cell with the content
echo '<td>'.$sContent.'</td>';
}
// End the line
echo '</tr>';
}
// Close the HTML Table
echo '</table>';
// Close you file
fclose($oFile);
I have done this 3 weeks ago ^_^
If you have a problem, tell me. Maybe I can help you !

Styling each result of an fgets($file) list differently, is it possible?

G'day, first post so here we go. Very open to suggestions as I'm not sure if it's possible to do what I want with the type of coding I am using. Kinda new/rusty to coding, been a LOOOONG time.
Purpose of current coding:
I have a .txt file with a list of file names (map names to be exact for my situation, each on it's own line) that is constantly being changed and modified as we add/remove maps. I am using a script on a .php page to parse the contents of that file and display the results on a webpage. The script outputs each map name to a variable that is wrapped in an href tag, which results in a link to download that particular map. This continues until all maps have been created in a list, each as a link to download that map.
Problem I am having:
I do not wish some maps/entries to be created as links, and only as text. Is there a way to filter the results of an fgets() and style them different based on value? So like map1-map4 all get turned into download links but map5 does not, then map6 and on continue to be download links.
Current script/code being used:
<?php
$file = fopen("maplists/dodgeball.ini", "r");
while (!feof($file)) {
$dbmapname[] = fgets($file);
}
fclose($file);
foreach ($dbmapname as $dbmap){
echo "<a href='http://www.mydownloadurl.com/fastdl/maps/" . $dbmap . ".bsp.bz2'>$dbmap</a><br />";
}
?>
Coding revised thanks to help below. Here is my current coding to produce what I was looking for:
foreach ($dbmapname as $dbmap){
if(!in_array($dbmap, $stockmaps)){
echo "<a href='http://www.mydownloadurl.com/fastdl/maps/" . $dbmap . ".bsp.bz2'>$dbmap</a><br />";
}
else echo $dbmap."<br />";
}
I am still having a slight issue though regarding the last entry of the array being forced to be a link regardless if it is in the $stockmaps array or not.
There are a ton of ways to implement this. Below I've presented a nice general way where you create an array of maps for which you don't want a link and then loop through and print either link or the plain text depending on whether each map is in the list.
<?php
$file = fopen("maplists/dodgeball.ini", "r");
while (!feof($file)) {
$dbmapname[] = trim(fgets($file));
}
fclose($file);
$nolink = array( $dbmapname[4] ); //fifth map
foreach ($dbmapname as $dbmap){
if(!in_array($dbmap, $nolink)){
echo "<a href='http://www.mydownloadurl.com/fastdl/maps/" . $dbmap . ".bsp.bz2'>$dbmap</a><br />";
}
else echo $dbmap."<br />";
}
}
?>
You can add item to the filter based on whatever criteria you want
//Add item 2 to the list
$nolink[] = $dbmapname[1];
//Add all items after item 20 to the list
$nolink = array_merge($nolink, array_slice($dbmapname, 20));
//Don't link a specific set of maps
$nolink = array('bad_map', 'another_map_not_to_show');

Got a bunch of images, need to put them together to form a big picture (like a puzzle)

I got a bunch of images (225 in total). Example of their names:
4n27e.png
4n28e.png
4n29e.png
4n30e.png
5n12e.png
5n25e.png
5n26e.png
5n27e.png
5n28e.png
I need to form one big picture out of all these images. For example first line of images would be 4n27e (2nd image 4n28e, 3rd image 4n29e and so on). Second line of images would start from 5n12e (2nd image 5n25e and so on). What methods do i need to search for to solve this?
Note: i need to do this only with php and maybe some javascript.
Test case for logic, you can replace the echo with an img tag, and /or use div.
<?php
$images=array();
$images[]="4n27e.png";
$images[]="4n28e.png";
$images[]="4n29e.png";
$images[]="4n30e.png";
$images[]="5n12e.png";
$images[]="5n25e.png";
$images[]="5n26e.png";
$images[]="5n27e.png";
$images[]="5n28e.png";
echo "<table border='1'>";
$oldIndex=0;
$row=1;
foreach($images as $image)
{
if(substr($image,0,1)!=$oldIndex)
{
if($row>1){echo "</tr>";}
echo "<tr>";
$oldIndex=substr($image,0,1);
$row++;
}
echo "<td>$image</td>";
}
echo "</table>";
?>

Creating a grid view of products in PHP

very new to PHP to please bear with.
As you can see from my snippet of code I am simply displaying product information one line under each other then repeating the loop using while. This then obviously displays my relevant data in just one column, one under each other.
while ($row = mysqli_fetch_row($result)){
echo "<img src=\"images/album1.jpg\"/><br>"; //this will eventually show the product image
echo "$row[1] <br>"; //this shows the product name
echo "<strong>&pound$row[2]</strong><br>"; //this shows the product price
}
How would I go about creating a grid view, for example using columns to display my data? I presume it would be some kind of loop to be added and maybe using tables to display my data?
Any help is greatly appreciated.
you can dot this by creating div and float that div to left this will create grid view
while ($row = mysqli_fetch_row($result)){
echo "<div class='container'>";
echo "<img src=\"images/album1.jpg\"/><br>"; //this will eventually show the product image
echo "$row[1] <br>"; //this shows the product name
echo "<strong>&pound$row[2]</strong><br>"; //this shows the product price
echo "</div>";
}
and css
.container{
float:left;
}
you can
also set the max height and width of div

Categories