Current location: Hot Scripts Forums » Programming Languages » PHP » Excel To MySQL


Excel To MySQL

Reply
  #1 (permalink)  
Old 01-14-05, 03:48 AM
eddyvlad eddyvlad is offline
Wannabe Coder
 
Join Date: Sep 2003
Location: In The Bloody Pits Of Hell
Posts: 160
Thanks: 2
Thanked 0 Times in 0 Posts
Excel To MySQL

I have to convert all the data (collumn and rows) in .xls to MySQL (Field and rows).
I have no idea where to start. I heard something about COM or active x or something that I need. My PHP is in Windows.

Help...
__________________
Mr. Brown Eyes
Reply With Quote
  #2 (permalink)  
Old 01-14-05, 04:28 AM
Beck Beck is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
<?

define(db_host, "localhost");
define(db_user, "root");
define(db_pass, "");
define(db_link, mysql_connect(db_host, db_user, db_pass));
define(db_name, "test");
mysql_select_db(db_name);


$excel = new COM("Excel.Application") or die("Excel could not be started");


ini_set('max_execution_time','120');



$excel -> Visible = 0;



$excel -> DisplayAlerts = 0;



$data = $excel -> Workbooks -> Open("C:\userlist.xls");

$Sheets = $data -> Worksheets(1);



for($i = 3; $i <= 5; $i++){

for($x = 1; $x <= 3; $x++){
$Cell = $Sheets -> Cells($i, $x);
$Cell -> activate;
switch($x){
case 1; $name = $Cell -> value; break;
case 2; $username = $Cell -> value; break;
case 3; $country = $Cell -> value; break;
}
}



$SQL = mysql_query("INSERT INTO members VALUES(NULL, '$name', '$username', '$country')");

}


$excel -> Quit();

?>

also you can see more information and some graphics about above...

http://www.websoldier.net/index.php?...&article_id=51
Reply With Quote
  #3 (permalink)  
Old 01-14-05, 04:54 AM
thedevshop thedevshop is offline
Newbie Coder
 
Join Date: Jan 2005
Location: Bangkok Thailand
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
dbqwikSync software tool may help

You may want to checkout dbQwikSync2mySQL http://www.thedevshoponline.com/dbqwiksync.html
This will take PC databases (including excel spread sheets) and move them the mySQL, creating the required tables and moving the data. If that's what you are trying to do.
Reply With Quote
  #4 (permalink)  
Old 01-14-05, 09:34 AM
Tatsi Tatsi is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
I think you can use PHP Excel Parser Pro (http://www.zakkis.ca/products) for converting .xls data to MySQL. Check the site- they have free trial version so you could try'n'see.
__________________
Veni, vidi, vici
Reply With Quote
  #5 (permalink)  
Old 01-17-05, 07:44 PM
eddyvlad eddyvlad is offline
Wannabe Coder
 
Join Date: Sep 2003
Location: In The Bloody Pits Of Hell
Posts: 160
Thanks: 2
Thanked 0 Times in 0 Posts
Hmm... The COM thingy don't work. So I found a library script base on the Open Office.org library at Sourceforge.net. Hmm.. The script is very hard... I think it reads from the binary of the excel file coz it have...

PHP Code:

define('EXTENSION_BLOCK_POS'0x44);
define('NUM_EXTENSION_BLOCK_POS'0x48);
define('PROPERTY_STORAGE_BLOCK_SIZE'0x80);
define('BIG_BLOCK_DEPOT_BLOCKS_POS'0x4c);
define('SMALL_BLOCK_THRESHOLD'0x1000); 
What the hell? 0x1000?? What does that mean? Well... atleast it gets the job done... I'm figuring out why it can't load large excel file. Since it's open source, I'll upload the script sometime in the future to be shared and improved on. Till then, thanks!!
__________________
Mr. Brown Eyes
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
MySQL 4.1 Subquery Performance SLOW TokenSDragon PHP 2 06-15-07 12:46 PM
Excel document containing records, need to save as a text file to upload to mysql bearslife PHP 1 06-05-04 03:24 AM
mysql crash IMPORTANT comby PHP 0 03-02-04 10:27 AM
great product for dumping/recovering MySQL databases Dave Brown General Advertisements 1 10-03-03 07:40 AM


All times are GMT -5. The time now is 05:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.