Advertisement
johncarlson21

john php excel 2

Sep 25th, 2013
75
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('A1', 'Date')
  71.             ->setCellValue('B1', 'Salutation')
  72.             ->setCellValue('C1', 'Last Name')
  73.             ->setCellValue('D1', 'First Name')
  74.             ->setCellValue('E1', 'Email')
  75.             ->setCellValue('F1', 'Phone')
  76.             ->setCellValue('G1', 'Loan Type')
  77.             ->setCellValue('H1', 'How Long')
  78.             ->setCellValue('I1', 'First Time')
  79.             ->setCellValue('J1', 'Veteran')
  80.             ->setCellValue('K1', 'Prop Zip Code')
  81.             ->setCellValue('L1', 'Prop Type')
  82.             ->setCellValue('M1', 'Prop Use')
  83.             ->setCellValue('N1', 'When')
  84.             ->setCellValue('O1', 'Afford')
  85.             ->setCellValue('P1', 'Saved')
  86.             ->setCellValue('Q1', 'Income')
  87.             ->setCellValue('R1', 'Credit Score')
  88.             ->setCellValue('S1', 'On Time')
  89.             ->setCellValue('T1', 'Bankruptcies')
  90.             ->setCellValue('U1', 'Forclosures')
  91.             ->setCellValue('V1', 'Judgements');
  92.  
  93. while($row = mysql_fetch_array($result)){
  94.    
  95.     $data = array(
  96.         ' ',// will be an empty because there is no column 0
  97.         $row['sub_date'],
  98.         $row['salutation'],
  99.         $row['l_name'],
  100.         $row['f_name'],
  101.         $row['email'],
  102.         $row['phone'],
  103.         $row['loan_type'],
  104.         $row['how_long'],
  105.         $row['first_time'],
  106.         $row['veteran'],
  107.         $row['p_zip'],
  108.         $row['p_type'],
  109.         $row['p_use'],
  110.         $row['when'],
  111.         $row['afford'],
  112.         $row['saved'],
  113.         $row['income'],
  114.         $row['credit_score'],
  115.         $row['on_time'],
  116.         $row['bankruptcies'],
  117.         $row['foreclosures'],
  118.         $row['judgments'],
  119.         );
  120.        
  121.         $alpha = array(
  122.         '',
  123.         'A',
  124.         'B',
  125.         'C',
  126.         'D',
  127.         'E',
  128.         'F',
  129.         'G',
  130.         'H',
  131.         'I',
  132.         'J',
  133.         'K',
  134.         'L',
  135.         'M',
  136.         'N',
  137.         'O',
  138.         'P',
  139.         'Q',
  140.         'R',
  141.         'S',
  142.         'T',
  143.         'U',
  144.         'V',
  145.         );
  146.  
  147. //Loop to put together
  148. for($i=0; $i<count($data); $i++){
  149.    
  150.     if ($i > 0) {
  151.         $objPHPExcel->setActiveSheetIndex(0)->setCellValue($alpha[$i].$c, $data[$i]);
  152.     }// end if
  153.    
  154. }//end for loop
  155.  
  156. // increment counter for the row
  157. $c++;
  158.  
  159. }//end while   
  160.  
  161. // Rename worksheet
  162. $objPHPExcel->getActiveSheet()->setTitle('Leads');
  163.  
  164.  
  165. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  166. $objPHPExcel->setActiveSheetIndex(0);
  167.  
  168.  
  169. // Redirect output to a client’s web browser (Excel2007)
  170. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  171. header('Content-Disposition: attachment;filename="01simple.xlsx"');
  172. header('Cache-Control: max-age=0');
  173.  
  174. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  175. $objWriter->save('php://output');
  176. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement