Tuesday, May 6, 2008

Update Excel sheet from Foxpro

My client wants to get tracking number on the spreadsheet they supplied. Tracking numbers are in foxpro cursor created by exporting from Fedex software.


lca = ALIAS() && table created from Fedex Export


lcxls = GETFILE('xls')

ConnectionString = [Provider=Microsoft.Jet.OLEDB.4.0;Data Source=]+lcxls +[;Extended Properties="Excel 8.0;HDR=Yes;"]
oConn = CREATEOBJECT('adodb.Connection')
oConn.OPEN(ConnectionString)
ors = CREATEOBJECT('adodb.recordset')
ors.LockType = 3

lcsql = "select * from [Sheet1$] where track is null"
ors.OPEN(lcsql, oConn)

DO WHILE NOT ors.EOF
lcPid = TRANSFORM(ors.Fields(0).value)
SELECT (lca)
LOCATE FOR pid = lcpid
IF FOUND()
ors.FIELDS("Track").VALUE = ALLTRIM(track)
ors.FIELDS("Shipdate").VALUE = shipdate
ENDIF
ors.UPDATE()
ors.movenext()
ENDDO
ors.CLOSE()
oConn.CLOSE()

RETURN

No comments: