Avatar of Bohne
Bohne

asked on 

spreadsheet-excel-writer.php not working

Hi,

I'd like to use spreadsheet-excel-writer.php, but it's not working! :-( http://pear.php.net/manual/de/package.fileformats.spreadsheet-excel-writer.php

I tried to implement the following example:

<?php
require_once 'Spreadsheet/Excel/Writer.php';

// 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();
?>

But unfortunately, the excel file is empty! The file opens and the filename "test.xls" appears (as it should), but the fields are empty. There is no php error, so where's the problem?

Here my example: http://web182.theta.ibone.ch/adressliste.temp/test5.php


Thanks a lot!
PHP

Avatar of undefined
Last Comment
Bohne
Avatar of daveaton
daveaton

Move this statement  to right above the close statement

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


like this

<?php
require_once 'Spreadsheet/Excel/Writer.php';

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

// 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);

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

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

You can find more information here.
http://www.php-editors.com/pear_manual/p_package.fileformats.spreadsheet-excel-writer.intro-format.html

figure 29-4 gives a good example




Avatar of Bohne
Bohne

ASKER

... unfortunately this does not make any difference! :-( I also tried the example mentioned above but without success: http://web182.theta.ibone.ch/adressliste.temp/test6.php
Avatar of daveaton
daveaton

Try a non good example from this page..

http://www.php-editors.com/pear_manual/p_package.fileformats.spreadsheet-excel-writer.intro-format.html

<?php
require_once 'Spreadsheet/Excel/Writer.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();
?>

the only difference I see in your code and the example code is that is is using  "" instead of single  '' for text which should not make a difference but try it anyway.. If that does not help we will dig deeper into the problem..


Avatar of daveaton
daveaton

hum I meant to say a known good example instead of a non good... crapy fingers are not doing what I tell them :)
ASKER CERTIFIED SOLUTION
Avatar of daveaton
daveaton

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bohne
Bohne

ASKER

... hm, I did nothing! I just asked my host to install the PEAR package properly! Now its working and you get the points for nothing. :-) Thanks anyway...
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo