By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,965 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,965 IT Pros & Developers. It's quick & easy.

Handling .xls files with PHP - can it be done?

P: n/a
Hi All,

Up until now, I have been importing data from Excel spreadsheets into MySQL
by exporting them to either .csv files, or tab-delimited .txt files, then
using PHP scripts to insert each row. This works fine, but just adds
another step (open xls, save as csv, then import into MySQL). I am
wondering, has there been any work done on handling xls files, natively, in
PHP? The files I work with are very simple; just rows of data divided into
columns. No cells are calculated based on the value of other cells. It is
all text fields, with one field that holds a date value (not sure if Excel
stores that as text or some sort of timestamp?).

I am well aware of all the tools you can use to convert .xls to something
else (e.g., OpenOffice), but I would like to do it *natively* in PHP, or at
least using a program that I can kick off from within PHP. That way I can
upload an .xls file, and let my scripts worry about converting it to
something easily inserted in MySQL.

Any thoughts?

Sincerely,
-Josh
Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Joshua Beall wrote:
Hi All,

Up until now, I have been importing data from Excel spreadsheets into MySQL
by exporting them to either .csv files, or tab-delimited .txt files, then
using PHP scripts to insert each row. This works fine, but just adds
another step (open xls, save as csv, then import into MySQL). I am
wondering, has there been any work done on handling xls files, natively, in
PHP? The files I work with are very simple; just rows of data divided into
columns. No cells are calculated based on the value of other cells. It is
all text fields, with one field that holds a date value (not sure if Excel
stores that as text or some sort of timestamp?).

I am well aware of all the tools you can use to convert .xls to something
else (e.g., OpenOffice), but I would like to do it *natively* in PHP, or at
least using a program that I can kick off from within PHP. That way I can
upload an .xls file, and let my scripts worry about converting it to
something easily inserted in MySQL.

Any thoughts?

Sincerely,
-Josh


good idea! write a php function set for this! we're all looking forward
to use it... ;)

ar.
Jul 17 '05 #2

P: n/a
"Allan Rydberg" <al****@southtech.net> wrote in message
news:cc**********@newshispeed.ch...
Joshua Beall wrote:
good idea! write a php function set for this! we're all looking forward
to use it... ;)


There are actually some commercial solutions for this, but I was hoping for
something Open Source.

There is also a PEAR package that lets you write XLS files, but none (afaik)
that let you read. Hmm.

Any pointers?
Jul 17 '05 #3

P: n/a
"Joshua Beall" <jb****@donotspam.remove.me.heraldic.us> wrote in message
news:yX*****************@nwrddc01.gnilink.net...
"Allan Rydberg" <al****@southtech.net> wrote in message
news:cc**********@newshispeed.ch...
Joshua Beall wrote:
good idea! write a php function set for this! we're all looking forward
to use it... ;)
There are actually some commercial solutions for this, but I was hoping

for something Open Source.

There is also a PEAR package that lets you write XLS files, but none (afaik) that let you read. Hmm.

Any pointers?


It is possible on Windos platforms by using COM objects, but I bet you want
NIX compatiblity don't you?
Jul 17 '05 #4

P: n/a
> It is possible on Windos platforms by using COM objects, but I bet you
want
NIX compatiblity don't you?


You're a mind reader ;-)
Jul 17 '05 #5

P: n/a
In article <VA******************@nwrddc03.gnilink.net>,
"Joshua Beall" <jb****@donotspam.remove.me.heraldic.us> wrote:
Hi All,

Up until now, I have been importing data from Excel spreadsheets into MySQL
by exporting them to either .csv files, or tab-delimited .txt files, then
using PHP scripts to insert each row. This works fine, but just adds
another step (open xls, save as csv, then import into MySQL). I am
wondering, has there been any work done on handling xls files, natively, in
PHP? The files I work with are very simple; just rows of data divided into
columns. No cells are calculated based on the value of other cells. It is
all text fields, with one field that holds a date value (not sure if Excel
stores that as text or some sort of timestamp?).

I am well aware of all the tools you can use to convert .xls to something
else (e.g., OpenOffice), but I would like to do it *natively* in PHP, or at
least using a program that I can kick off from within PHP. That way I can
upload an .xls file, and let my scripts worry about converting it to
something easily inserted in MySQL.

Any thoughts?

Sincerely,
-Josh


You'll have to 'roll your own' here. The various formats of Excel are
documented (Google showed the following):

