Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc
Magento UK
PHP Cached Download Function

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

Archive for the 'excel' Category

PHP : Dead Easy Excel Export

Wednesday, July 9th, 2008

Some people like their excel files. For people who want their data exported in an excel format checkout this chunk of code. It's really easy :-)

First of all you need to download this php excel class

Now try this code:

PLAIN TEXT
PHP:
  1. $query = mysql_query("select * from table");
  2. while($q = mysql_fetch_assoc($query)){
  3.     $output[] = $q;
  4. }
  5. require_once "excel.php";
  6. $export_file = "xlsfile://export.xls";
  7. $fp = fopen($export_file, "wb");
  8. if (!is_resource($fp))
  9. {
  10.     die("Cannot open $export_file");
  11. }
  12. fwrite($fp, serialize($output));
  13. fclose($fp);
  14. header ("Content-Type: application/x-msexcel");
  15. header ("Content-Disposition: attachment; filename=\"exports.xls\"" );
  16. readfile("xlsfile://export.xls");
  17. exit;

That's got to be the easiest thing you have ever done in PHP. Thanks goes to the excellent PHP Classes site.

Here is some further reading:
PHP Excel Formula Parser
PHP Excel Export class
Export data directly to Excel by configuring the MIME Type Profile Option
Power your PHP Business Logic with Excel
Reading/Parsing Excel Spreadsheet using PHP

Posted in excel, php | 1 Comment »

  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • Freelance osCommerce UK
    • Online Backend System
    • Populating osCommerce and other Ecommerce Platforms
    • MySQL Add Column if Not Exists - PHP Function
    • HP Printer on Ubuntu
    • Purashop : SEO Services
    • Ultimate osCommerce Checkout - Fast and Friendly
    • osCommerce Contribution Released: Server Migration Synchronisation
    • Favourite Firefox Extensions
    • Speeding Up osCommerce

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design