| |||||||||||
| |||||||||||
Downloading data for use in Excel (from PHP / MySQL)
Requirement: To allow a visitor to your web site to click on a link that downloads data from the server into a Microsoft Excel spreadhseet.
Solutions - I'm going to offer you two: a) To send the output as a text file - delimited by tabs between columns, and with new lines for each new line. Add appropriate content type headers (such as octet-stream) to save the file to local disc rather than displaying it, and pass back a file name with a .xls extension to provide direction to the operating system as to how to handle the file. In most environments, Excel will do the import for you. I have written an example that does this, grabbing data from one of our MySQL databases that logs web site traffic Run the example or see the source of the example or b) To send the output as an HTML table, in which case Excel will interpret the rows and columns of the tables as its data cells. I've written an example of this too - using an alternative content type to show the flexibility that's available. And I have also put a formula into one of the cells so that you can get excel to fill in the extra boxes for you. This example just populates a spread sheet with some numbers as a "proof of concept" but it's still a series of useful pointers, I hope. You can Run the example or see the source code You'll notice in the source code of both examples that I've added in extra headers in my response to ensure that the browser doesn't cache the results - that's done to make sure that you get a fresh download each time you run the scripts, rather than being given stored old data. (written 2008-01-25 07:24:03) Associated topics are indexed under H112 - PHP - Further Web Page and Network HandlingS156 - Interfacing Applications to MySQL Databases
Some other Articles
Paging Martin Noke, who petitions for more trains from Trowbridge to SwindonEvening drive across the roof of Wiltshire Terms and Conditions - Hotel, England - plain English Flipping images on your web page Downloading data for use in Excel (from PHP / MySQL) Python - formatting objects Pictures you can use - for free - from our library Keeping staff up to date on hotel room status Autovivification - the magic appearance of variables in Perl Perl, PHP or Python? No - Perl AND PHP AND Python! 1780 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||