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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <?php
session_start();
require_once('includes/application_top.php');
/** Error reporting */
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
$query_excel = 'select c.customers_dob as birthdate, c.customers_fax as fax, c.customers_gender as gender, c.customers_firstname as firstname, c.customers_lastname as lastname, ab.entry_company as company, c.customers_email_address as mail, ab.entry_street_address as address1, ab.entry_suburb as address2, ab.entry_postcode as cpostal, ab.entry_city as city, co.countries_name as country, co.countries_id countries_id, c.customers_telephone as telephone from ' . TABLE_CUSTOMERS . ' c INNER JOIN ' . TABLE_ADDRESS_BOOK . ' ab on c.customers_id = ab.customers_id INNER JOIN ' . TABLE_COUNTRIES . ' co on ab.entry_country_id = co.countries_id where c.customers_id IN ' . $_SESSION['prenom'] . ' group by c.customers_id order by lastname ,firstname ASC ';
$client_array_excel = tep_db_query($query_excel);
$nb_result = tep_db_num_rows($client_array_excel);
/** PHPExcel */
require_once 'includes/classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Email')
->setCellValue('B1', 'SalutationID')
->setCellValue('C1', 'FirstName')
->setCellValue('D1', 'LastName')
->setCellValue('E1', 'Company')
->setCellValue('F1', 'Address 1')
->setCellValue('G1', 'Address 2')
->setCellValue('H1', 'Address 3')
->setCellValue('I1', 'ZipCode')
->setCellValue('J1', 'City')
->setCellValue('K1', 'CountryID')
->setCellValue('L1', 'Phone')
->setCellValue('M1', 'Fax')
->setCellValue('N1', 'Mobil Phone')
->setCellValue('O1', 'MsgFormatId')
->setCellValue('P1', 'SaleMgt')
->setCellValue('Q1', 'Birthdate')
->setCellValue('r1', 'CustomDate1');
// Miscellaneous glyphs, UTF-8
$i=2;
while( $client_excel = tep_db_fetch_array($client_array_excel))
{
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i , $client_excel['mail']);
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i , '1');
$objPHPExcel->getActiveSheet()->setCellValue('C' . $i , $client_excel['firstname']);
$objPHPExcel->getActiveSheet()->setCellValue('D' . $i , $client_excel['lastname']);
$i++;
}
// Rename sheet
//$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="test.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
?> |
Partager