Jump to content

PHP Import/Export Excel


matfish

Recommended Posts

In regards to : [url=http://www.phpfreaks.com/forums/index.php/topic,89428.0.html]http://www.phpfreaks.com/forums/index.php/topic,89428.0.html[/url]

Im also looking for the same.

Can anyone point me in the right right direction to do the following:-

Iv got an excel spreadsheet on the server complete with heading/logo & footer.
I need to read it, add a new line of values and then export/upload back to the server.

Iv got the reading/writing of values without a problem, however How do I maintain the header/footer and logo etc? Any just put in the new line/entry?

Many thanks
Link to comment
https://forums.phpfreaks.com/topic/35802-php-importexport-excel/
Share on other sites

Well, you say you already can read/write data to the file already. I see no reason why doing so would change the header/footer - which in your original statement you said you wanted to keep the same. But, in your last statement you say that the footer includes a sum of th evalues in the table.

So, I am still a little confused here. Are you having problems with the header/footer getting changed when you edit data in the spreadsheet OR is the problem that you need to change the footer to show a new sum?
Lets try asking a different question...

How do you open an existing excel file (which already has a company logo&heading) and then use the below to post my query to that excel doc to download?



[code]$line1="RSR\tProduct\tColor\tSales\t";

$line2="1\tPrinter\tGrey\t13\t";
$line3="2\tCD\tBlue\t15\t";
$line4="3\tDVD\tRed\t7\t";
$line5="4\tMonitor\tGreen\t4\t";
$line6="5\tTelephone\tBlack\t2\t";


$data="$line1\n$line2\n$line3\n$line4\n$line5\n$line6\n";

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";[/code]

? Any ideas?
Well, I found a tutorial on working with a spreadsheet: http://www.dreamincode.net/forums/showtopic10132.htm

And, now I see your problem. At first I couldn't write to an existing spreadsheet. But, if I used PHP to first create a spreadsheet I could then open and write new data to the spreadsheet on successive sessions. I'm pretty sure this is because the spreadsheet created through PHP is tab delimited, whereas a "new" document created through Excel is in a proprietary Excel format.

I then took the template I created through PHP and added a header and footer. But, then as soon as I edited the document through PHP it lost its headers. Because a tab delimited file is nothing more than a text document - does not have headers.

So, I don't have a solution for you. but, I did find another source that may be of some interest. It shows how to create a spreadsheet with styles and formatting: http://www.tecnorama.org/document.php?id_doc=64

Uless you can find a class or plug-in, I think you may be out of luck. If you were to open an Excel file that has a header/footer in a text editor you would see what a mess the code is and how difficult it could be to replicate.

Good luck.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.