• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
phpexcel problem

#1
[eluser]Damjan[/eluser]
Hi,

i am new to Codeigniter. I use PHPExcel library to make excel file, now I want to download file through browser. I have made excel file, and following code try to execute download:

$this->load->library('PHPExcel');
$this->load->library('PHPExcel/IOFactory');
$this->load->library('PHPExcel/Writer/Excel2007');
.
.
.
$objPHPExcel->getActiveSheet()->setTitle('Simple');

$objWrite = IOFactory::createWriter($objPHPExcel,'Excel2007'); // HERE ERROR HAPPENING (I think Smile)

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="30template.xlsx"');
header('Cache-Control: max-age=0');


$objWrite->save('php://output');

BUT error display:

Fatal error: Cannot redeclare class Excel2007 in C:\Users\Damjan\Dropbox\Projects\www\PhoneNumber\application\libraries\PHPExcel\Writer\Excel2007.php on line 36


#2
[eluser]MRosenello[/eluser]
Can you post the content of Excel2007.php? It looks like you are declaring the same class twice in there. You can only declare a class once.

-Mike

#3
[eluser]CodeIgniteMe[/eluser]
how are you including your Excel2007 library? where is your web root path?

#4
[eluser]Damjan[/eluser]
[quote author="MRosenello" date="1340214923"]Can you post the content of Excel2007.php? It looks like you are declaring the same class twice in there. You can only declare a class once.

-Mike[/quote]

I don't make changes to file Excel2007.php except renaming class name to file name, PHPExcel_Writer_Excel2007 to Excel2007. Excel2007 have about 500 line of code. 36. line of code is:

class Excel2007 implements PHPExcel_Writer_IWriter

[quote author="CodeIgniteMe" date=""]how are you including your Excel2007 library? where is your web root path?[/quote]

I have copy Excel2007 to application/libraries/PHPExcel/Writer folder and in my application
$this->load->library(‘PHPExcel/Writer/Excel2007’);

#5
[eluser]CodeIgniteMe[/eluser]
[quote author="Damjan" date="1340264639"][quote author="MRosenello" date="1340214923"]Can you post the content of Excel2007.php? It looks like you are declaring the same class twice in there. You can only declare a class once.

-Mike[/quote]

I don't make changes to file Excel2007.php except renaming class name to file name, PHPExcel_Writer_Excel2007 to Excel2007. Excel2007 have about 500 line of code. 36. line of code is:

class Excel2007 implements PHPExcel_Writer_IWriter

[quote author="CodeIgniteMe" date=""]how are you including your Excel2007 library? where is your web root path?[/quote]

I have copy Excel2007 to application/libraries/PHPExcel/Writer folder and in my application
$this->load->library(‘PHPExcel/Writer/Excel2007’);[/quote]

OK., so all you will have to do is change the name of your new class. maybe add underscore on it

class Excel_2007

#6
[eluser]Damjan[/eluser]
Now I've got following error:

Fatal error: Class 'PHPExcel_Writer_Excel2007' not found in C:\Users\Damjan\Dropbox\Projects\www\PhoneNumber\application\libraries\PHPExcel\IOFactory.php on line 141

IOFactory.php:

public static function createWriter(PHPExcel $phpExcel, $writerType = '') {
// Search type
$searchType = 'IWriter';

// Include class
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $writerType, $searchLocation['class']);
$classFile = str_replace('{0}', $writerType, $searchLocation['path']);

$instance = new $className($phpExcel); // line 141
if ($instance !== NULL) {
return $instance;
}
}
}

// Nothing found...
throw new Exception("No $searchType found for type $writerType");
}

#7
[eluser]CodeIgniteMe[/eluser]
what is the name of your new Excel2007 class?
I think you should both name your class and file to PHPExcel_Writer_Excel2007 and PHPExcel_Writer_Excel2007.php respectively
there might be some dependencies to that class in you excel library

#8
[eluser]Damjan[/eluser]
It's ok, working now. Thanks.

#9
[eluser]CodeIgniteMe[/eluser]
Great! good to know


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.