| | |
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 29 Days Ago
Last edited by Will Gresham; 29 Days Ago 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: 527
Reputation:
Solved Threads: 61
0
#3 29 Days Ago
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 |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





