Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
NEED Help in saving data into .xls file
Old 09-04-2007, 12:11 AM NEED Help in saving data into .xls file
Skilled Talker

Posts: 65
Trades: 0
HI, actually am new to php enviroment and i need a help in saving the data into the .xls file exectly according to how the data is organised in the php page.
currently i can retrieve the datafrom the database and display it. what should i do to save the data into the .xls file by providing a link?

Code:
<?php
$host="localhost";  
$username="root";
$password="";
$db_name="test"; 
$tbl_name="test_mysql";  
 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
 
while($rows=mysql_fetch_array($result)){
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%"><? echo $rows['id']; ?></td>
<td width="30%"><? echo $rows['name']; ?></td>
<td width="30%"><? echo $rows['lastname']; ?></td>
<td width="30%"><? echo $rows['email']; ?></td>
</tr>
</table>
<?
 
}
 
mysql_close();
?>
this is how i display the data in the php page according to the format (id,name,lastname,email). how do i save the data into the .xls file so the format in the .xls file will also be the same as how it is displayed in the php page by providing a link?
leolim is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-04-2007, 03:45 AM Re: NEED Help in saving data into .xls file
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Do not go to .xls, the format is closed, and microsoft don't gives how it's formatted.

Generate an CSV (comma separated values), and let excel import it if you want to exchange datas.
Simply generate a text file, with the first line being the fields name, and every later lines being the datas:
Code:
id,name,value
1,"this is a name", "and it's value"
2,"my name is Joe", "and I love bananas"
Excel will read and display those correctly.
But it only support datas, no formulas/macros
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-05-2007, 02:06 AM Re: NEED Help in saving data into .xls file
Skilled Talker

Posts: 65
Trades: 0
But i am still unclear with
Generate an CSV (comma separated values), and let excel import it if you want to exchange datas.
How should i actually do the. pls give me guide.
thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-05-2007, 06:11 AM Re: NEED Help in saving data into .xls file
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
simply create a file with the structure like I've displayed above.
Once this file is created, with an .xls extension, when you try to open it with excel, it will display it like it was an excel file.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-06-2007, 01:35 AM Re: NEED Help in saving data into .xls file
Skilled Talker

Posts: 65
Trades: 0
Actually i am still blur about it as the enviroment are new to me. kindly could you explain it more detail?
thanks
leolim is offline
Reply With Quote
View Public Profile
 
Old 09-06-2007, 10:05 PM Re: NEED Help in saving data into .xls file
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Actually Excel can accept a type of format in which you can create a dynamic page for it. Its a cross between html and xml in which you can alter the xls layout with specific widths colors styles and multiple other things.

I don't know what the format is, but I bet you could Google it, or better yet find another php script to download to use as an example. (phpMyAdmin export modules for example).
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 09-08-2007, 08:46 AM Re: NEED Help in saving data into .xls file
Skilled Talker

Posts: 62
Name: Tom Wright
Location: Brighton, UK
Trades: 0
When reading writing csv files in php there are a few key funtions you'll want to read up on:
  1. fopen and related - these are simple functions which handle files very well.
  2. explode/implode - these are great for converting arrays (which are great for storing tabular data in php) into delimited strings (like you'll want for your csv file).
If I were at work I'd put some sample code for you to play with, but you should be able to make a start from this post. Let me know if you have any trouble.
Tom
__________________
My site:
Please login or register to view this content. Registration is FREE
tomythius is offline
Reply With Quote
View Public Profile
 
Old 09-10-2007, 05:24 PM Re: NEED Help in saving data into .xls file
masoko's Avatar
Novice Talker

Posts: 7
Name: masoko
Location: Bulgaria
Trades: 0
here is an example on how to generate xml

PHP Code:
print "<?xml version='1.0' encoding='utf-8'?>\n";
print "<Properties>\n";
print "<Exporter><![CDATA[http://site.com]]></Exporter>\n";
while ($row = mysql_fetch_array($result)) 
        {
            $listings ++;
                

            print "<Property>\n";
            print "<PropertyID><![CDATA[".$row[id1]."]]></PropertyID>\n";
            print "<PropertyName><![CDATA[".$row[title]."]]></PropertyName>\n";
            print "<PropertyTypeName><![CDATA[".xmlentities($propcat[$row[proptype]])."]]></PropertyTypeName>\n";
            print "<LocationName><![CDATA[".$row[location]."]]></LocationName>\n";
            print "<LocationTypeName><![CDATA[".$row[locationtype]."]]></LocationTypeName>\n";
            print "<RegionName><![CDATA[".$row[regionname]."]]></RegionName>\n";
            print "<Description><![CDATA[".strip_tags($row[descr])."]]></Description>\n";
            print "<Area><![CDATA[".$row[size]."]]></Area>\n";
            print "<Garden><![CDATA[0]]></Garden>\n";
            print "<Cost><![CDATA[".$row[price]."]]></Cost>\n";
            print "<Currency><![CDATA[EUR]]></Currency>\n";
        
            print "</Property>\n";
            
        }
masoko is offline
Reply With Quote
View Public Profile Visit masoko's homepage!
 
Old 09-10-2007, 11:25 PM Re: NEED Help in saving data into .xls file
Skilled Talker

Posts: 65
Trades: 0
well thanks for the reply and i still trying on it as the php is a total new enviroment for me. i will try the solution posted.
leolim is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to NEED Help in saving data into .xls file
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34287 seconds with 12 queries