1 Replies - 3960 Views - Last Post: 28 July 2008 - 12:52 PM Rate Topic: -----

#1 pavanpuligandla   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-July 08

Export excel sheet values to Mysql table

Posted 28 July 2008 - 11:21 AM

i'm trying to export an excel workbook to mysql table but couldnt succeed, at last i found a solution which is not that much perfect to implement( i,e import CSV to Mysql table.)
I want to export any xls file to the specified database table, but in my code i'm predefining the .csv file which is to be exported to the mysql table..
kindly go thru this and do the need ful.. the code is as follows :;


//Connect to mysql server
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
//Select database
if(!$db) {
die("Unable to select database");

$fcontents = file ('http://localhost/Project/spsheet.xls');
# expects the csv file to be in the same dir as this script

for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
echo "$line<BR>";
$arr = explode("','", $line);
echo "$arr";
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$sql = "insert into subject values (". implode("'", $arr).")";
#$sql = "insert into test values ('". $arr ."')";
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";

my motto is to implement the code which it should read the contents of input <b>ANY</b> .xls file instead of predefining the path to only a selected single .xls file...i dont need any csv file but i need to export only excel workbook.

[$fcontents = file ('http://localhost/Project/spsheet.xls');]-- predefined path of xls file..

Many thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: Export excel sheet values to Mysql table

#2 akozlik   User is offline

  • D.I.C Addict
  • member icon

Reputation: 91
  • View blog
  • Posts: 798
  • Joined: 25-February 08

Re: Export excel sheet values to Mysql table

Posted 28 July 2008 - 12:52 PM

You cannot export an Excel spreadsheet as a database. You must export it as a csv or other delimited format, and then process it from there. I've written a tutorial on the subject that can be found here:


Good luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1