SQLite Forum

Noob Question
Login
Let us suppose, you have a bunch of xls-files in `D:/xlsData` folder.<br> 
You can try to import data within sqlite-gui in an one select without CSV-step.<br>
```
select odbc_read('Driver={Microsoft Excel Driver (*.xls)};Dbq=D:\xlsData\' || line, 'select * from "Sheet1$"', line)
from exec('powershell Get-ChildItem -Path D:/xlsData -Name')
```

What happen here:<br>
<ul>
<li> `exec(command)` returns list of files in folder. Test it:<br> 
```
select line from exec('powershell Get-ChildItem -Path D:/xlsData<br> -Name')
```
</li>
<li> `odbc_read(DSN, query, target)` fetchs data from sheet1 to table named as filename for each row.</li>
</ul>

Both `exec` and `odbc_read` are only sqlite-gui abilities. Check Wiki ([link](https://github.com/little-brother/sqlite-gui/wiki#extensions)) for `odbc` and `exec` extensions.<br>
If you need to fetch data from different sheets then you can create auxilary table `aux` with columns `filename` and `sheet number`
```
select odbc_read('Driver={Microsoft Excel Driver (*.xls)};Dbq=D:\xlsData\' || line, 'select * from "'|| aux.sheet || '$"', line)
from exec('powershell Get-ChildItem -Path D:/xlsData -Name') e inner join aux on e.line = aux.filename
```

P.S. For some data `odbc_read` can be broken. It has a lack of testing.<br>
P.P.S. I'm a author of sqlite-gui :)