-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
572 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,85 +6,49 @@ | |
|
||
The SQLiteToExcel library integrates [Apache POI](http://poi.apache.org/) 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. | ||
|
||
## Version history | ||
[Release Notes](https://github.com/li-yu/SQLiteToExcel/releases) | ||
|
||
## How to use | ||
#### 1.Add Gradle dependencies or download the Jar file as libs to the project | ||
#### 1.Add Gradle dependencies | ||
``` Gradle | ||
compile 'com.liyu.tools:sqlitetoexcel:1.0.4' | ||
``` | ||
[SqliteToExcel-v1.0.4.jar](https://github.com/li-yu/SQLiteToExcel/releases) | ||
#### 2.Add SD card read and write permissions to AndroidManifest.xml (Android 6.0 and above need to deal with run-time permissions) | ||
```xml | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
compile 'com.liyu.tools:sqlitetoexcel:1.0.5' | ||
``` | ||
|
||
#### 3.SQLite -> Excel Sample code(Specific examples can be found in [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/java/com/liyu/demo/MainActivity.java)) | ||
* Initialize (Default export path is external SD card root directory ```Environment.getExternalStorageDirectory()```) | ||
```java | ||
SqliteToExcel ste = new SqliteToExcel(this, "helloworld.db"); | ||
``` | ||
or(Specifies the root directory of the export) | ||
```java | ||
SqliteToExcel ste = new SqliteToExcel(this, "helloworld.db", "/mnt/sdcard/myfiles/"); | ||
``` | ||
* Export a single table to excel | ||
```java | ||
ste.startExportSingleTable(String table, String fileName, ExportListener listener); | ||
``` | ||
* Export multiple tables to excel | ||
```java | ||
ste.startExportTables(List<String> tables, String fileName, ExportListener listener); | ||
``` | ||
* Export all tables to excel | ||
```java | ||
ste.startExportAllTables(String fileName, ExportListener listener); | ||
``` | ||
* Task listener interface | ||
#### 2.SQLite -> Excel Sample code(Specific examples can be found in [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/java/com/liyu/demo/MainActivity.java)) | ||
```java | ||
public interface ExportListener { | ||
void onStart(); | ||
|
||
void onCompleted(String filePath); | ||
|
||
void onError(Exception e); | ||
} | ||
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. | ||
.setPath(outoutPath) //Optional, if null, default output path is app ExternalFilesDir. | ||
.setFileName("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. | ||
``` | ||
|
||
#### 4.Excel -> SQLite Sample code(Specific examples can be found in [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/java/com/liyu/demo/MainActivity.java)) | ||
* Initialize | ||
#### 3.Excel -> SQLite Sample code(Specific examples can be found in [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/java/com/liyu/demo/MainActivity.java)) | ||
```java | ||
ExcelToSqlite ets = new ExcelToSqlite(this, "user.db"); | ||
``` | ||
* From the assets directory | ||
```java | ||
ets.startFromAsset(String assetFileName, ImportListener listener); | ||
``` | ||
* For any excel files | ||
```java | ||
ets.startFromFile(File file, ImportListener listener); | ||
``` | ||
* Task listener interface | ||
```java | ||
public interface ImportListener { | ||
void onStart(); | ||
|
||
void onCompleted(String dbName); | ||
|
||
void onError(Exception e); | ||
} | ||
new ExcelToSQLite | ||
.Builder(this) | ||
.setDataBase(databasePath) //Required. | ||
.setAssetFileName("user.xls") // if it is a asset file. | ||
.setFilePath("/storage/doc/user.xls") // if it is a normal file. | ||
.start(ImportListener); // or .start() for synchronous method. | ||
``` | ||
|
||
#### 5.Thanks | ||
#### 4.Thanks (how to support xlsx?) | ||
- [https://github.com/centic9/poi-on-android](https://github.com/centic9/poi-on-android) | ||
- [https://github.com/FasterXML/aalto-xml](https://github.com/FasterXML/aalto-xml) | ||
- [https://github.com/johnrengelman/shadow](https://github.com/johnrengelman/shadow) | ||
|
||
#### 6.Precautions | ||
* When convert Excel to SQLite,the default take excel sheet in the first row as the database table column name, please refer to the style [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/assets/user.xls). | ||
#### 5.Precautions | ||
* When convert Excel to SQLite, take excel sheet first row as the database table column name, please refer to the style [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/assets/user.xls). | ||
* 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. | ||
* ~~The database files must be located under ```/data/data/package name/databases/` ``, and are usually located in this directory.~~ | ||
|
||
## About me | ||
* Email: [[email protected]](mailto:[email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,87 +4,51 @@ | |
|
||
[English README](README-EN.md) | ||
|
||
SQLiteToExcel 库整合了 [Apache POI](http://poi.apache.org/) 和一些基本的数据库查询操作,使得 SQLite 和 Excel 之间相互转换更加便捷。 | ||
SQLiteToExcel 库整合了 [Apache POI](http://poi.apache.org/) 和一些基本的数据库操作,使得 SQLite 和 Excel 之间相互转换更加便捷。 | ||
|
||
从 v1.0.5 版本开始,不再支持 **xlsx 格式**,因为 poi ooxml 库和其他一些相关的依赖太大了,体积超过了 10MB,同时开发过程中也发现 poi 对于 Android 支持不够全面,放弃 xlsx 也是挺无奈的,个人觉得 xls 格式对于我们来说已经够用。 | ||
|
||
## 更新历史 | ||
[Release Notes](https://github.com/li-yu/SQLiteToExcel/releases) | ||
|
||
## 如何使用 | ||
#### 1.添加 Gradle 依赖或者下载 Jar 文件作为 libs 添加到工程中 | ||
#### 1.添加 Gradle 依赖 | ||
``` Gradle | ||
compile 'com.liyu.tools:sqlitetoexcel:1.0.4' | ||
``` | ||
[SqliteToExcel-v1.0.4.jar](https://github.com/li-yu/SQLiteToExcel/releases) | ||
#### 2.添加 SD 卡读写权限到 AndroidManifest.xml(Android 6.0 及以上需要处理运行时权限) | ||
```xml | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
compile 'com.liyu.tools:sqlitetoexcel:1.0.5' | ||
``` | ||
|
||
#### 3.SQLite -> Excel 示例代码(具体示例可参考 [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/java/com/liyu/demo/MainActivity.java) 工程) | ||
* 初始化(默认导出路径为外部 SD 卡根目录 ```Environment.getExternalStorageDirectory()```) | ||
```java | ||
SqliteToExcel ste = new SqliteToExcel(this, "helloworld.db"); | ||
``` | ||
或(指定导出的根目录) | ||
```java | ||
SqliteToExcel ste = new SqliteToExcel(this, "helloworld.db", "/mnt/sdcard/myfiles/"); | ||
``` | ||
* 导出单个表到 excel | ||
```java | ||
ste.startExportSingleTable(String table, String fileName, ExportListener listener); | ||
``` | ||
* 导出多个表到 excel | ||
```java | ||
ste.startExportTables(List<String> tables, String fileName, ExportListener listener); | ||
``` | ||
* 导出所有表到 excel | ||
```java | ||
ste.startExportAllTables(String fileName, ExportListener listener); | ||
``` | ||
* 任务监听器接口 | ||
```java | ||
public interface ExportListener { | ||
void onStart(); | ||
|
||
void onCompleted(String filePath); | ||
|
||
void onError(Exception e); | ||
} | ||
new SQLiteToExcel | ||
.Builder(this) | ||
.setDataBase(databasePath) //必须。 小提示:内部数据库可以通过 context.getDatabasePath("internal.db").getPath() 获取。 | ||
.setTables(table1, table2) //可选, 如果不设置,则默认导出全部表。 | ||
.setPath(outoutPath) //可选, 如果不设置,默认输出路径为 app ExternalFilesDir。 | ||
.setFileName("test.xls") //可选, 如果不设置,输出的文件名为 xxx.db.xls。 | ||
.setEncryptKey("1234567") //可选,可对导出的文件进行加密。 | ||
.setProtectKey("9876543") //可选,可对导出的表格进行只读的保护。 | ||
.start(ExportListener); // 或者使用 .start() 同步方法。 | ||
``` | ||
|
||
#### 4.Excel -> SQLite 示例代码(具体示例可参考 [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/java/com/liyu/demo/MainActivity.java) 工程) | ||
* 初始化 | ||
```java | ||
ExcelToSqlite ets = new ExcelToSqlite(this, "user.db"); | ||
``` | ||
* 从 assets 目录传入 excel 文件 | ||
```java | ||
ets.startFromAsset(String assetFileName, ImportListener listener); | ||
``` | ||
* 以 File 形式传入任意 excel 文件 | ||
```java | ||
ets.startFromFile(File file, ImportListener listener); | ||
``` | ||
* 任务监听器接口 | ||
```java | ||
public interface ImportListener { | ||
void onStart(); | ||
|
||
void onCompleted(String dbName); | ||
|
||
void onError(Exception e); | ||
} | ||
new ExcelToSQLite | ||
.Builder(this) | ||
.setDataBase(databasePath) //必须。 | ||
.setAssetFileName("user.xls") // 如果文件在 asset 目录。 | ||
.setFilePath("/storage/doc/user.xls") // 如果文件在其他目录。 | ||
.start(ImportListener); // 或者使用 .start() 同步方法。 | ||
``` | ||
|
||
#### 5.感谢 | ||
#### 4.感谢(如何支持 xlsx 可以参考以下仓库) | ||
- [https://github.com/centic9/poi-on-android](https://github.com/centic9/poi-on-android) | ||
- [https://github.com/FasterXML/aalto-xml](https://github.com/FasterXML/aalto-xml) | ||
- [https://github.com/johnrengelman/shadow](https://github.com/johnrengelman/shadow) | ||
|
||
#### 6.注意事项 | ||
#### 5.注意事项 | ||
* Excel 导入 SQLite 时,默认取 excel 中 sheet 的**第一行**作为数据库表的列名,样式请参考 [demo](https://github.com/li-yu/SQLiteToExcel/blob/master/app/src/main/assets/user.xls)。 | ||
* 目前仅支持 blob 字段导出为图片,因为我也不知道 byte[] 是文件还是图片。 | ||
* 数据库文件须位于```/data/data/包名/databases/```下,一般都是位于这个目录下。 | ||
* ~~数据库文件须位于```/data/data/包名/databases/```下,一般都是位于这个目录下。~~ | ||
|
||
## 关于我 | ||
* Email: [[email protected]](mailto:[email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.