| | |
How to Convert .xls file to .csv file in php code
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2009
Posts: 17
Reputation:
Solved Threads: 0
hi,
if any one know that how to convert a excel file to csv file with php coding?????
actually i want to make a site where user upload the data as a excel
file format.
and when they clicked button the excel file is changing in csv file first
then the csv file data entered into the database directly.
i know the procedure to upload data from csv to mysql but i dont know how to change the type from excel to csv.
please help me.thank u.
if any one know that how to convert a excel file to csv file with php coding?????
actually i want to make a site where user upload the data as a excel
file format.
and when they clicked button the excel file is changing in csv file first
then the csv file data entered into the database directly.
i know the procedure to upload data from csv to mysql but i dont know how to change the type from excel to csv.
please help me.thank u.
0
#2 Nov 3rd, 2009
Last edited by Will Gresham; Nov 3rd, 2009 at 8:26 am.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
0
#3 Nov 3rd, 2009
This code reads the .xls file and then converts it to the .csv line by line.
But i will suggest to look for any external library or function to do the same, it will be more easy -
But i will suggest to look for any external library or function to do the same, it will be more easy -
PHP Syntax (Toggle Plain Text)
/* Get the excel.php class here: http://www.phpclasses.org/browse/package/1919.html */ require_once("../classes/excel.php"); $inputFile=$argv[1]; $xlsFile=$argv[2]; if( empty($inputFile) || empty($xlsFile) ) { die("Usage: ". basename($argv[0]) . " in.csv out.xls\n" ); } $fh = fopen( $inputFile, "r" ); if( !is_resource($fh) ) { die("Error opening $inputFile\n" ); } /* Assuming that first line is column headings */ if( ($columns = fgetcsv($fh, 1024, "\t")) == false ) { print( "Error, couldn't get header row\n" ); exit(-2); } $numColumns = count($columns); /* Now read each of the rows, and construct a big Array that holds the data to be Excel-ified: */ $xlsArray = array(); $xlsArray[] = $columns; while( ($rows = fgetcsv($fh, 1024, "\t")) != FALSE ) { $rowArray = array(); for( $i=0; $i<$numColumns;$i++ ) { $key = $columns[$i]; $val = $rows[$i]; $rowArray["$key"] = $val; } $xlsArray[] = $rowArray; unset($rowArray); } fclose($fh); /* Now let the excel class work its magic. excel.php has registered a stream wrapper for "xlsfile:/" and that's what triggers its 'magic': */ $xlsFile = "xlsfile:/".$xlsFile; $fOut = fopen( $xlsFile, "wb" ); if( !is_resource($fOut) ) { die( "Error opening $xlsFile\n" ); } fwrite($fOut, serialize($xlsArray)); fclose($fOut); exit(0);
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
![]() |
Similar Threads
- help with output file from screen to csv file (C)
- Dumping bulk data from csv file into MS-Access DB. (Java)
- having trouble parsing more than one html file into a csv file (Python)
- insert csv file into mysql through php (PHP)
- dat,txt file and csv file???? (C++)
- I Need Help Please. Adding PHP Code To My Site. (PHP)
- Need Help Reading a csv file created from MSExcel (C)
- Save a text file in an csv.file with ascii? (PHP)
Other Threads in the PHP Forum
- Previous Thread: paypal integration
- Next Thread: Making an Admin page
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess 301 access ajax apache api array beginner binary broken button cakephp checkbox class cms code compression cron curl database date directory display download dropdown dynamic echo email error file files folder form forms function functions google href htaccess html httppost image include insert integration ip java javascript joomla limit link login loop mail md5 menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search secure server sessions sms soap source space speed sql structure syntax system table tutorial update upload url validation validator variable video votedown web xml youtube





