PHP Classes

Textarea 2 CSV: Convert a pasted Excel document to the CSV format

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 46%Total: 654 All time: 4,903 This week: 95Up
Version License PHP version Categories
textarea-2-csv 1.0.0GNU General Publi...5.0Text processing, Parsers
Description 

Author

This class can Convert a pasted Excel document to the CSV format.

It can parse text of a Excel spreadsheet eventually pasted in a form textarea input and convert it in data in the CSV format.

The converted data may saved to a given file or displayed as the current script output.

The CSV field separator character is configurable.

Innovation Award
PHP Programming Innovation award nominee
January 2013
Number 6
Some applications need that the users supply tabular data, eventually edited in a spreadsheet program like Excel.

The users could upload the spreadsheet file but it may be hard to process it, especially when it is necessary that the data of a specific range of cells.

This class provides an alternative approach for this problem that consists in letting the user copy data from the spreadsheet program and pasting it in a textarea form input.

Then the class is able to parse the input data and return it in a more convenient format for processing by the application.

Manuel Lemos
Picture of Gianluca Zanferrari
  Performance   Level  
Name: Gianluca Zanferrari <contact>
Classes: 19 packages by
Country: The Netherlands The Netherlands
Age: 57
All time rank: 1674 in The Netherlands The Netherlands
Week rank: 312 Down10 in The Netherlands The Netherlands Down
Innovation award
Innovation award
Nominee: 5x

Example

<?php
require_once('class.textarea2csv.php');
/*
 * 1) initiate the class passing the $_POST data
 * 2) optional: set a different divider than comma (default) with function set_divider(';') or set_divider(chr(9)); options are: ; and tab
 * 3) call the function save_data() without parameter to get the data returned OR call the function save_data('filename') with a parameter to save the data with the given filename
 */

if(isset($_POST['xls']) && trim($_POST['xls']) != ''){
       
   
$csv = new textarea_2_csv($_POST);
   
   
// possibility to set the divider to another format
    // $xls->set_divider(';');
    // $xls->set_divider(chr(9));

    // process data and save it with filename output
   
$data = $csv->save_data('output');

}
?>
<html>
    <h2>Example of class "Textarea 2 csv"</h2>
    <p>Copy the the content of an excel sheet, paste it in the textarea and click on "Send".</p>
    <form method="post">
        <p><textarea name="xls" style="width: 800px; height: 400px"></textarea></p>
        <p><input type="submit" value="Send" /></p>
    </form>
</html>


  Files folder image Files  
File Role Description
Plain text file class.textarea2csv.php Class class itself
Accessible without login Plain text file example.textarea2csv.php Example example of use

 Version Control Unique User Downloads Download Rankings  
 0%
Total:654
This week:0
All time:4,903
This week:95Up
User Ratings User Comments (1)
 All time
Utility:66%StarStarStarStar
Consistency:66%StarStarStarStar
Documentation:-
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:46%StarStarStar
Rank:3125
 
sdsdsdsd sdsdsd sdsdsd
11 years ago (harry)
35%StarStar