Forum Moderators: coopster

Message Too Old, No Replies

Help required regarding Spreadsheet excel writer

Spreadsheet_excel_writer, pear package

         

naiquevin

6:16 am on Oct 6, 2009 (gmt 0)

10+ Year Member



I want to use Spreadsheet_excel_writer in my application and for that I am trying it in a separate php file first. When I run the file, the browser does ask for xls file download but upon opening it (using openOffice installed on windows), it asks me for "text import" instead of showing the file contents directly.. as it happens in an online demo i came across..

When it opens upon importing the text, some garbage characters appear along with the text i am trying to insert

here is the code from the pear manual


<?php
define('DIR_CLASSES','D:/wamp/www/mygame/simcha svn/Pear_packages/');

require_once('Pear_packages/Spreadsheet/Excel/Writer.php');

echo 'hello';

ExportToExcel();

function ExportToExcel(){

// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();

// sending HTTP headers
$workbook->send('test.xls');

// Creating a worksheet
$worksheet =& $workbook->addWorksheet('My first worksheet');

// The actual data
$worksheet->write(0, 0, 'Name');
$worksheet->write(0, 1, 'Age');
$worksheet->write(1, 0, 'John Smith');
$worksheet->write(1, 1, 30);
$worksheet->write(2, 0, 'Johann Schmidt');
$worksheet->write(2, 1, 31);
$worksheet->write(3, 0, 'Juan Herrera');
$worksheet->write(3, 1, 32);

// Let's send the file
$workbook->close();

exit;
}

?>

also i notice that the 'hello' that i am echoing before calling the function also appears in the xls file ..

unable to figure out how to debug this ... kindly help

naiquevin

9:25 am on Oct 6, 2009 (gmt 0)

10+ Year Member



I got it working now .. it was something to do with headers I guess..

i used ob_clean() and its working perfectly although i didnt quite get what ob_start() does.

Also, I am using Zend Framework and it doesnt work when I write the code in the model. whereas it works if the code is in a separate file included in the index.. cant figure out why