import an excel spreadsheet into DB

liunx

Guest
is this possible if the fields match or is there a program that I can use in php for this. I want to make a standings script to update everyday for MLB standings and I was wondering how to go about ityou can always export to a different format. never tried anything like that though, so i don't know.depending on the db and if the fields match, then you could save it ias a csv file (where values are seperated by commas)

then from there most databases will import that file. but that means you would have to delete the values in the db and then import those. unless you set it up in php to open that csv file and parse it and then update the db.

a few ways to do it.are there any programs or scripts out there that do this already. I am not to proficient in PHP and it would be MYSQLyou would have to look at <!-- w --><a class="postlink" href="http://www.hotscripts.com">www.hotscripts.com</a><!-- w --> but more than likely there isn't.thanks man, is it something that you may be able to write for me if the money was rightsorry I don't have the time right now. if you don't need it in a hurry I can write something in the next couple of days. just leave me your database table (the structure is fine) and a copy of the excel file.I know how to do this in ASP (already have very modular code for such a process), and know that it would be realy a pain in the butt in PHP.

If you want the code, I can post it.sure if you do not mind pasting the code or sending it to me at <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->,

haven't used this in a lil bit and just used it again to make sure everything was still working and it is but there are a few things to keep in mind.


  1. It's not the prettiest thing I've ever made by fair - in fact, it's quite hideous, but you're not interested in the interface, just the code
    The code is pretty simple - open both the Excel file and the SQL database and copy from Excel to SQL
    Most the code you need to look at is in UploadXLS.asp
    Range Name - these are basically the name of the Sheets in the Excel file, and they interpret into table names in the code
    Your default Range Name is basically [$Sheet1$] and only changes if the name of the Sheet has been changed
    [/list=1]

    My interface is probably more complex than you need for an example, but it does give you something to play with.

    Just mainly check out UploadXLS.asp. The other file just gets the Server/File information and loads the Server's table's fields and the XLS file's cells and asks you to relate the two. Which brings me to another good point, the first line of your xls file has to be basically column headers - this isn't a me thing, it's an ODBC thing.

    Good luck
    I'm sure you'll prolly have Q's so fire away.thanks a million and I really appreciate it. As dumb as I am I am sure that I will have a question or 2 or maybe a million. One of the top of my head is that you say that you have a working demo of this. Do you have a link that I can check out or did I read that wrong

    Thanks a bunch

    Mikeman I looked at the code and I am not really sure how to convert ASP to PHP. I am not sure if it really can be done. What is the DB that this uses, is it ODBC, I am using MYSQL. I will continue to work at it, but it all may be for nothingSee, that's the big nasty.

    I'm not sure how well PHP is at having two database connections open at one time.

    The way you have to do it is open your mySQL connection like normal and then open another Connection to the XLS file. (the latter of which I don't think is possible through PHP - maybe only ASP, but it sounds like Scoutt might know how)

    While you have both open, you have to iterate through the XLS recordset you've created and then copy each record from XLS to mySQL.

    Check with your Server Host and see if they host ASP. If they do then you could just use ASP for this purpose.

    Keep in touch.open XLS in php is not hard at all. iterate through the recordset will be the tough one. in PHP you can use COM to open excel files only if the server is windows and has a copy of excel on there.

    like I said, save the excel file as .csv and send it to me along with the structure of the db and I can write something to update the database.

    you can also try <!-- w --><a class="postlink" href="http://www.asp2php.com">www.asp2php.com</a><!-- w --> to convert that file of putts, but not sure how good it will do.If that asp2php can convert that file, then I'd be darned impressed.

    Cuz it's pretty complex...er...complicated...er...has issues...er....something.

    :smug:scoutt,

    that is the problem I do not know or I do not have the db layout yet. basically i want to have something that I can put up the nfl standings, mlb, or any sport that I want to have the standings of, that I can update everyday without paying for a feed that costs thousands of dollars a month to import. I thougt that if I had a standings.php script then I could pull the data from my DB after I updated it every morning. I would pull the data from lets say ESPN and then paste it in an excell spreadsheet and then use that as the input file. the db structure would need (i Guess):

    team
    wins
    losses
    games behind
    pct

    W L T PCT GB
    NY Jets 5 5 0 .500 2

    does this make since and the input would look something like this:

    NY Jets,5,5,.500, 2 or how ever I would copy and paste it into the spread sheet.

    does that make since

    thanks for all the helpthat is what I wanted.

    give me a few and I will come up with something.thanks man, Is it possible to just parse a site that already has the standings and use their's without having to create all that information? I thought that php could do that, I am probably wrong though!only if you have permission to do so. yes you could but that could be more work. lets take it one step at a time.Okay,
    but can the first step be like the second to last.

    It's really the only fun step.

    All the intrigue and anxiety of wondering if you make it or fall all the way back down.

    Yep, nothing beats it.I would never want to do anything without permission!!:p

    Thanks for the help you two!!ok here it is. the excel file has to be like this

    Team wins losses games behind pct
    San Fransisco12050.25
    LA Dodgers222460.25

    but as you save that file as a csv (comma seperated) file you need to take the headings out. so all you have is the data.

    then upload it to the same directory as the standings.php file. then just run the file. of cource after you made the table in the database. code for this is in the standings.php file.is there a way that I can edit or Download that into excell or save it as a CSV file.save what in excel?like if you were to go to
    msnbc nfl standings (<!-- m --><a class="postlink" href="http://www.scoreboard.msnbc.com/msnbc/main.asp?frames=0&sport=nfl&cat=ST&day=&team=&">http://www.scoreboard.msnbc.com/msnbc/m ... ay=&team=&</a><!-- m -->)

    and cut and paste the standings into a spreadsheet, if I try and save it as a csv file, it says it is the wrong format.


    I really appreciate you taking your time to help me out manyou have to copy that text and stick it in the excel file and then save that file as a xls file, just for back up that is. then do a save as and save it as a csv file. you have to establish the excel file first before saving it as a csv file.i will try it out and let you know


    thanks manUse XML!

    This is what it was designed for. An architectural-free means of describing data structures. It can be read and interpreted by Excel, databases, Word, and many more applications. You can even use an XSLT stylesheet to produce the HTML output for the page.

    Hey-ho, just thought I'd drop that one into the bubbling pot :)i have no idea how to use XML,
    Sorry man i wish I couldGuys,
    Let me input some thoughts on this as I have worked on Excel to ORACLE db in UNIX extensively and done very well;
    As in our earlier remarks, excel to ASP to db conversion takes place thru either MS-Jet Database engine or any oleDB provider (odbc );
    So i don't know anything in php; BUT if there is this supprt in eiher Microsoft Jet Engine or Ole DB Provider support then You can perhaps use it in your Connection as Provider and create your recordset and work with excel dynamically;

    RAJsure that is fine and dandy but 1. he isn't using oracle and 2 how can you make excel run in unix? and 3 he is using php as his host can't run asp.He will need to have 2 recordsets;

    1. for excel data read from; and
    2. to update/insert to antother DB to write to;
    ( ORACLE was one example;
    but it does not matter, since it is SQL;)
    You will need to have those to connections for the 2 recordsets;

    XL to ASP connection(1 above) can be done thru Ms-Jet or OLE db provider; and
    to update, I have provided a thread/Code in "UPDATE MULTIPLE ROWS" for (2 above).

    Question is what is equivalent in PHP as is in ASP to connect to XL thru Jet Engine? If at all; if not is there other way to connect to Excel from PHP; (2 above ) is possible since it is using Odbc drivers.

    thx
    RAJyes php can connect to excel but it doesn't use the ODBC drivers. it uses COM, which in a sense is ODBC when it comes down to it.

    the way that he has done it is a lot easier then trying to up excel through php.
 
Top