Solved

Convert XLS to CSV using PHP on Linux Apache server

Posted on 2008-10-18
4
6,012 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>> 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now