Hi everyone,

I am facing one problem. In one php page which is showing a table or record of an employee and i want to show that table in excel sheet with using download button which table is coming in php file.

So how i can do this using php code or html code . Please help me
Actually i want to show a empoyee record in excel page ( directly clicking on a button).

So how i can do this. If u have any example to do this. then please tell me . It is very urgent.

Thanks,
Gagan

Recommended Answers

All 28 Replies

There is a topic about it at http://www.daniweb.com/forums/showthread.php?t=91019&highlight=excel
It basically says to use the excel html formating like when you export html file from excel. Also it quotes the following code:

<?php


echo "<table cellspacing='4' cellpadding='4' border=1 align=center>";
echo"<tr>";
echo"<td>Day</td>";
echo"<td>Time</td>";
echo"<td>Unit</td>";
echo"<td>Lecturer</td>";
echo"</tr>";

echo"</table>";















header("Content-type: application/octet-stream");

# replace excelfile.xls with whatever you want the filename to default to
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");


?> 
  
  
</p>
</body>
</html>

Hope that helps.

There is a topic about it at http://www.daniweb.com/forums/thread91019.html&highlight=excel
It basically says to use the excel html formating like when you export html file from excel. Also it quotes the following code:

Hope that helps.

hi sir,

I have used Sql query to fetching a record from a databse and this is showing this on a web page like this--

Date Day TimeIn TimeOut TotalTime Status
2009-02-23 Monday 10:11:18 19:38:22 9.27 Hours O.K.
2009-02-24 Tuesday 10:09:52 20:06:27 9.56 Hours O.K.
2009-02-25 Wednesday 10:04:13 18:52:28 8.49 Hours O.K.
2009-02-26 Thursday 09:56:55 19:52:56 9.56 Hours O.K.
2009-02-27 Friday 10:08:51 18:00:00 -.09 Hours O.K.
2009-02-28 Saturday 10:06:13 19:50:34 9.44 Hours O.K.
2009-03-01 Sunday Sunday Sunday Sunday Sunday
2009-03-02 Monday 10:09:09 15:31:12 5.31 Hours O.K.
below this i have used this link .
<td height="4" colspan="8" bgcolor="#FFFFFF" scope="row" align="center"><a href="test.xls">Downaload This page</a></td>

but now i want this should be copy in excel file and what code i wil have to written in php so that these all result would come in Excel file . that is the thing i want to do . this i was asking. Please help me
Thanks
gagan

Well I don't know you database structure (column names) but first step is to make the data output like the below. After you make a php file with the output like the below, then I shall show you how to add the headers to download as a excel file. The headers are also shown in the example above (previous post).

<table cellspacing='4' cellpadding='4' border=1 align=center>
<tr>
<td>Date</td>
<td>Day</td>
<td>TimeIn</td>
<td>TimeOut</td>
<td>TotalTime</td>
<td>Status</td>
</tr>
<tr>
<td>2009-02-23</td>
<td>Monday</td>
<td>10:11:18</td>
<td>19:38:22</td>
<td>9.27 Hours</td>
<td>O.K.</td>
</tr>
<tr>
<td>2009-02-24</td>
<td>Tuesday</td>
<td>10:09:52</td>
<td>20:06:27</td>
<td>9.56 Hours</td>
<td>O.K.</td>
</tr>
<tr>
<td>2009-02-25</td>
<td>Wednesday</td>
<td>10:04:13</td>
<td>18:52:28</td>
<td>8.49 Hours</td>
<td>O.K.</td>
</tr>
<tr>
<td>2009-02-26</td>
<td>Thursday</td>
<td>09:56:55</td>
<td>19:52:56</td>
<td>9.56 Hours</td>
<td>O.K.</td>
</tr>
<tr>
<td>2009-02-27</td>
<td>Friday</td>
<td>10:08:51</td>
<td>18:00:00</td>
<td>09 Hours</td>
<td>O.K.</td>
</tr>
<tr>
<td>2009-02-28</td>
<td>Saturday</td>
<td>10:06:13</td>
<td>19:50:34</td>
<td>9.44 Hours</td>
<td>O.K.</td>
</tr>
</table>

Just a note, I noticed the link I provided didn't work so the update is: http://www.daniweb.com/forums/thread91019.html

//while clicking download button do this process
 $content - should have the content like
$content = "<table><tr><td>val1</td><td>val2</td></tr></table>";

header('Pragma: anytextexeptno-cache', true);
header("Content-type: application/vnd.ms-excel");
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename='myfile.xls');
print $content;

//while clicking download button do this process
$content - should have the content like
$content = "<table><tr><td>val1</td><td>val2</td></tr></table>";

header('Pragma: anytextexeptno-cache', true);
header("Content-type: application/vnd.ms-excel");
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename='myfile.xls');
print $content;

You have that backtofront. Unusally it is more like the following as quoted from an earlier post:

<?
$content - should have the content like
$content = "<table><tr><td>val1</td><td>val2</td></tr></table>";
echo $content;
header('Pragma: anytextexeptno-cache', true);
header("Content-type: application/vnd.ms-excel");
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename=myfile.xls');
?>
</p>
</body>
</html>

//while clicking download button do this process
$content - should have the content like
$content = "<table><tr><td>val1</td><td>val2</td></tr></table>";

header('Pragma: anytextexeptno-cache', true);
header("Content-type: application/vnd.ms-excel");
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename='myfile.xls');
print $content;

Hi vinoth,

I want to discuss with you . because i am facing one problem which i have already discussed in this forum session_start warning . please help me . i have done every effort for solving that warning.
pls help me if u can solve this.
thanks ,
gagan

