473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

spreadsheet

I'm trying to print out mysql table data into excel. I found code on
web but it outputs everything into one cell instead of spacing out on
spreadsheet. I have no clue how to fix.

<?PHP
$result = mysql_query("SELECT * FROM $db_table3");
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($result, $i)."\t";
}

while($row = mysql_fetch_row($result)){
$line = '';
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}
else
{
# important to escape any quotes to preserve them in the data.
# needed to encapsulate data in quotes because some data might be
multi line.
# the good news is that numbers remain numbers in Excel even though
quoted.
$value = $value . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
# this line is needed because returns embedded in the data have "\r"
# and this looks like a "box character" in Excel
$data = str_replace("\r", "", $data);
# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == "") {
$data = "\nno matching records found\n";
}
# This line will stream the file to the user rather than spray it
across the screen
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");
echo $header."\n".$data;
?>

Jul 4 '07 #1
2 1152
On Wed, 04 Jul 2007 01:21:05 -0000, up2trouble
<ly**********@gmail.comwrote:
>I'm trying to print out mysql table data into excel. I found code on
web but it outputs everything into one cell instead of spacing out on
spreadsheet. I have no clue how to fix.
Output it into an HTML table as if you were displaying it on a
webpage.
You can even do pretty colours!

<http://www.evolt.org/article/Using_MySQL_and_PHP_to_Present_Excel_Spreadsheets/20/26896/>
helped me...
--
Locate your Mobile phone: <http://www.bizorg.co.uk/news.html>
Great gifts: <http://www.ThisBritain.com/ASOS_popup.html>
Jul 4 '07 #2
On 4 jul, 03:06, David Quinton
<usenet_2005D_em...@REMOVETHISBITbizorg.co.ukwrote :
On Wed, 04 Jul 2007 01:21:05 -0000, up2trouble

<lynettesm...@gmail.comwrote:
I'm trying to print out mysql table data into excel. I found code on
web but it outputs everything into one cell instead of spacing out on
spreadsheet. I have no clue how to fix.

Output it into an HTML table as if you were displaying it on a
webpage.
You can even do pretty colours!

<http://www.evolt.org/article/Using_MySQL_and_PHP_to_Present_Excel_Spr...>
helped me...
--
Locate your Mobile phone: <http://www.bizorg.co.uk/news.html>
Great gifts: <http://www.ThisBritain.com/ASOS_popup.html>
You could try saving your file as txt file and then import it from
Excel, in that way you'll make sure that the content that you are
generating is ok and you should focus in find the correct headers for
the file.

Jul 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Phil Powell | last post by:
What would one best recommend to parse an existing Excel spreadsheet (was done in Excel 97 or 2000 not sure to be honest)? I am looking for the most practical way of parsing an existing...
2
by: quadric | last post by:
Hi, I have an application that requires that Python initiate and mediate a live and iterative conversation between an external application (in which Python is embedded) and an external Excel...
2
by: Fabio | last post by:
Hello, there's a module called Spreadsheet::WriteExcel. It allows me to create a new worksheet and edit its cells: my $workbook = Spreadsheet::WriteExcel->new('my.xls'); my $worksheet =...
2
by: Colleyville Alan | last post by:
I have been working on an application that queries data from Access, loads it into an array, and then writes it to an Excel spreadsheet. I use the array approach to have fine control over spacing,...
3
by: Brooke | last post by:
I am new to ASP.NET, but have been programming for about 14 years (C# about 2 years). My manager asked me to develop a web application that would allow employees to view a spreadsheet that is used...
2
TMS
by: TMS | last post by:
The spreadsheet is due today and i needed help with the last two parts of the spreadsheet, so I went to my teacher. My spreedsheet was working BETTER before he made me change it. Now it prints a...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
1
by: platski | last post by:
I have learned a bit about vb recently and have been using it for my job, I still have questions and dont know how to do many things yet. I appreciate your time and efforts and hopefully I can...
8
by: Perl Beginner | last post by:
I am using Win32. I have created an excel spreadsheet, formatted the columns and rows, and would like to write to the cells…all of this using Spreadsheet::WriteExcel. My issue is, my script is very...
0
by: dutsnekcirf | last post by:
Okay, I think this one is a really hard one for yous geniuses out there. I'm going to try my best to explain in as much detail as I can. And for the most part I just want to know if I'm doing this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.