PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Add one line to tutorial example and get garbage

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Documentation, Tutorials, How to's
View previous topic :: View next topic  
Author Message
griffmcc



Joined: 05 Mar 2009
Posts: 7

PostPosted: Thu Mar 05, 2009 7:20 pm    Post subject: Add one line to tutorial example and get garbage Reply with quote

When I add one line to a 'Spreadsheet/Excel/Writer.php' tutorial example, I get garbage in the Excel file that is generated.

I can successfully run the second example at http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.intro-format.php.

However, if I add the statement:

Code:
require_once ‘my_lib.php’;


anywhere in the example (except after the last line) then the Excel file that is generated is full of garbage. This is true whether the my_lib.php file contains something as simple as:
Code:
function TestFunction()
{
}

or even is an empty file.

Does anybody know what’s going on? Can one not include any other PHP files in a PHP file that uses the Excel Writer?

Thank you,

Griff

Here is an example that will generate an Excel file full of garbage. Before you run it make sure and create an empty file called 'empty_file.php' in the same directory as this example:

Code:
<?php

require_once 'Spreadsheet/Excel/Writer.php';
require_once 'empty_file.php';

$workbook = new Spreadsheet_Excel_Writer();

$format_bold =& $workbook->addFormat();
$format_bold->setBold();

$format_title =& $workbook->addFormat();
$format_title->setBold();
$format_title->setColor('yellow');
$format_title->setPattern(1);
$format_title->setFgColor('blue');

$worksheet =& $workbook->addWorksheet();

$worksheet->write(0, 0, "Quarterly Profits for Dotcom.Com", $format_title);
// While we are at it, why not throw some more numbers around
$worksheet->write(1, 0, "Quarter", $format_bold);
$worksheet->write(1, 1, "Profit", $format_bold);
$worksheet->write(2, 0, "Q1");
$worksheet->write(2, 1, 0);
$worksheet->write(3, 0, "Q2");
$worksheet->write(3, 1, 0);

$workbook->send('test.xls');
$workbook->close();

?>
Back to top
View user's profile Send private message
griffmcc



Joined: 05 Mar 2009
Posts: 7

PostPosted: Thu Mar 05, 2009 7:25 pm    Post subject: Correction to previous post Reply with quote

The second sentence should not end in a period because that makes the URL go 404.

Here is the tutorial file I am referring to:

http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.intro-format.php
Back to top
View user's profile Send private message
griffmcc



Joined: 05 Mar 2009
Posts: 7

PostPosted: Thu Mar 05, 2009 7:57 pm    Post subject: One more correction to the original post Reply with quote

The second instance of "Code:" should read:

<?php
function TestFunction()
{
}
?>
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1230

PostPosted: Thu Mar 05, 2009 10:20 pm    Post subject: Reply with quote

There is likely some whitespace before the opening PHP tag (<?php) or after the closing tag (?>), or maybe you're (or better: your editor) using the UTF-8 BOM. PHP can't send the necessary headers in this case, causing the binary Excel data to show up in your browser.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Documentation, Tutorials, How to's All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement