Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 20-03-2008, 12:31 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Jan 2008
Posts: 6
Default Excel sheet to sql server database


Can anyone tell me how to transfer and pick data from an excel sheet and put that in the table of a database in SQL?

Last edited by Hitboxx; 20-03-2008 at 12:36 PM. Reason: Normal font and colour will do just fine.
maitrasagnik is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 20-03-2008, 10:26 PM   #2 (permalink)
हॉर्न ओके प्लीज़
 
victor_rambo's Avatar
 
Join Date: Sep 2007
Posts: 1,493
Default Re: Excel sheet to sql server database

1. Convert the spreadsheet into CSV or tab delimited file using the "Save as" option.
2. Use the file() function to get every line in an array.
3. Explode the string at tab(/t) or comma(,).
4. Prepare the MySQL inset into query and execute.

Example usage:
The excel sheet saved as CSV file xls2mysql.php:
Code:
Amitabh Bachhan, 62, Male
Emma Watson, 18, Female
Daniel Radcliffe,18,Male
The PHP code:
PHP Code:
<?php
$xls
=file("xls2mysql.csv");
foreach(
$xls as $row)
{
$fields=explode(",",$row);//comma if csv; /t(tab) if tab demilted.
echo "$fields[0] ";//instead of echoing the fileds, you should prepare the mysql insert query
echo "$fields[1] ";
echo 
"$fields[2] ";
echo 
"<br>";
}
?>
PS: I have written this code fro MySQL, but it WON'T differ for MS SQL
__________________
विक्टर रॅंबो - चाणकया प्रभावित व्यक्ति

गीक होना माँगता

Last edited by victor_rambo; 20-03-2008 at 10:29 PM. Reason: Automerged Doublepost
victor_rambo is offline  
Old 20-03-2008, 10:44 PM   #3 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Excel sheet to sql server database

@OP - Do mention the language you require help in.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Closed Thread

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Sheet Doubt kunaltech Software Q&A 6 06-02-2008 12:27 AM
Funny answer sheet ravi_9793 Chit-Chat 9 15-12-2007 09:53 AM
Windows Property sheet vivekphlp Software Q&A 2 01-06-2007 02:28 PM
Getting live datas from webpage to Excel Sheet navino87 Software Q&A 3 26-02-2007 11:43 AM
Learn Excel from Mr. Excel Ramakrishnan Software Q&A 1 25-12-2006 08:27 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:55 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2