简体   繁体   中英

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

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

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. But I guess that won't cause a lot of problems.

I see a problem in your for loop. It should be like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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