Advertisement
johncarlson21

john php excel

Sep 25th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  42. if (PHP_SAPI == 'cli')
  43.     die('This example should only be run from a Web Browser');
  44.  
  45. /** Include PHPExcel */
  46. require_once 'Classes/PHPExcel.php';
  47.  
  48.  
  49. // Create new PHPExcel object
  50. $objPHPExcel = new PHPExcel();
  51.  
  52. // Set document properties
  53. $objPHPExcel->getProperties()->setCreator("Teresa Romano")
  54.                              ->setLastModifiedBy("Teresa Romano")
  55.                              ->setTitle("Office 2007 XLSX Test Document")
  56.                              ->setSubject("Office 2007 XLSX Test Document")
  57.                              ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  58.                              ->setKeywords("office 2007 openxml php")
  59.                              ->setCategory("Test result file");
  60.  
  61.  
  62. // Add some data
  63.  
  64. $c=2;
  65.  
  66. $sql = "SELECT * from `leads` WHERE (`sub_date` BETWEEN '$date1' AND '$date2')";
  67. $result = mysql_query($sql);
  68.  
  69. $objPHPExcel->setActiveSheetIndex(0)
  70.             ->setCellValue('')
  71.             ->setCellValue('A1', 'Date')
  72.             ->setCellValue('B1', 'Salutation')
  73.             ->setCellValue('C1', 'Last Name')
  74.             ->setCellValue('D1', 'First Name')
  75.             ->setCellValue('E1', 'Email')
  76.             ->setCellValue('F1', 'Phone')
  77.             ->setCellValue('G1', 'Loan Type')
  78.             ->setCellValue('H1', 'How Long')
  79.             ->setCellValue('I1', 'First Time')
  80.             ->setCellValue('J1', 'Veteran')
  81.             ->setCellValue('K1', 'Prop Zip Code')
  82.             ->setCellValue('L1', 'Prop Type')
  83.             ->setCellValue('M1', 'Prop Use')
  84.             ->setCellValue('N1', 'When')
  85.             ->setCellValue('O1', 'Afford')
  86.             ->setCellValue('P1', 'Saved')
  87.             ->setCellValue('Q1', 'Income')
  88.             ->setCellValue('R1', 'Credit Score')
  89.             ->setCellValue('S1', 'On Time')
  90.             ->setCellValue('T1', 'Bankruptcies')
  91.             ->setCellValue('U1', 'Forclosures')
  92.             ->setCellValue('V1', 'Judgements');
  93.  
  94. while($row = mysql_fetch_array($result)){
  95.    
  96.     $data = array(
  97.         ' ',// will be an empty because there is no column 0
  98.         $row['sub_date'],
  99.         $row['salutation'],
  100.         $row['l_name'],
  101.         $row['f_name'],
  102.         $row['email'],
  103.         $row['phone'],
  104.         $row['loan_type'],
  105.         $row['how_long'],
  106.         $row['first_time'],
  107.         $row['veteran'],
  108.         $row['p_zip'],
  109.         $row['p_type'],
  110.         $row['p_use'],
  111.         $row['when'],
  112.         $row['afford'],
  113.         $row['saved'],
  114.         $row['income'],
  115.         $row['credit_score'],
  116.         $row['on_time'],
  117.         $row['bankruptcies'],
  118.         $row['foreclosures'],
  119.         $row['judgments'],
  120.         );
  121.        
  122.         $alpha = array(
  123.         '',
  124.         'A',
  125.         'B',
  126.         'C',
  127.         'D',
  128.         'E',
  129.         'F',
  130.         'G',
  131.         'H',
  132.         'I',
  133.         'J',
  134.         'K',
  135.         'L',
  136.         'M',
  137.         'N',
  138.         'O',
  139.         'P',
  140.         'Q',
  141.         'R',
  142.         'S',
  143.         'T',
  144.         'U',
  145.         'V',
  146.         );
  147.  
  148. //Loop to put together
  149. for($i=0; $i<count($data); $i++){
  150.    
  151.     if ($i > 0) {
  152.         $objPHPExcel->setActiveSheetIndex(0)->setCellValue($alpha[$i].$c, $data[$i]);
  153.     }// end if
  154.    
  155. }//end for loop
  156.  
  157. // increment counter for the row
  158. $c++;
  159.  
  160. }//end while   
  161.  
  162. // Rename worksheet
  163. $objPHPExcel->getActiveSheet()->setTitle('Leads');
  164.  
  165.  
  166. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  167. $objPHPExcel->setActiveSheetIndex(0);
  168.  
  169.  
  170. // Redirect output to a client’s web browser (Excel2007)
  171. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  172. header('Content-Disposition: attachment;filename="01simple.xlsx"');
  173. header('Cache-Control: max-age=0');
  174.  
  175. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  176. $objWriter->save('php://output');
  177. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement