Forum Moderators: coopster

Message Too Old, No Replies

Converting .xls to .txt using LAMP

...so I can dump the data into mysql

         

Robber

10:57 am on Dec 3, 2004 (gmt 0)

10+ Year Member



Hi,

Now before we start, the easiest way do to this is to just open the .xls in Excel then save as as .txt (tab delimited). But on this particular occassion, I can't do that as I want this to be an automated cron process, I am however trying to get the source file dumped straight into .txt rather than .xls.

So in the meantime I found a project on sourceforge that will let me load an xls into php arrays. Thats pretty neat, exactly what I needed.

But! The xls I need to read is 30-35mb. Now since the php memory_limit directive is set to 8M the script won't work.

I dont want to change the value in php.ini as this is on a live web server and that could be a hazard.

I dont want to just temporarily change the php.ini because I am going to be doing this conversion in a scheduled cron.

I had thought there would be a function such as set_time_limit but for mem usage so I could change it just for the duration of the scripts execution, but there isn't!

So, anyone got a good way round this?

Cheers

Birdman

12:29 pm on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can probably read the file in chunks to get around the mem limit.

Check out the sixth user comment on this page:

[us2.php.net...]

Robber

12:33 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



Thanks, I'll take a look at that but I would have thought the .xls class will need to have the whole file loaded into memory before it can do anything, but I'll have a go.

Cheers

baze22

12:34 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



Is there any way you can do it in chunks and loop through the file? Just read x rows at a time, write them to a file and repeat until eof.

baze

baze22

1:37 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



Just noticed - 2 replies while I was doing my previous post (and in 2 different threads no less) - I've gotta hit submit quicker. :)

The function as written may have you read the whole file at once, but maybe you could modify it to do chunks.

baze

lazydog

11:12 am on Dec 5, 2004 (gmt 0)

10+ Year Member



How about another installation of php on the same server with a different php.ini?
Having said that, if you are using php-cli to process the excel files, then you can configure php-cli to use a diff. ini.

Hope that helps.