<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');
/** Include PHPExcel */
require_once 'class/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("duchengjiu")
->setLastModifiedBy("duchengjiu")
->setTitle("Office 2007 XLSX userTable")
->setSubject("Office 2007 XLSX userTable")
->setDescription("Test userTable for Office 2007 XLSX.")
->setKeywords("office 2007")
->setCategory("userTable");
mysql_connect('localhost','root','root');
mysql_select_db('test');
$result = mysql_query("select * from user");
$i = 1;
while(list($id, $username, $password) = mysql_fetch_row($result)){
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$i, $id)
->setCellValue('B'.$i, $username)
->setCellValue('C'.$i, $password);
$i++;
}
$objPHPExcel->getActiveSheet(0)->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>