Advertisement
Guest User

download

a guest
Sep 25th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.34 KB | None | 0 0
  1. <?php
  2. require('authenticate.php');
  3. require('config.php');
  4. ?>
  5.  
  6. <?php
  7. /**
  8.  * PHPExcel
  9.  *
  10.  * Copyright (C) 2006 - 2013 PHPExcel
  11.  *
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Lesser General Public
  14.  * License as published by the Free Software Foundation; either
  15.  * version 2.1 of the License, or (at your option) any later version.
  16.  *
  17.  * This library is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * Lesser General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU Lesser General Public
  23.  * License along with this library; if not, write to the Free Software
  24.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  25.  *
  26.  * @category   PHPExcel
  27.  * @package    PHPExcel
  28.  * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  29.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  30.  * @version    1.7.9, 2013-06-02
  31.  */
  32.  
  33. //Get the id from the previous page
  34. $date1=$_GET['date1'];
  35. $date2=$_GET['date2'];
  36.  
  37. /** Error reporting */
  38. error_reporting(E_ALL);
  39. ini_set('display_errors', TRUE);
  40. ini_set('display_startup_errors', TRUE);
  41. date_default_timezone_set('Europe/London');
  42.  
  43. if (PHP_SAPI == 'cli')
  44.     die('This example should only be run from a Web Browser');
  45.  
  46. /** Include PHPExcel */
  47. require_once 'Classes/PHPExcel.php';
  48.  
  49.  
  50. // Create new PHPExcel object
  51. $objPHPExcel = new PHPExcel();
  52.  
  53. // Set document properties
  54. $objPHPExcel->getProperties()->setCreator("Teresa Romano")
  55.                              ->setLastModifiedBy("Teresa Romano")
  56.                              ->setTitle("Office 2007 XLSX Test Document")
  57.                              ->setSubject("Office 2007 XLSX Test Document")
  58.                              ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  59.                              ->setKeywords("office 2007 openxml php")
  60.                              ->setCategory("Test result file");
  61.  
  62.  
  63. // Add some data
  64.  
  65. $c=2;
  66.  
  67. $sql = "SELECT * from `leads` WHERE (`sub_date` BETWEEN '$date1' AND '$date2')";
  68. $result = mysql_query($sql);
  69.  
  70. $objPHPExcel->setActiveSheetIndex(0)
  71.             ->setCellValue('')
  72.             ->setCellValue('A1', 'Date')
  73.             ->setCellValue('B1', 'Salutation')
  74.             ->setCellValue('C1', 'Last Name')
  75.             ->setCellValue('D1', 'First Name')
  76.             ->setCellValue('E1', 'Email')
  77.             ->setCellValue('F1', 'Phone')
  78.             ->setCellValue('G1', 'Loan Type')
  79.             ->setCellValue('H1', 'How Long')
  80.             ->setCellValue('I1', 'First Time')
  81.             ->setCellValue('J1', 'Veteran')
  82.             ->setCellValue('K1', 'Prop Zip Code')
  83.             ->setCellValue('L1', 'Prop Type')
  84.             ->setCellValue('M1', 'Prop Use')
  85.             ->setCellValue('N1', 'When')
  86.             ->setCellValue('O1', 'Afford')
  87.             ->setCellValue('P1', 'Saved')
  88.             ->setCellValue('Q1', 'Income')
  89.             ->setCellValue('R1', 'Credit Score')
  90.             ->setCellValue('S1', 'On Time')
  91.             ->setCellValue('T1', 'Bankruptcies')
  92.             ->setCellValue('U1', 'Forclosures')
  93.             ->setCellValue('V1', 'Judgements');
  94.  
  95. while($row = mysql_fetch_array($result)){
  96.    
  97.     $data = array(
  98.         ' ',// will be an empty because there is no column 0
  99.         $row['sub_date'],
  100.         $row['salutation'],
  101.         $row['l_name'],
  102.         $row['f_name'],
  103.         $row['email'],
  104.         $row['phone'],
  105.         $row['loan_type'],
  106.         $row['how_long'],
  107.         $row['first_time'],
  108.         $row['veteran'],
  109.         $row['p_zip'],
  110.         $row['p_type'],
  111.         $row['p_use'],
  112.         $row['when'],
  113.         $row['afford'],
  114.         $row['saved'],
  115.         $row['income'],
  116.         $row['credit_score'],
  117.         $row['on_time'],
  118.         $row['bankruptcies'],
  119.         $row['foreclosures'],
  120.         $row['judgments'],
  121.         );
  122.        
  123.         $alpha = array(
  124.         '',
  125.         'A',
  126.         'B',
  127.         'C',
  128.         'D',
  129.         'E',
  130.         'F',
  131.         'G',
  132.         'H',
  133.         'I',
  134.         'J',
  135.         'K',
  136.         'L',
  137.         'M',
  138.         'N',
  139.         'O',
  140.         'P',
  141.         'Q',
  142.         'R',
  143.         'S',
  144.         'T',
  145.         'U',
  146.         'V',
  147.         );
  148.  
  149. $objPHPExcel->setActiveSheetIndex(0);
  150.  
  151. //Loop to put together
  152. for($i=0; $i<count($data); $i++){
  153.    
  154.     if ($i > 0) {
  155.         $objPHPExcel->setCellValue($alpha[$i].$c, $data[$i]);
  156.     }// end if
  157.    
  158. }//end for loop
  159.  
  160. // increment counter for the row
  161. $c++;
  162.  
  163. }//end while
  164.        
  165.  
  166. // Miscellaneous glyphs, UTF-8
  167. $objPHPExcel->setActiveSheetIndex(0)
  168.             ->setCellValue('A4', 'Miscellaneous glyphs')
  169.             ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
  170.  
  171. // Rename worksheet
  172. $objPHPExcel->getActiveSheet()->setTitle('Leads');
  173.  
  174.  
  175. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  176. $objPHPExcel->setActiveSheetIndex(0);
  177.  
  178.  
  179. // Redirect output to a client’s web browser (Excel5)
  180. header('Content-Type: application/vnd.ms-excel');
  181. header('Content-Disposition: attachment;filename="leadsexport.xls"');
  182. header('Cache-Control: max-age=0');
  183. // If you're serving to IE 9, then the following may be needed
  184. header('Cache-Control: max-age=1');
  185.  
  186. // If you're serving to IE over SSL, then the following may be needed
  187. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  188. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  189. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  190. header ('Pragma: public'); // HTTP/1.0
  191.  
  192. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  193. $objWriter->save('php://output');
  194. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement