Page 1 of 1

how can we import data from excel to database

Posted: Thu Aug 16, 2007 5:50 am
by makana
i need a example code where we can store teh data from excel sheet onto database

Posted: Thu Aug 16, 2007 7:41 am
by feyd
Have you tried the various Excel Readers out there?

Posted: Thu Aug 16, 2007 3:57 pm
by thinsoldier
if it's just raw data and nothing else, no formatting, not graphs, not macro stuff
then just save it as a csv (comma separated value).

read the .csv with file() or file_get_contents()
http://php.net/file

file will turn the csv into an array



Code: Select all

// example:
// sun, moon, stars
// earth, fire, wind

// becomes

array
   [0] array
        [0] sun
        [1] moon
        [2] stars
  [1] array
        [0] earth
        [1] fire
        [2] wind
once you have array of data it's easy to loop through and put it all in a query.

Posted: Thu Aug 16, 2007 4:55 pm
by feyd
fgetcsv() often works better.