Skip to content

Latest commit

 

History

History
69 lines (56 loc) · 3.58 KB

README-EN.md

File metadata and controls

69 lines (56 loc) · 3.58 KB

SQLiteToExcel

Download

中文版 README

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.

Version history

Release Notes

How to use

1. Add Gradle dependencies

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.

4. Thanks (how to support xlsx?)

5. Precautions

  • 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.

About me