Solved

Convert XLS to CSV using PHP on Linux Apache server

Posted on 2008-10-18
4
6,039 Views
Last Modified: 2013-12-13
I have an exisitng web app written in PHP, that allows the user to upload a csv file and it imports the data into a mysql table.

My client is now complaining about converting xls files to csv.  Is there a script or linux program that I can run on the server that would convert the excel spreadsheet to csv on the web server?

Then my client could just upload the xls files and be done with it?

What about a linux based conversion of xlsx files to csv??
0
Comment
Question by:fastfind1
  • 2
  • 2
4 Comments
 

Author Comment

by:fastfind1
ID: 22749889
I have found on source_forge something called Spreadsheet_Excel_Reader.  I tried the following code to try and get a csv file to pop out from the xls file, but it is not working.  Can anyone see the error in my code?
<?php
 
require_once 'reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('closing/closing.xls');
 
?>

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 22752658
The Spreadsheet_Excel_Reader class is not well-documented.  In fact, I could find no documentation for it at all.  But I believe it only reads an Excel file.

What error are you receiving with your code?
0
 

Author Comment

by:fastfind1
ID: 22755955
No error - but no result.

Maybe Spreadsheet_Excel_reader is not what I want.

Anyone have a solution for converting xls files to csv files on a linux server - using a PHP script, or something similar?
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 22758274
>>> No error - but no result.

I would expect not, seeing as how your code only reads the file.  Once you have the data from the file, you'll need to reorganize it into rows of comma-delimited text.  

See here for a brief tutorial on using the reader class.  It also talks about the writer class, but that should not be necessary for your purposes:

http://devzone.zend.com/article/3336-Reading-and-Writing-Spreadsheets-with-PHP
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question