java - 使用按钮将 sqlite 数据库导出到 excel 可读文件(可能是 csv)?

标签 java android excel sqlite

我将本教程 (http://www.screaming-penguin.com/node/7749) 改编为我构建的 Android 应用程序,允许按下按钮将当前数据库导出到用户的 sdcard。它运行完美。

但我担心我的应用程序的用户不熟悉 db 文件,我正在寻找一种方法将其转换为对用户更友好的格式。我遇到了这个线程 (http://groups.google.com/group/android-beginners/browse_thread/thread/4e53ebca14daecfc),它建议“从数据库查询数据并将数据写入 csv 文件。”

我希望有人能给我指出正确的方向,让我开始弄清楚如何做到这一点。我发现很难找到有关特定方法的更多信息。

还是用简短的“关于”如何读取和访问 .db 文件来解释更有意义?

谢谢

编辑:我也有一个关于 sqlite 导出过程的问题,我想我只是在这里问而不是创建一个新问题。有没有办法修改下面的代码,以便每次导出都会收到日期的字符串表示形式或仅附加一个数字?现在,如果您第二次导出,它会自动覆盖旧文件。谢谢。

protected Boolean doInBackground(final String... args) {

        File dbFile = new File(Environment.getDataDirectory() + 
                "/data/com.example.example/databases/data");

        File exportDir = new File(Environment.getExternalStorageDirectory(), "exampledata");

        if (exportDir.exists()) {
            exportDir.mkdirs();
        }

        File file = new File(exportDir, dbFile.getName());

        try {
            file.createNewFile();
            this.copyFile(dbFile, file);
            return true;
        } catch(IOException e) {
            Log.e(MyApplication.APP_NAME, e.getMessage(), e);
            return false;
        }

    }

最佳答案

I was hoping someone could point me in the right direction to begin figuring out how to do this.

要读入数据,请使用 rawQuery()

要写入数据,请使用 Java I/O .还有open source CSV libraries适用于可能在 Android 上运行的 Java。

Is there a way to modify the code below so that each export would receive either a string representation of the date or just a single numeral appended to it?

使用字符串连接将您想要的任何内容添加到文件名中。

此外,请摆脱:

File dbFile = new File(Environment.getDataDirectory() + 
                "/data/com.example.example/databases/data");

并将其替换为:

File dbFile=getDatabasePath("data");

关于java - 使用按钮将 sqlite 数据库导出到 excel 可读文件(可能是 csv)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4180083/

相关文章:

java - Spring MongoDB 手册引用

java - 不可扩展的窗口

Android Studio 非常慢的 gradle 构建

java - 拦截并重新抛出 Java 未处理的异常

java - Apache XmlBeans NullPointerException

android - Android Studio 错误 : Cannot launch AVD in emulator

android - 如果按钮按下得太快,按钮单击声音 MediaPlayer 会崩溃

c# - f# 读取 xls 文件 - 如何解析 value2 对象

excel - 如何通过宏更改工作表样式?

excel - 如果标题行不包含子字符串且范围不包含 #N/A,则求和