Error Warning using PHPExcel

Topics: User Forum
Dec 6, 2008 at 6:13 PM
I uploaded PHPExcel to my server and started to put the code into a php echo page that I want users to be able to copy to an Excel form.  I am getting the following error warning when going to that page:

Warning: require_once(PHPExcel/Cell/DataType.php) [function.require-once]: failed to open stream: No such file or directory in /home/pkrbook/public_html/bookkeeper/Classes/PHPExcel/Cell.php on line 30

Fatal error: require_once() [function.require]: Failed opening required 'PHPExcel/Cell/DataType.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:pkrbook/bookkeeper/Classes/') in /home/pkrbook/public_html/bookkeeper/Classes/PHPExcel/Cell.php on line 30

The file metioned is in the folder so what could be wrong?

Mike
Developer
Dec 7, 2008 at 12:17 AM
Could it be your include path? How did you set your include path?
Dec 7, 2008 at 4:38 AM
Here is the include path at the top of the page.

set_include_path(get_include_path() . PATH_SEPARATOR . 'pkrbook/bookkeeper/Classes/');
include('Classes/PHPExcel.php');
include('Classes/PHPExcel/IOFactory.php');

Thanks, Mike
Developer
Dec 7, 2008 at 4:47 AM
Judging from your error message, you would need this instead:

set_include_path(get_include_path() . PATH_SEPARATOR . '/home/pkrbook/public_html/bookkeeper/Classes/');

If it's not working, post back the new error message.
Developer
Dec 7, 2008 at 4:50 AM
I usually do like this, so script can be moved to web server without needed to update include path:

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__)' . '/Classes/');


Dec 7, 2008 at 2:30 PM
Ok the first example worked to get rid of that error.  Now I am getting this error:

<>Fatal error: Call to undefined function fetch_array() in /home/pkrbook/public_html/bookkeeper/cash_tourney_excel.php on line 78</>: Call to undefined function fetch_array() in on line

I will look at this page some more to see if I have something set up wrong.  It is showing my column Titles so i have that much set up right.

Mike
Dec 7, 2008 at 7:09 PM
OK I got rid of the fatal error warnings.  I get my echo print out the way it should be, but below that I get this code:

ÐÏࡱá;þÿ þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ » ÌAB°=¼%r8X"1ÈÿArial1ÈÿArial1ÈÿArial1ÈÿArial1ÈÿArial1ȐArial1ȼCalibri¤Generalàõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À àõÿ €À à €À à ˆÀ à¤ Ì “€ÿ’â8ÿÿÿÿÿÿÿÿÿÿÿÿ€€€€€€€€€ÀÀÀ€€€™™ÿ™3fÿÿÌÌÿÿffÿ€€fÌÌÌÿ€ÿÿÿÿÿÿ€€€€€ÿÌÿÌÿÿÌÿÌÿÿ™™Ìÿÿ™ÌÌ™ÿÿÌ™3fÿ3ÌÌ™ÌÿÌÿ™ÿfff™–––3f3™f333™3™3f33™333…U Worksheet®üField 1Field 2Field 3Field 4Field 5Field 6Field 7 » ÌAU*+€‚Áƒ„&ffffffæ?'ffffffæ?(è?)è?¡"dXX333333Ó?333333Ó?ý ý ý ý ý ý ý >¶@ Root Entryÿÿÿÿÿÿÿÿ ÀF€m¾‚lXÉ€m¾‚lXÉÀBook ÿÿÿÿÿÿÿÿÿÿÿÿ ÀF¤þÿÿÿþÿÿÿþÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

What am I doing wrong?
Developer
Dec 7, 2008 at 7:29 PM
Look like you are trying to send xls file directly to the browser, but have forgotten to set the HTTP headers.
Dec 8, 2008 at 12:23 AM
Ok I set the header and footer and out put them.  Now I get this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/pkrbook/public_html/bookkeeper/cash_tourney_excel.php:3) in /home/pkrbook/public_html/bookkeeper/cash_tourney_excel.php on line 124

Warning: Cannot modify header information - headers already sent by (output started at /home/pkrbook/public_html/bookkeeper/cash_tourney_excel.php:3) in /home/pkrbook/public_html/bookkeeper/cash_tourney_excel.php on line 125

Warning: Cannot modify header information - headers already sent by (output started at /home/pkrbook/public_html/bookkeeper/cash_tourney_excel.php:3) in /home/pkrbook/public_html/bookkeeper/cash_tourney_excel.php on line 126

Dont know if I have header information right or placed correctly.

I put this code just above the table for the column Titles:
// Set header and footer. When no different headers for odd/even are used, odd header is assumed.  
$excel->getActiveSheet()->getHeaderFooter()->setOddHeader("&amp;CData Map");  
$excel->getActiveSheet()->getHeaderFooter()->setOddFooter("&amp;RPage &amp;P of &amp;N"); 

Then I put this code at the bottom of the page:

// Output the headers  
header('Content-Type: application/vnd.ms-excel;');  
header('Content-type: application/x-msexcel');  
header('Content-Disposition: attachment; filename="' . $file_name . '.xls"');  

// Output the spreadsheet in binary format  
include 'PHPExcel/Writer/Excel5.php';  
$writer = new PHPExcel_Writer_Excel5($excel);  
$writer->save("php://output");

Dec 8, 2008 at 12:30 AM
I also put this code below $result=:

// Start to build the spreadsheet  
$excel = new PHPExcel();  
$excel->setActiveSheetIndex(0);

// Put in the header row  
$excel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "Field 1"); 

Then this code below the echo table:

$row_count = 2;  
while($row = mysql_fetch_array($result)) {  
 
$excel->getActiveSheet()->setCellValueByColumnAndRow(0, $row_count, $row[0]);

Do you see where I may be making a mistake?

Developer
Dec 8, 2008 at 12:38 AM
Make sure you are not sending any output before those header() statements. There must be absolutely no whitespace before the opening <?php tag.

If you have included other files, also check those. Thirdly, you could be outputting stray characters if you have saved as UTF-8 with BOM. Make sure to save your PHP-scripts as UTF-8 without BOM.

Dec 8, 2008 at 2:06 AM
I put the header() statements just below where I called the  '$results=' and before any output.  I made sure there was no white space.  I have the older cpanel that doent save as UTF-8.