Giter Site home page Giter Site logo

sqlitetoexcel's Introduction

SQLiteToExcel

Download

English README

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

更新历史

2017-03-31 : v1.0.3

  • 新增 Excel 导入 SQLite 数据库的功能

2017-03-28 : v1.0.2

  • 上传到 JCenter

2017-03-24 : v1.0.2

  • 解决 blob 字段导出报错的 bug
  • 目前仅支持 blob 字段导出为图片
  • Apache POI 版本同步更新到 v3.15

2015-12-25 : v1.0.1

  • 可以设置导出目录,默认为内部SD卡根目录
  • Apache POI 版本同步更新到 v3.13

主要功能

  • SQLite <-> Excel 相互转换

如何使用

1.添加 Gradle 依赖或者下载 Jar 文件作为 libs 添加到工程中

compile 'com.liyu.tools:sqlitetoexcel:1.0.3'

SqliteToExcel-v1.0.3.jar

2.添加 SD 卡读写权限到 AndroidManifest.xml(Android 6.0 及以上需要处理运行时权限)

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

3.SQLite -> Excel 示例代码(具体示例可参考 demo 工程)

  • 初始化(默认导出路径为外部 SD 卡根目录 Environment.getExternalStorageDirectory()
SqliteToExcel ste = new SqliteToExcel(this, "helloworld.db");

或(指定导出的根目录)

SqliteToExcel ste = new SqliteToExcel(this, "helloworld.db", "/mnt/sdcard/myfiles/");
  • 导出单个表到 excel
ste.startExportSingleTable(String table, String fileName, ExportListener listener);
  • 导出多个表到 excel
ste.startExportTables(List<String> tables, String fileName, ExportListener listener);
  • 导出所有表到 excel
ste.startExportAllTables(String fileName, ExportListener listener);
  • 任务监听器接口
public interface ExportListener {
        void onStart();

        void onCompleted(String filePath);

        void onError(Exception e);
    }

4.Excel -> SQLite 示例代码(具体示例可参考 demo 工程)

  • 初始化
ExcelToSqlite ets = new ExcelToSqlite(this, "user.db");
  • 从 assets 目录传入 excel 文件
ets.startFromAsset(String assetFileName, ImportListener listener);
  • 以 File 形式传入任意 excel 文件
ets.startFromFile(File file, ImportListener listener);
  • 任务监听器接口
public interface ImportListener {
        void onStart();

        void onCompleted(String dbName);

        void onError(Exception e);
    }

5.注意事项

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

关于我

sqlitetoexcel's People

Contributors

li-yu avatar

Watchers

Rocky avatar  avatar

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.