Solved

Convert XLS to CSV using PHP on Linux Apache server

Posted on 2008-10-18
4
6,049 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 51

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 51

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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