Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pear Package - Spreadsheet_Excel_Writer Append to file

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
GB
I have fair knowledge of php but zero of a Spreadsheet_Excel_Writer PEAR package I am trying to use. It writes to excel files with formats etc. and works very well if you are creating an excel file from scratch. I need to append data to an existing file. Currently it overwrites (with blank cells) my existing data and just insrts the new cell info.

The spreadsheet consists of time recordings for a task and each time the task is performed times have to be recorded, so I need to append to the bottom of the list.

The following is the code I have. Even if i put the number of the row that I want to place the data into it puts it in that row but everything else dissapears. I susspose it is creating a new file of the same name and inserting data. It needs to write to an existing file without disturbing the current data.

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

// We give the path to our file here
$workbook = new Spreadsheet_Excel_Writer('times.xls');

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


$worksheet->write(40, 0, '08/03/06');
$worksheet->write(40, 1, 14);

// We still need to explicitly close the workbook
$workbook->close();
?>


Any help or pointers would be greatly appreciated.

Thanks and Regards
 
sorry to say that i don't think you can do this using the pear class. last time i checked it only creats new files.

some thoughts:

1. instead of creating a file why not just create the new bits and send to the browswer (use the send method).

2. if your server is running on windows (and you have excel installed) you can address the excel file with COM instead of this php class.

3. how about writing to the spreadsheet using an odbc connection?

4. spreadsheets aren't great places to store timesheet information when dealing with multiple people. there are a number of freeware timesheet management programs out there (i like ultrize) - you could try them?
 
I completely agree, spreadsheet usage for this sucks but managers won't listen to the grunt of a team. Anyhows,


Shame that only new files will work maybe this will change in a later update who knows. This package was the option after trying out the usual fopen() commands with php which unfortunatly didn't work.

With this in mind I'll have a look at reading in the data in the existing excel sheet, append the new time (maybe in a temporary text tile) then write the updated info to a new sheet with the same name and format so it looks like it has been appended!!
 
With this in mind I'll have a look at reading in the data in the existing excel sheet, append the new time (maybe in a temporary text tile) then write the updated info to a new sheet with the same name and format so it looks like it has been appended!!

you don't need to - just use the COM object (if you are using windows etc).
 
Sorry I missed that point.


Sounding really stupid but, what is this COM object? I don't think I have come accross it before.
 
pleasure - don't ignore the odbc option either - that might well be even easier for you to develop to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top