Giter Club home page Giter Club logo

sqlitetoexcel's Introduction

SQLiteToExcel

Download

English README

SQLiteToExcel 库整合了 Apache POI 和一些基本的数据库操作,使得 SQLite 和 Excel 之间相互转换更加便捷。

从 v1.0.5 版本开始,不再支持 xlsx 格式,因为 poi ooxml 库和其他一些相关的依赖太大了,体积超过了 10MB,同时开发过程中也发现 poi 对于 Android 支持不够全面,放弃 xlsx 也是挺无奈的,个人觉得 xls 格式对于我们来说已经够用。

v1.0.8 版本开始支持自定义 SQL 查询导出了。

更新历史

Release Notes

如何使用

1. 添加 Gradle 依赖

implementation 'com.liyu.tools:sqlitetoexcel:1.0.10'

2. SQLite -> Excel demo

new SQLiteToExcel
                .Builder(this)
                .setDataBase(databasePath) //必须。 小提示:内部数据库可以通过 context.getDatabasePath("internal.db").getPath() 获取。
                .setTables(table1, table2) //可选, 如果不设置,则默认导出全部表。
                .setOutputPath(outoutPath) //可选, 如果不设置,默认输出路径为 app ExternalFilesDir。
                .setOutputFileName("test.xls") //可选, 如果不设置,输出的文件名为 xxx.db.xls。
                .setEncryptKey("1234567") //可选,可对导出的文件进行加密。
                .setProtectKey("9876543") //可选,可对导出的表格进行只读的保护。
                .start(ExportListener); // 或者使用 .start() 同步方法。

自定义 SQL 导出:

new SQLiteToExcel
                .Builder(this)
                .setDataBase(databasePath)
                .setSQL("select name as '名字', price as '价格' from user where name like '%小鱼%'")
                .start(ExportListener);

3. Excel -> SQLite demo

new ExcelToSQLite
                .Builder(this)
                .setDataBase(databasePath) // 可选,如果不设置,默认为 “*.xls.db”,位于内部 database 目录下。
                .setAssetFileName("user.xls") // 如果文件在 asset 目录。
                .setFilePath("/storage/doc/user.xls") // 如果文件在其他目录。
                .setDecryptKey("1234567") // 可选,如果需要解密文档
                .setDateFormat("yyyy-MM-dd HH:mm:ss") // 可选,如果需要统一格式化日期单元格
                .start(ImportListener); // 或者使用 .start() 同步方法。

4. 感谢(如何支持 xlsx 可以参考以下仓库)

5. 注意事项

  • 读写外部文件时,Android 6.0 及以上版本需处理运行时权限。
  • Excel 导入 SQLite 时,默认取 excel 中 sheet 的第一行作为数据库表的列名,样式请参考 demo
  • 目前仅支持 blob 字段导出为图片,因为我也不知道 byte[] 是文件还是图片。
  • 数据库文件须位于/data/data/包名/databases/下,一般都是位于这个目录下。

联系我

sqlitetoexcel's People

Contributors

li-yu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlitetoexcel's Issues

数据量过大导致OOM

数据库里面的数据超过了10000条,调用的时候导致了OOM,请问有什么解决方案没?

数据上了几百条就无法导出了

几十条数据导出来是没问题的,但是一旦几百条后导出的excel文件大小就是0kb了,以为是在导出当中,但是等了很久也还是0kb且打不开,求大佬指教

录入出错

感谢开源,我导出时设置了密码 然后录入是没有相应的添加密码的设置,会导致录入出错

1.0.8版本setTables(String...tables)失效

1.0.8版本里
public String start() {
try {
if (tables == null || tables.size() == 0) {
tables = getTablesName(database);
}
return exportTables(getTablesName(database), fileName);
} catch (Exception e) {
if (database != null && database.isOpen()) {
database.close();
}
return null;
}
}
return 的永远是所有的表

数据导入可以查重吗?

大神,比如我数据库已经有数据了,我现在再导入数据,可以不把一样的数据再导入添加吗?谢谢

如何插入图片到excel?

把图片用blob格式存入sqlite,如何导入到excel里面?直接导入会报错说blob不是string类型,有办法将图片插入到生成的excel里面吗

importing .xls file

exception stating sup[lied data appears to be in the Office2007+ XML. and that the part of POI that gets called is the one dealing with OLE2 Office Documents.
the exception suggests to call different part of POI and gives an example
XSSF instead of HSSF

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.