Reading from a .csv and .xls file via ODBC
Posted: Thu Nov 29, 2018 3:41 am
Example:
class ReadFromFile : Test
Main()
Database csv
csv.Connect("Driver="{Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\Temp\;")
csv.Execute("select * from Report.csv")
List<List<Object>> readLines
List<Object> readLine
Boolean end = false
while(!end)
readLine = {}
csv.FetchToList(readLine)
if (readLine.Count() != 0)
readLines.Add(readLine)
else
end = true
csv.Disconnect()
Print(readLines)
Database excel
excel.Connect("Driver=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb);Dbq=C:\Temp\Report.xlsx;")
excel.Execute("select * from [Worksheet1$A1:M10]")
readLines = {}
end = false
while(!end)
readLine = {}
excel.FetchToList(readLine)
if (readLine.Count() != 0)
readLines.Add(readLine)
else
end = true
excel.Disconnect()
Print(readLines)
ATTENTION:
If you notice information lacks in the Print() statement may be you have to set up an own System DSN in the ODBC Data Source Administrator.
For the example I set up a "Microsoft Text Driver (*.txt; *.csv) DSN with directory "C:\Temp" and the format "CSV" for Tables "default" and Characters "OEM" (Rows to Scan: 25).
class ReadFromFile : Test
Main()
Database csv
csv.Connect("Driver="{Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\Temp\;")
csv.Execute("select * from Report.csv")
List<List<Object>> readLines
List<Object> readLine
Boolean end = false
while(!end)
readLine = {}
csv.FetchToList(readLine)
if (readLine.Count() != 0)
readLines.Add(readLine)
else
end = true
csv.Disconnect()
Print(readLines)
Database excel
excel.Connect("Driver=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb);Dbq=C:\Temp\Report.xlsx;")
excel.Execute("select * from [Worksheet1$A1:M10]")
readLines = {}
end = false
while(!end)
readLine = {}
excel.FetchToList(readLine)
if (readLine.Count() != 0)
readLines.Add(readLine)
else
end = true
excel.Disconnect()
Print(readLines)
ATTENTION:
If you notice information lacks in the Print() statement may be you have to set up an own System DSN in the ODBC Data Source Administrator.
For the example I set up a "Microsoft Text Driver (*.txt; *.csv) DSN with directory "C:\Temp" and the format "CSV" for Tables "default" and Characters "OEM" (Rows to Scan: 25).