PHP Classes

PHP MySQL XLSX Export: Export MySQL table records to Excel XML format

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (9)   Blog (1)    
Ratings Unique User Downloads Download Rankings
StarStarStar 46%Total: 2,575 All time: 1,484 This week: 455Up
Version License PHP version Categories
mysql-xlsx-export 1GNU General Publi...4.0XML, Databases
Description 

Author

This class can export MySQL table records to Excel XML format.

It can execute a query to retrieve data from a given MySQL database table and generates an Excel file in the XLSX format with the retrieved data.

The class can either query all fields of a given table, just a few specific fields of the table and execute a given query.

The titles of the generated Excel spreadsheet columns are configurable.

Picture of Gianluca Zanferrari
  Performance   Level  
Name: Gianluca Zanferrari <contact>
Classes: 19 packages by
Country: The Netherlands The Netherlands
Age: 57
All time rank: 1674 in The Netherlands The Netherlands
Week rank: 264 Down7 in The Netherlands The Netherlands Down
Innovation award
Innovation award
Nominee: 5x

Example

<?php
/*
* Do not forget to set the right credentials in the class for the mysql connection
* modify the queries here below.
*/

include('class.mysql2xls_xml.php');

$xls_xml = new excel_xml;

/*
* short query: select all fields from table
*/
$xls_xml->short_query('dbase_name','table_name');
$xls_xml->save_as('output_short.xml');

$xls_xml = new excel_xml;

/*
* short query: select field_1 ans field_2 from table, orders by field_1 and limit 2 records
*/
$xls_xml->short_query('dbase_name','table_name', array('field_1','field_2'), ' ORDER BY field_1 LIMIT 2');
$xls_xml->save_as('output_short_extended.xml');

$xls_xml = new excel_xml;

/*
* short query: select all fields from table where field_1 > 0 and field_1 < 100, orders by field_1 and limit 1 record
* this method can be used for more complex queries with joins and so on...
*/
$xls_xml->long_query('dbase_name','SELECT * FROM table_name WHERE field_1 > 0 AND field_1 < 100 ORDER BY field_1 LIMIT 1');
$xls_xml->save_as('output_long.xml');

/*
* send the output to browser and triggers the office software. Tested with MS Office 2007 and libre office 3.6.2.2
*/
$xls_xml->to_excel('output_to_browser.xml');
?>


  Files folder image Files  
File Role Description
Plain text file class.mysql2xls_xml.php Class class itself
Accessible without login Plain text file example.php Example example
Accessible without login Plain text file template.xml Data template

 Version Control Unique User Downloads Download Rankings  
 0%
Total:2,575
This week:0
All time:1,484
This week:455Up
User Ratings User Comments (5)
 All time
Utility:66%StarStarStarStar
Consistency:70%StarStarStarStar
Documentation:-
Examples:62%StarStarStarStar
Tests:-
Videos:-
Overall:46%StarStarStar
Rank:3154
 
teste
6 years ago (Wesley Braga)
27%StarStar
teste
6 years ago (Wesley Braga)
27%StarStar
the file are incompleat if you not place the "select the data...
10 years ago (Gabby Abergel)
32%StarStar
quite a nice program.
11 years ago (ehos olivia)
65%StarStarStarStar
This is not true XLSX export.
11 years ago (Artur Muszynski)
27%StarStar