http://chicago.sourceforge.net/devel/docs/excel
http://sc.openoffice.org/excelfileformat.pdf

The top link has two links to php code to WRITE excel, but they don't
work very well. I found the following to be much better:

http://www.phpclasses.org/browse/package/767.html

None of the code out there does native reading of Excel. You'll have to
do it yourself.

Now I ask you:

How important is this to you and your project?
How much time do you have to spend on this?
What would be the "return on investment" of having the feature?

Get 3-6 months to code this up and build it into php?

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '05 #6

P: n/a
Joshua Beall wrote:
Up until now, I have been importing data from Excel spreadsheets into
MySQL by exporting them to either .csv files, or tab-delimited .txt files,
then using PHP scripts to insert each row.**This*works*fine,*but*just*adds
another step (open xls, save as csv, then import into MySQL).**I*am
wondering, has there been any work done on handling xls files, natively,
in PHP?**The*files*I*work*with*are*very*simple;*just* rows*of*data*divided
into columns.**No*cells*are*calculated*based*on*the*val ue*of*other*cells.*
It*is all text fields, with one field that holds a date value (not sure if
Excel stores that as text or some sort of timestamp?).

I am well aware of all the tools you can use to convert .xls to something
else (e.g., OpenOffice), but I would like to do it natively in PHP, or at
least using a program that I can kick off from within PHP.**That*way*I*can
upload an .xls file, and let my scripts worry about converting it to
something easily inserted in MySQL.


http://pear.php.net/package-info.php...t_Excel_Writer

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #7

P: n/a
Chris Hope wrote:
Joshua Beall wrote:
Up until now, I have been importing data from Excel spreadsheets into
MySQL by exporting them to either .csv files, or tab-delimited .txt
files, then using PHP scripts to insert each row.**This*works*fine,*but
just*adds another step (open xls, save as csv, then import into MySQL).*
I*am wondering, has there been any work done on handling xls files,
natively, in PHP?**The*files*I*work*with*are*very*simple;*just* rows*of
data*divided into columns.**No*cells*are*calculated*based*on*the*val ue*of
other*cells. It*is all text fields, with one field that holds a date
value (not sure if Excel stores that as text or some sort of timestamp?).

I am well aware of all the tools you can use to convert .xls to something
else (e.g., OpenOffice), but I would like to do it natively in PHP, or at
least using a program that I can kick off from within PHP.**That*way*I
can upload an .xls file, and let my scripts worry about converting it to
something easily inserted in MySQL.


http://pear.php.net/package-info.php...t_Excel_Writer


I'm still half asleep. There I was misreading what you wrote and thought you
were trying to write an xls not read one...

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #8

P: n/a
"Chris Hope" <bl*******@electrictoolbox.com> wrote in message
news:10**************@216.128.74.129...
http://pear.php.net/package-info.php...t_Excel_Writer


I'm still half asleep. There I was misreading what you wrote and thought you
were trying to write an xls not read one...

I am actually using that package right now to dump the contents, after
processing, back to an xls that the user can download.

I think, however (As Michael Vilain pointed out in another post), that if it
comes down to either writing my own .xls reader, or simply insisting that
users export to .csv before uploading, the latter is probably the better
solution, due to the narrow scope of the project I am working on. There
will not be more than a handful of people using this tool, and they too
would probably rather it be done now, and they have to export to .csv once
per week to upload to the website. Perhaps more to the point, they would
rather do that than *pay* me to roll my own .xls reader.

So, I guess that is the end of that. Although, if someone knows where I
should be looking, do let me know!

-jb
Jul 17 '05 #9

P: n/a
On Thu, 01 Jul 2004 16:27:10 +0000, Joshua Beall wrote:
"Allan Rydberg" <al****@southtech.net> wrote in message
news:cc**********@newshispeed.ch...
Joshua Beall wrote:
good idea! write a php function set for this! we're all looking forward
to use it... ;)


There are actually some commercial solutions for this, but I was hoping for
something Open Source.

There is also a PEAR package that lets you write XLS files, but none (afaik)
that let you read. Hmm.

Any pointers?


xls2csv

Haven't used it, but it might do what you want by calling it within PHP
with system() or the like.

http://www.45.free.net/~vitus/ice/catdoc/

later...

--
Jeffrey Silverman
je*****@pantsjhu.edu
Drop "pants" to reply by email

Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.