Use SimpleExcel to export xls. I wrote an article a few days ago and used the php-excel-reader class to import the excel content. By the way, I used simpleexcel to export some excel files, which is a simple export xls class, very useful! S. I wrote an article a few days ago and used the php-excel-reader class to import the excel content. By the way, I used the simple excel class to export the xls content, very useful!
Simple excel source code is as follows:
The code is as follows:
/**
* Simple excel generating from PHP5
*
* @ Package Utilities
* @ License http://www.opensource.org/licenses/mit-license.php
* @ Author Oliver Schwarz
* @ Version 1.0
*/
Class Excel_Xml
{
Private $ header =" \ N ";
Private $ footer =" ";
Private $ lines = array ();
Private $ sEncoding;
Private $ bConvertTypes;
Private $ sWorksheetTitle;
Public function _ construct ($ sEncoding = 'utf-8', $ bConvertTypes = false, $ sWorksheetTitle = 'table1 ')
{
$ This-> bConvertTypes = $ bConvertTypes;
$ This-> setEncoding ($ sEncoding );
$ This-> setWorksheetTitle ($ sWorksheetTitle );
}
Public function setEncoding ($ sEncoding)
{
$ This-> sEncoding = $ sEncoding;
}
Public function setWorksheetTitle ($ title)
{
$ Title = preg_replace ("/[\\|:\/ | \? | \ * | \ [| \]/"," ", $ Title );
$ Title = substr ($ title, 0, 31 );
$ This-> sWorksheetTitle = $ title;
}
Private function addRow ($ array)
{
$ Cells = "";
Foreach ($ array as $ k => $ v ):
$ Type = 'string ';
If ($ this-> bConvertTypes === true & is_numeric ($ v )):
$ Type = 'number ';
Endif;
$ V = htmlentities ($ v, ENT_COMPAT, $ this-> sEncoding );
$ Cells. =" ". $ V ." \ N ";
Endforeach;
$ This-> lines [] =" \ N ". $ cells ." \ N ";
}
Public function addArray ($ array)
{
Foreach ($ array as $ k => $ v)
$ This-> addRow ($ v );
}
Public function generateXML ($ filename = 'Excel-export ')
{
$ Filename = preg_replace ('/[^ aA-zZ0-9 \ _ \-]/', '', $ filename );
Header ("Content-Type: application/vnd. ms-excel; charset =". $ this-> sEncoding );
Header ("Content-Disposition: inline; filename = \" ". $ filename.". xls \"");
Echo stripslashes (sprintf ($ this-> header, $ this-> sEncoding ));
Echo "\ n SWorksheetTitle. "\"> \ n
\ N ";Foreach ($ this-> lines as $ line)Echo $ line;Echo"
\ N\ N ";
Echo $ this-> footer;
}
}
?>
The use case of php is as follows:
The code is as follows:
/**
* @ Author mckee
* @ Blog www.phpddt.com
*/
Require_once 'Excel. class. php ';
$ Xls = new Excel_Xml ('utf-8', false, 'test ');
$ Data = array (
1 => array ('name', 'address '),
2 => array ('php point pass', 'www .phpddt.com '),
3 => array ('Baidu ', 'www .baidu.com ')
);
$ Xls-> addArray ($ data );
$ Xls-> generateXML ('name4test ');
?>
The export result is as follows:
Export excel, a simple export xls class, very easy to use! S...