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 
[Solved] Saving with Excel Writer
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PEAR Forum Forum Index -> File Formats
View previous topic :: View next topic  
Author Message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 11:03 am    Post subject: [Solved] Saving with Excel Writer Reply with quote

Hi guys,

New to forum. New to Pear. New to Excel Writer.

Loving it so far but I am having problems saving the created spreadsheet.

My initial attempts were successful at sending the file to the screen using
Code:
->send('NAME');


And know to block out this when I want to save the file and put the destination of the file in:

Code:
$workbook = new Spreadsheet_Excel_Writer('/home/.../files/test.xls');


where ... is the path to where I want to save the file.
Is this correct?

I am running this on a VPS and have had my Server Administrator install Pear, Spreadsheet and recently BIFFwriter if this makes a difference.

Thanks for any response.

D.
_________________
Regards,
D.


Last edited by daemonkin on Wed Feb 06, 2008 11:34 am; edited 1 time in total
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 05, 2008 11:54 am    Post subject: Re: Saving with Excel Writer Reply with quote

daemonkin wrote:
Code:
$workbook = new Spreadsheet_Excel_Writer('/home/.../files/test.xls');


where ... is the path to where I want to save the file.
Is this correct?


Yes, just like it's explained here:
http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.intro.php

Do you have problem with this? Any error messages?
Back to top
View user's profile Send private message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 12:01 pm    Post subject: Reply with quote

Mark.
Thanks for the quick reply.
I have read the documentation and various other bits on the net but the example given just gives a generic filename and no mention of absolute path names or directories.

I am running this script and trying to save it anywhere. Once I have that sorted I can work on storing where I need it.

I am getting a blank screen (using Firefox) when I remove the ->send() function and no file appears at the specified filepath.

Can you tell me if I need to implement BIFFwriter? If so, how should I implement it?

Thanks for your help.

D.
_________________
Regards,
D.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 05, 2008 12:10 pm    Post subject: Reply with quote

daemonkin wrote:
I have read the documentation and various other bits on the net but the example given just gives a generic filename and no mention of absolute path names or directories.


Ah, okay, but it says above the example "... give a valid file path to the workbook constructor." => Your usage is right.

But:
- you might don't have write permissions in that directory
- you might to set a temp directory:
http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-workbook.settempdir.php

daemonkin wrote:
I am getting a blank screen (using Firefox) when I remove the ->send() function and no file appears at the specified filepath.


Maybe you have error_reporting set to a very high level or have set display_errors to off. For debugging PEAR code, the following lines are helpful:

Code:

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'PEAR.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
Back to top
View user's profile Send private message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 1:52 pm    Post subject: Reply with quote

Mark,

I have the following:

Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'PEAR.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
require_once 'Spreadsheet/Excel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer('test.xls');
$worksheet =& $workbook->addWorksheet('My first worksheet');
$workbook->setTempDir('/home/.../temp');
$worksheet->write(0, 0, "did this work?");
$workbook->close();
?>


but am getting:
Can't open test.xls. It may be in use or protected.

Any thoughts?
_________________
Regards,
D.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 05, 2008 2:44 pm    Post subject: Reply with quote

daemonkin wrote:
I have the following:[...]
but am getting:
Can't open test.xls. It may be in use or protected.


Is it Excel that gives you this message? If yes, you need to close the file in Excel before you write it with your PHP script.
Back to top
View user's profile Send private message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 3:14 pm    Post subject: Reply with quote

Sorry, its on the browser window.
_________________
Regards,
D.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 05, 2008 3:19 pm    Post subject: Reply with quote

daemonkin wrote:
Sorry, its on the browser window.


Okay. The message is generated in OLE/PPS/Root.php, in the save() method. You could remove the "@" sign from the fopen() call there to get a reasonable error message.
Back to top
View user's profile Send private message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 4:11 pm    Post subject: Reply with quote

Mark,

I appreciate all your help and advice. The Pear App is being run from the server root and I do not think I have access to it.

Is there any reason why this would not be working? I have chmoded the temp dir to 777
_________________
Regards,
D.
Back to top
View user's profile Send private message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 4:40 pm    Post subject: Reply with quote

Trash the last comment.

Got the following after editing the fopen

Code:
Warning: fopen(test.xls) [function.fopen]: failed to open stream: Permission denied in /usr/lib/php/OLE/PPS/Root.php on line 104


Any help?
_________________
Regards,
D.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 05, 2008 4:52 pm    Post subject: Reply with quote

daemonkin wrote:
I appreciate all your help and advice. The Pear App is being run from the server root and I do not think I have access to it.


Well, there is always the possibility to install PEAR yourself in your own directory.

daemonkin wrote:
Is there any reason why this would not be working? I have chmoded the temp dir to 777


The file may still be assigned to another user. Depending on your permissions and who has created the file, you might need to ask your host to change the permissions.
Back to top
View user's profile Send private message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 4:55 pm    Post subject: Reply with quote

Please see last post.
fopen causing the error due to permissions in Root.php

D.
_________________
Regards,
D.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 05, 2008 5:04 pm    Post subject: Reply with quote

daemonkin wrote:
Please see last post.
fopen causing the error due to permissions in Root.php


You wrote that you can't edit Root.php to remove the "@" from the fopen() call, don't you? If you would edit the file, you would get a reasonable error message telling you e.g. that you don't have permissions for the .xls file or that somebody else is editing the file (but I guess that this is unlikely).
Back to top
View user's profile Send private message
daemonkin



Joined: 05 Feb 2008
Posts: 10

PostPosted: Tue Feb 05, 2008 5:08 pm    Post subject: Reply with quote

I found and edited the Root.php file and removed the '@' on fopen to see what the errors were.

The only error I am getting is

Code:
failed to open stream: Permission denied in /usr/lib/php/OLE/PPS/Root.php on line 104


Does this make any sense? If I pass the destination path in the constructor I am still getting an error due to Root.php

D.
_________________
Regards,
D.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 05, 2008 5:10 pm    Post subject: Reply with quote

"Permission denied" means that you (better said: the webserver) may not access that directory. Maybe you have a typo in the path? Are you sure that you've chosen the right directory?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> File Formats All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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

'Actiemonitor' online projectmanagement software