Hi vinoth,

I want to discuss with you . because i am facing one problem which i have already discussed in this forum session_start warning . please help me . i have done every effort for solving that warning.
pls help me if u can solve this.
thanks ,
gagan

Did you check my post on http://www.daniweb.com/forums/thread177977.html
I have found numerous topics on both daniwebs and PHPfreaks in the past and two main reasons are the editor adds a hidden string at the beginning and the second being that there is something before <? tag. I believe some have even tried using <?php instead of <? or vice versa and is then successful.

Did you check my post on http://www.daniweb.com/forums/thread177977.html
I have found numerous topics on both daniwebs and PHPfreaks in the past and two main reasons are the editor adds a hidden string at the beginning and the second being that there is something before <? tag. I believe some have even tried using <?php instead of <? or vice versa and is then successful.

thanks for reply,
I have also tried this as u told me. I have changed the <? tag to <?php also .Still the problem is same . pls help me . how i can solve this.

thanks,

thanks for reply,
I have also tried this as u told me. I have changed the <? tag to <?php also .Still the problem is same . pls help me . how i can solve this.

thanks,

Try making a file using your normal editor and type the following code in it to see if it reports an error.

<?
session_start();
?>

hi gagan,
Please send me ur thread URL... (session_start)..

hi gagan,
Please send me ur thread URL... (session_start)..

ya sure sir,pls see this warning which i am facing . i am sending the url of my website. pls see this page and then tell me the solution for this.

http://www.warddamon.com/login/hoa.php?login=T

this is the url where this warning is coming. when i do session_start(); line in comments then this problem is not coming. but i need this line so that i can know about session.pls help me.
thanks,
gagan

hi gagan,
pls send ur (session_start) thread url...

hi gagan,
pls send ur (session_start) thread url...

about which URL u r saying about .........on which page i am facing this problem i have already send u that url.

http://www.warddamon.com/login/hoa.php?login=T

this is that URL where warning is coming. Can we chat on gmail . if u will say that will be easy for us communication.
thanks,
gagan

Also I still haven't heard of the results for when you try to open a page with only the following code:

<?
session_start();
?>

That will say if it is your editor.

Also I still haven't heard of the results for when you try to open a page with only the following code:

<?
session_start();
?>

That will say if it is your editor.

yes, if i run only this code in my php file .
means i am saying if i will write code in a.php file only
<?php
session_start();
?>
then warning are coming. then what will be reason for that ??

thanks,
gagan

hi gagan,
I tried to create the same error.... in my local system...
by,
i removed write permission to my temp folder(c:\windows\temp).
and i ran my php program which has the session_start.. and etc., things..
i got the same error.......
So the conclusion is...

Please make sure ur tmp folder and its SUB folders has the write permission... for all users

hi gagan,
I tried to create the same error.... in my local system...
by,
i removed write permission to my temp folder(c:\windows\temp).
and i ran my php program which has the session_start.. and etc., things..
i got the same error.......
So the conclusion is...

Please make sure ur tmp folder and its SUB folders has the write permission... for all users

thanks for reply,
i am so confused about this tmp folder .You are saying that tmp folder which are in my local system means on my wamp server or u r saying on that sever where this site is uploaded .

Pls tell me this on which sever i will have to check this tmp folder on my wamp sever or my client's sever.
thanks,
gagan

my window server...
default temp folder (c:/windows/temp)

wt abt u? r u using window/linux?
by seeing ur error.. i could able to understand . its linux.

So please make sure var/tmp folder and its sub folder has the write permission....

if still prob exist... we will try it in some other option

my window server...
default temp folder (c:/windows/temp)

wt abt u? r u using window/linux?
by seeing ur error.. i could able to understand . its linux.

So please make sure var/tmp folder and its sub folder has the write permission....

if still prob exist... we will try it in some other option

hi , me also using window. Did you mean i should change permissions from my system C:/window/temp folder . This means this poblem is not due to our client's system or sever. As already send u URL of website which is facing this problem.

ur local machine might be window....

wt abt ur site... (It is in linux server only know)

u hv gmail id?.. can u come 2 chat?

ur local machine might be window....

wt abt ur site... (It is in linux server only know)

yes sir , my site is on linux server........actually i am making site for my client. so he has linux sever where this site is uploaded.

Try making a file using your normal editor and type the following code in it to see if it reports an error.

<?
session_start();
?>

hello sir,
still, I am facing such type of problem if you want to see this
you can see this URL
http://www.warddamon.com/login/hoa.php?login=T

Please help me . How I can resolve this problem.
Thanks,
Gagan

*Repeats*
Its not the 'invisible character' in your script that is causing this error. Its the permissions. Change the permission of the folder php-ses and tmp to 0766. Ie., Read, write and execute to the owner
Read, write to groups and others. :) It will fix the problem. If you can't do that yourself, ask your system admin to do it for you.

*Repeats*
Its not the 'invisible character' in your script that is causing this error. Its the permissions. Change the permission of the folder php-ses and tmp to 0766. Ie., Read, write and execute to the owner
Read, write to groups and others. :) It will fix the problem. If you can't do that yourself, ask your system admin to do it for you.

hi ,
i have changed the permission of tmp folder still , problem is same.How i can resolve this. Please help me.
Thanks,
gagan

Not only the tmp folder, but also php-ses folder. :)

Not only the tmp folder, but also php-ses folder. :)

yes sir, i have also given 766 permission to tmp folder and php-ses folder also which is in tmp folder.still i am facing same problem. Pls help me .
thanks,
gagan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.