Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

need help with PhpExcel php to excel error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

need help with PhpExcel php to excel error

Postby GlendonPhilipp » Tue Aug 12, 2014 12:17 am

hello i want to use the 10autofilter.php from phpexcel, to our program. but i want a code that will print on excel the datas on our database since its only prints row 1 and doesnt print all data on our mysql please help me you can see the code it only output 1 row :( please help

please also see the code here
Code: Select all
<?php
error_reporting(0);
session_start();
include("dbconnect.php");
/**
 * PHPExcel
 *
 * Copyright (C) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt   LGPL
 * @version    1.8.0, 2014-03-02
 */

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

date_default_timezone_set('Europe/London');

/** Include PHPExcel */
require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';

// Create new PHPExcel object
echo date('H:i:s').' Create new PHPExcel object'.EOL;
$objPHPExcel = new PHPExcel();

// Set document properties
echo date('H:i:s').' Set document properties'.EOL;
$objPHPExcel->getProperties()->setCreator('Maarten Balliauw')
                      ->setLastModifiedBy('Maarten Balliauw')
                      ->setTitle('PHPExcel test Document')
                      ->setSubject('PHPExcel test Document')
                      ->setDescription('test document for PHPExcel, generated using PHP classes.')
                      ->setKeywords('office PHPExcel php')
                      ->setCategory('test result file');

// Create the worksheet
echo date('H:i:s').' Add data'.EOL;
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Serviceid')
                              ->setCellValue('B1', 'Servicename')
                              ->setCellValue('C1', 'Email Address')
                              ->setCellValue('D1', 'Contact Person')
                        ->setCellValue('E1', 'Year Assistance Received')
                         ->setCellValue('F1', 'Year Established');
                      
 $res = mysql_query("select * from services");
$row = mysql_num_rows($res);
for($i=0;$i<$row;$i++){
$serviceid  = mysql_result($res,$i,"serviceid");
$servicename  = mysql_result($res,$i,"servicename");
$contactemail  = mysql_result($res,$i,"contactemail");
$charge  = mysql_result($res,$i,"charge");
$contactlastname  = mysql_result($res,$i,"contactlastname");
$contactmiddlename  = mysql_result($res,$i,"contactmiddlename");
$yearassistancereceived  = mysql_result($res,$i,"yearassistancereceived");
$yearestablished  = mysql_result($res,$i,"yearestablished");

$dataArray = array(array($serviceid,$servicename ,   $contactemail,$charge." ".$contactmiddlename." ".$contactlastname, $yearassistancereceived, $yearestablished)
                 
                  );
$objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A2');

// Set title row bold
echo date('H:i:s').' Set title row bold'.EOL;
$objPHPExcel->getActiveSheet()->getStyle('A1:D1')->getFont()->setBold(true);

// Set autofilter
echo date('H:i:s').' Set autofilter'.EOL;
// Always include the complete filter range!
// Excel does support setting only the caption
// row, but that's not a best practise...
$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension());

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;

echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;


// Save Excel 95 file
echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;

echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;


// Echo memory peak usage
echo date('H:i:s').' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB'.EOL;

// Echo done
echo date('H:i:s').' Done writing files'.EOL;
echo 'Files have been created in ' , getcwd() , EOL;
}
Attachments
untitled2.JPG
this is the output
untitled2.JPG (24.74 KiB) Viewed 43 times
untitled.JPG
this is the error i get but it executes output
untitled.JPG (49.25 KiB) Viewed 43 times
GlendonPhilipp
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Feb 26, 2014 5:11 am

Return to PHP coding => General

Who is online

Users browsing this forum: dendonpaul, Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.