简体   繁体   English

将数据从SQlite导出到excel

[英]export data from SQlite to excel

well guys i have already viewed many questions about this topic , none of the answers worked for me , i managed to create csv file in the external storage with the help of this answer ,tried to convert it but it is corrupted or not in the correct format 大家好,我已经查看了有关此主题的许多问题,没有一个答案对我有用,我设法借助此答案在外部存储中创建了csv文件,试图进行转换,但该文件已损坏或未正确显示格式

ArrayList<AttendRegisterObject> list ;
    MyDBHelper db = new MyDBHelper(getApplicationContext());
    list = db.ReportGetter(); 
    File exportDir = new File(Environment.getExternalStorageDirectory(), "");
    if (!exportDir.exists()) {
        exportDir.mkdirs();
    }

    File file = new File(exportDir, "mdf.csv");

    try {
        file.createNewFile();
        CSVWriter csvWrite = new CSVWriter(new FileWriter(file));   
        for (int index = 0; index < list.size(); ) {
            String arrStr[] = {String.valueOf(list.get(0))};
            csvWrite.writeNext(arrStr);

        }
        csvWrite.close();           

    } catch (IOException e) {
        e.printStackTrace();
    }

The best way to do this is to use the JXL API https://1drv.ms/f/s!AvOuIgzBSUHMicNEvKEYfkiqnfW2IQ 最好的方法是使用JXL API https://1drv.ms/f/s!AvOuIgzBSUHMicNEvKEYfkiqnfW2IQ

Download this from here. 从这里下载。

You will get the tutorial and the documentation inside the folder. 您将在文件夹中获得教程和文档。 The only set back is that this can create XLS file and not XLSX files. 唯一的缺点是,它可以创建XLS文件,而不能创建XLSX文件。 But I guess that won't cause a lot of problems. 但是我想那不会引起很多问题。

I see a problem in your for loop. 我发现您的for循环出现问题。 It should be like this: 应该是这样的:

for (int index = 0; index < list.size(); index++) {
    String arrStr[] = {String.valueOf(list.get(index))};
    csvWrite.writeNext(arrStr);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM