使用按钮来源码数据库导出到Excel可读的文件(或许CSV)? [英] Using a button to export sqlite db to an excel-readable file (perhaps csv)?

查看:200
本文介绍了使用按钮来源码数据库导出到Excel可读的文件(或许CSV)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我适应这个教程(http://www.screaming-penguin.com/node/7749)到Android应用程序我已经建立了以允许按钮preSS到当前数据库中导出用户的SD卡。它完美的作品。

不过,我担心我的应用程序的用户将不熟悉的数据库文件,而我正在寻找一种方式将其转换成一个更加用户友好的格式。我碰到这个线程(http://groups.google.com/group/android-beginners/browse_thread/thread/4e53ebca14daecfc),其中建议查询数据库中的数据,并把数据写入一个CSV文件中。

我希望有人能指出我在正确的方向,开始盘算如何做到这一点。我发现它很难追查有关特定方法的详细信息。

或者它更有意义,只是在很短的解释有关如何阅读和访问db文件?

感谢

编辑:我也有一个关于sqlite的出口过程中,我想我就问这里,而不是创建一个新的问题的问题。有没有一种方法来修改下面的code,使每个出口将获得一个字符串再日期presentation或只是一个单一的数字追加到了吗?如果导出了第二次现在,它会自动覆盖旧的文件。谢谢你。

 保护布尔doInBackground(最后的字符串参数... args){

        文件DBFILE =新的文件(Environment.getDataDirectory()+
                /data/com.example.example/databases/data);

        文件exportDir =新的文件(Environment.getExternalStorageDirectory(),exampledata);

        如果(exportDir.exists()){
            exportDir.mkdirs();
        }

        档案文件=新的文件(exportDir,dbFile.getName());

        尝试 {
            file.createNewFile();
            this.copyFile(DBFILE,文件);
            返回true;
        }赶上(IOException异常E){
            Log.e(MyApplication.APP_NAME,e.getMessage(),E);
            返回false;
        }

    }
 

解决方案
  

我希望有人能指出我在正确的方向,开始盘算如何做到这一点。

要读取数据,使用 rawQuery()

要写入数据,使用的Java I / O 。此外还有打开来源 CSV库的用于Java的可能工作在Android上。

  

有没有办法修改下面的code,使每个出口将获得一个字符串再日期presentation或只是一个单一的数字追加到它?

使用字符串连接到任何你想要添加到文件名。

此外,请改掉:

 文件DBFILE =新的文件(Environment.getDataDirectory()+
                /data/com.example.example/databases/data);
 

和将其替换为:

 文件DBFILE = getDatabasePath(数据);
 

I adapted this tutorial (http://www.screaming-penguin.com/node/7749) to an Android app I've built to allow for a button press to export the current database to the user's sdcard. It works flawlessly.

But I'm afraid that users of my app would be unfamiliar with the db file, and I'm looking for a way to convert that to a more user-friendly format. I came across this thread (http://groups.google.com/group/android-beginners/browse_thread/thread/4e53ebca14daecfc), which recommends "querying data from the database and writing the data into a csv file."

I was hoping someone could point me in the right direction to begin figuring out how to do this. I'm finding it hard to track down more information about the specific method.

Or does it make more sense to just explain in a short "about" how to read and access .db files?

Thanks

EDIT: I also have a question about the sqlite export process, which I think I'll just ask here rather than create a new question. 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? Right now if you export a second time, it automatically overwrites the old file. Thanks.

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.

To read in the data, use rawQuery().

To write the data, use Java I/O. There are also open source CSV libraries for Java that may work on Android.

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?

Use string concatenation to add whatever you want to the filename.

Also, please get rid of:

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

and replace it with:

File dbFile=getDatabasePath("data");

这篇关于使用按钮来源码数据库导出到Excel可读的文件(或许CSV)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