Here is an updated version
REM ***** BASIC *****
Sub Main
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
con =getOdbcExcelConnection("e:\Documents\CHECK_CONN.xlsx")
oStatement =con.CreateStatement()
sSQL = "SELECT * FROM [TABLE$]"
oResult = oStatement.executeQuery(sSQL)
While oResult.Next
print oResult.getString(2)
wend
End Sub
Function DBQuoteName(sName As String, oCon) As String
Dim sQuote As String
sQuote = oCon.getMetaData().getIdentifierQuoteString()
DBQuoteName = sQuote & sName & sQuote
End Function
Public Function Is64bit() As Boolean
Is64bit= SF_Platform.ArchiTecture="64bit"
SF_Platform.Dispose
End Function
Function getOleDbTextConnection(folderLoc As String) As Object
If Is64bit() Then
sURL="sdbc:ado:Provider=Microsoft.ACE.OLEDB.12.0;Data Source="& folderLoc &";Extended Properties=""Text;HDR=Yes;FORMAT=Delimited"""
Else
sURL="sdbc:ado:Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& folderLoc &";Extended Properties=""Text;HDR=Yes;FORMAT=Delimited"""
End if
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
getOleDbTextConnection = oManager.getConnection(sURL)
End Function
Function getOleDbExcelConnection(folderLoc As String) As Object
If Is64bit() Then
sURL="sdbc:ado:Provider=Microsoft.ACE.OLEDB.12.0;Data Source="& folderLoc &";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"""
Else
sURL="sdbc:ado:Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& folderLoc &";Extended Properties=""Excel 8.0;"""
End if
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
getOleDbExcelConnection = oManager.getConnection(sURL)
End Function
Function getSdbcFlatFileConnection(fileLoc As String) As Object
Dim oParms() As New com.sun.star.beans.PropertyValue
AppendProperty(oParms(), "Extension", "csv")
AppendProperty(oParms(), "HeaderLine", True)
AppendProperty(oParms(), "FieldDelimiter", ",")
AppendProperty(oParms(), "StringDelimiter", """")
sURL="sdbc:flat:" & fileLoc
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
getSdbcFlatFileConnection= oManager.getConnectionWithInfo(sURL, oParms)
End Function
Function getSdbcOdsFileConnection(fileLoc As String) As Object
sURL="sdbc:calc:" & fileLoc
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
getSdbcOdsFileConnection= oManager.getConnection(sURL)
End Function
Function getOdbcExcelConnection(fileLoc As String) As Object
If Is64bit() Then
sURL="sdbc:ado:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & fileLoc
Else
sURL="sdbc:ado:Driver={Microsoft Excel Driver (*.xls)};DBQ=" & fileLoc
End if
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
getOdbcExcelConnection = oManager.getConnection(sURL)
End Function
Function getOdbcTextConnection(folderLoc As String) As Object
If Is64bit() Then
sURL="sdbc:ado:Driver={Microsoft Access Text Driver (*.txt, *.csv)};FIL=text;Extensions=txt,csv,tab,asc;DefaultDir="& folderLoc
Else
sURL="sdbc:ado:Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="& folderLoc &";Extensions=asc,csv,tab,txt;"
End if
oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
getOdbcTextConnection = oManager.getConnection(sURL)
End Function
Function CreateProperty(sName$, oValue) As com.sun.star.beans.PropertyValue
Dim oProperty As New com.sun.star.beans.PropertyValue
oProperty.Name = sName
oProperty.Value = oValue
CreateProperty() = oProperty
End Function
Sub AppendProperty(oProperties(), sName As String, ByVal oValue)
oProperties=SF_Array.Append(oProperties(), CreateProperty(sName, oValue))
End Sub