Transferring data from MYSQL database to excel

I wish to transfer data from a MySQL database to excel in a particular format:
As if first field is name and the first row has name as “sagar” Then excel sheet has to be as follows
C1- s
D1-a
E1-g
F1-a
G1-r
Can this be done using php

Yes, you can do this. The easiest way is to generate CSV file or HTML file and output it with headers:
example for HTML:[php] header(“Content-type: application/vnd.ms-excel”);
header(“Content-Disposition: attachment; filename=myfile.xls”);
[/php]
example for CSV:[php] header(“Content-type: application/csv”);
header(“Content-Disposition:inline; filename=myfile.csv”);
[/php]
In both examples above, you start output data after headers, and Excel will recognize both formats. When using HTML you can also style cell colors, borders etc.
In your task, you will first need to determine size of longest word in field ‘name’ in your query. This size will be number of columns in the HTML table (for HTML) or number of comma delimited fields (for CSV).

If i want to have output in discrete format like if first row has “sagar” output in excel file should be like-
A1-s
b3-a
c7-g
d5-a
f1-r

Well, you need to build a matrix first (two dimensional array), then generate CSV/HTML file as described above. What is your question?

Sponsor our Newsletter | Privacy Policy | Terms of Service