The SQLiteToExcel library integrates Apache POI and some basic database query operations, making it easier to convert between SQLite and Excel.
From v1.0.5, not support xlsx format any more, because poi ooxml lib and other dependencies are so big( > 10 MB), and there are some strange problems on Android.
From v1.0.8, support custom SQL query.
compile 'com.liyu.tools:sqlitetoexcel:1.0.10'
2. SQLite -> Excel demo
new SQLiteToExcel
.Builder(this)
.setDataBase(databasePath) //Required. Tips: internal database path can be got by context.getDatabasePath("internal.db").getPath()
.setTables(table1, table2) //Optional, if null, all tables will be export.
.setOutputPath(outoutPath) //Optional, if null, default output path is app ExternalFilesDir.
.setOutputFileName("test.xls") //Optional, if null, default output file name is xxx.db.xls
.setEncryptKey("1234567") //Optional, if you want to encrypt the output file.
.setProtectKey("9876543") //Optional, if you want to set the sheet read only.
.start(ExportListener); // or .start() for synchronous method.
Custom SQL:
new SQLiteToExcel
.Builder(this)
.setDataBase(databasePath)
.setSQL("select name as USER_NAME, price as USER_PRICE from user where name like '%FRANK%'")
.start(ExportListener);
3. Excel -> SQLite demo
new ExcelToSQLite
.Builder(this)
.setDataBase(databasePath) // Optional, default is "*.xls.db" in internal database path.
.setAssetFileName("user.xls") // if it is a asset file.
.setFilePath("/storage/doc/user.xls") // if it is a normal file.
.setDecryptKey("1234567") // Optional, if need to decrypt the file.
.setDateFormat("yyyy-MM-dd HH:mm:ss") // Optional, if need to format date cell.
.start(ImportListener); // or .start() for synchronous method.
- https://github.com/centic9/poi-on-android
- https://github.com/FasterXML/aalto-xml
- https://github.com/johnrengelman/shadow
- When read or write external file, Android 6.0 and above need to deal with run-time permissions.
- When convert Excel to SQLite, take excel sheet first row as the database table column name, please refer to the style demo.
- Currently only blob field is supported as a picture, because I do not know whether byte [] is a file or a picture.
The database files must be located under ```/data/data/package name/databases/` ``, and are usually located in this directory.
- Email: [email protected]
- Weibo: @呵呵小小鱼