Linker IT Software
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
Uploading Data From Excel To A Database Table (Read 5329 times)
YaBB Newbies


Posts: 1
Uploading Data From Excel To A Database Table
27.04.06 at 04:11:02
I have been trying to upload data from an excel sheet to a database(PostgreSQL) table. Can someone please help me do this.very urgent.I am looking out for the code in PHP.thanks in advance.
Back to top
  IP Logged
Gerrit-Jan Linker
YaBB Administrator

Posts: 75
Re: Uploading Data From Excel To A Database Table
Reply #1 - 27.04.06 at 09:20:35
Loading data into a PostgreSQL table from Excel you need to use SQL*XL's insert multiple rows feature. To automate this process, just switch on the Excel macro recorder. The recorded code will look something like this:
Sub Macro1()
  SQLXL.InsertRecordset Table:="account" _
  , Columns:="BALANCE,ACCOUNTNO" _
  , DataRange:=Range("$A$2:$B$6") _
  , PromptOnError:=False _
  , SortToStatus:=True _
  , CommitFrequency:=50 _
  , Orientation:=1 _
  , Silent:=True _
  , Feedback:=True
End Sub

Now, to do this from PHP you need to use the OLE features of PHP (I think PHP can do this but I am not 100% sure) to start Excel and open a .xls file in which you have saved the above macro code. The easiest is if you also record the logging on to the database into a macro. To start the process when you open the macro workbook code a call to your macro in the Workbook_Open event. If you code a second line in this event to close Excel when the insert is done you have completed the task.
Again, I don't know how easy - or desirable - this would be from PHP. Why not use Excel and schedule the running of the macro workbook in the Windows scheduler?
Back to top
« Last Edit: 27.04.06 at 09:23:45 by Gerrit-Jan Linker »  

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1