 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
griffmcc
Joined: 05 Mar 2009 Posts: 7
|
Posted: Thu Mar 05, 2009 7:20 pm Post subject: Add one line to tutorial example and get garbage |
|
|
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 |
|
 |
griffmcc
Joined: 05 Mar 2009 Posts: 7
|
|
| Back to top |
|
 |
griffmcc
Joined: 05 Mar 2009 Posts: 7
|
Posted: Thu Mar 05, 2009 7:57 pm Post subject: One more correction to the original post |
|
|
The second instance of "Code:" should read:
<?php
function TestFunction()
{
}
?> |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1230
|
Posted: Thu Mar 05, 2009 10:20 pm Post subject: |
|
|
| 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 |
|
 |
|
|
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
|
|