Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
oExcel=GETOBJECT(,"Excel.Application")
oExcel.ActiveWorkBook.SaveAs("C:\CSVData\data.csv",23)
SELECT import
APPEND FROM ("C:\CSVData\data.csv") TYPE CSV
oCA = CREATEOBJECT("CursorAdapter")
WITH oCA
.Alias = "tranfile"
.DataSourceType = "ADO"
oConn = NEWOBJECT("adodb.connection")
WITH oConn
.ConnectionString = [Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\path\to\your\sheet.xlsx';Extended Properties="Excel 12.0;HDR=YES;"]
.Open( )
oRS = .Execute( "SELECT * FROM [Sheet1$]" )
lnNumFields = oRS.Fields.Count
ENDWITH
IF .CursorFill(,,,oRS)
GO BOTTOM && This speeds up the translation
ELSE
AERROR(laError)
m.oktocontinue = .F.
**** ERROR PROCESSING HERE
ENDIF
.CursorDetach
ENDWITH
LOCAL lcXLBook AS STRING, lnSQLHand AS INTEGER, ;
lcSQLCmd AS STRING, lnSuccess AS INTEGER, ;
lcConnstr AS STRING
CLEAR
lcXLBook = [C:\GENERAL\AB.xlsx]
lcConnstr = [Driver=] + ;
[{Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};] + ;
[DBQ=] + lcXLBook
IF !FILE( lcXLBook )
? [Excel file not found]
RETURN .F.
ENDIF
lnSQLHand = SQLSTRINGCONNECT( lcConnstr )
SQLExec(lnSQLHand , "Select * FROM 'Sheet1$'" ,'xlResults')
? [SQL Cmd Success:], IIF( xlResults > 0, 'Good!', 'Failed' )
IF xlResults < 0
LOCAL ARRAY laErr[1]
AERROR( laErr )
? laErr(3)
SQLDISCONNECT( lnSQLHand )
RETURN .F.
ENDIF
SELECT xlResults
BROWSE NOWAIT
SQLDISCONNECT( lnSQLHand )
SQLExec(lnSQLHand , "Select * FROM 'Sheet1$'" ,'xlResults')
lnSQLHand = SQLSTRINGCONNECT( lcConnstr )
IF lnSQLHand < 0
AERROR(laError)
* laError(1) now contains the error number;
* laError(2) contains the text of the error message
ELSE
* Connection handle OK
* Rest or your code goes here
ENDIF
lnSQLHand = SQLSTRINGCONNECT( lcConnstr )
IF lnSQLHand < 0
AERROR(laError)
* laError(1) now contains the error number;
* laError(2) contains the text of the error message
Suspend
* Now open up the debugger and inspect laError in the locals window, for example.
ELSE
* Connection handle OK
* Rest or your code goes here
[highlight #FCE94F]lnResult =[/highlight] SQLExec(lnSQLHand , "Select * FROM 'Sheet1$'" ,'xlResults')
? [SQL Cmd Success:], ICASE( [highlight #FCE94F]lnResult [/highlight] < 0, 'Failed', lnResult=0,'Still Processing','Good!' )
IF lnResult < 0
LOCAL ARRAY laErr[1]
AERROR( laErr )
? laErr(1),laErr(2),laErr(3)
SQLDISCONNECT( lnSQLHand )
RETURN .F.
ENDIF
SELECT xlResults
BROWSE NOWAIT
SQLDISCONNECT( lnSQLHand )
ENDIF
SQLExec(lnSQLHand , "Select * FROM 'Sheet1$'" ,'xlResults')
? [SQL Cmd Success:], IIF( xlResults > 0, 'Good!', 'Failed' )