Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('authenticate.php');
- require('config.php');
- ?>
- <?php
- /**
- * PHPExcel
- *
- * Copyright (C) 2006 - 2013 PHPExcel
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * @category PHPExcel
- * @package PHPExcel
- * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
- * @version 1.7.9, 2013-06-02
- */
- //Get the id from the previous page
- $date1=$_GET['date1'];
- $date2=$_GET['date2'];
- /** Error reporting */
- 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 'Classes/PHPExcel.php';
- // Create new PHPExcel object
- $objPHPExcel = new PHPExcel();
- // Set document properties
- $objPHPExcel->getProperties()->setCreator("Teresa Romano")
- ->setLastModifiedBy("Teresa Romano")
- ->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
- $c=2;
- $sql = "SELECT * from `leads` WHERE (`sub_date` BETWEEN '$date1' AND '$date2')";
- $result = mysql_query($sql);
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('')
- ->setCellValue('A1', 'Date')
- ->setCellValue('B1', 'Salutation')
- ->setCellValue('C1', 'Last Name')
- ->setCellValue('D1', 'First Name')
- ->setCellValue('E1', 'Email')
- ->setCellValue('F1', 'Phone')
- ->setCellValue('G1', 'Loan Type')
- ->setCellValue('H1', 'How Long')
- ->setCellValue('I1', 'First Time')
- ->setCellValue('J1', 'Veteran')
- ->setCellValue('K1', 'Prop Zip Code')
- ->setCellValue('L1', 'Prop Type')
- ->setCellValue('M1', 'Prop Use')
- ->setCellValue('N1', 'When')
- ->setCellValue('O1', 'Afford')
- ->setCellValue('P1', 'Saved')
- ->setCellValue('Q1', 'Income')
- ->setCellValue('R1', 'Credit Score')
- ->setCellValue('S1', 'On Time')
- ->setCellValue('T1', 'Bankruptcies')
- ->setCellValue('U1', 'Forclosures')
- ->setCellValue('V1', 'Judgements');
- while($row = mysql_fetch_array($result)){
- $data = array(
- ' ',// will be an empty because there is no column 0
- $row['sub_date'],
- $row['salutation'],
- $row['l_name'],
- $row['f_name'],
- $row['email'],
- $row['phone'],
- $row['loan_type'],
- $row['how_long'],
- $row['first_time'],
- $row['veteran'],
- $row['p_zip'],
- $row['p_type'],
- $row['p_use'],
- $row['when'],
- $row['afford'],
- $row['saved'],
- $row['income'],
- $row['credit_score'],
- $row['on_time'],
- $row['bankruptcies'],
- $row['foreclosures'],
- $row['judgments'],
- );
- $alpha = array(
- '',
- 'A',
- 'B',
- 'C',
- 'D',
- 'E',
- 'F',
- 'G',
- 'H',
- 'I',
- 'J',
- 'K',
- 'L',
- 'M',
- 'N',
- 'O',
- 'P',
- 'Q',
- 'R',
- 'S',
- 'T',
- 'U',
- 'V',
- );
- //Loop to put together
- for($i=0; $i<count($data); $i++){
- if ($i > 0) {
- $objPHPExcel->setActiveSheetIndex(0)->setCellValue($alpha[$i].$c, $data[$i]);
- }// end if
- }//end for loop
- // increment counter for the row
- $c++;
- }//end while
- // Rename worksheet
- $objPHPExcel->getActiveSheet()->setTitle('Leads');
- // 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="01simple.xlsx"');
- header('Cache-Control: max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save('php://output');
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement