Android program to convert the SQLite database to excel

前端 未结 4 1652
逝去的感伤
逝去的感伤 2020-12-03 02:07

I want to change the sqlite database .db file to excel.

But I am not able to find what exactly I have to do. Can anybody please elabor

4条回答
  •  我在风中等你
    2020-12-03 02:53

    I know this question is a little old but it provided me with the answer to the same question. I've cleaned up the code a little and done away with the need to write a csv file altogether by getting my database helper class to return me an ArrayList. Still using Apache POI though.

    File folder =new File(Environment.getExternalStorageDirectory()+APP_FILES_PATH);
        if(!folder.exists())
        {
            folder.mkdir();
        }
        DatabaseHelper dbHelper = DatabaseHelper.getInstance(context);
        ArrayList exts = dbHelper.getExtinguisherArray(1);
    
           HSSFWorkbook hwb = new HSSFWorkbook();
            HSSFSheet sheet = hwb.createSheet("extinguishers");
            for(int x = 0; x < exts.size(); x++)
            {
                String[] arr = exts.get(x);
                HSSFRow row = sheet.createRow(x);
                for(int i = 0; i< arr.length; i++)
                {
                    HSSFCell cell = row.createCell(i);
                    String data = arr[i];
                    cell.setCellValue(data);
    
                }
            }
            FileOutputStream fileOut = new FileOutputStream(Environment.getExternalStorageDirectory()+APP_FILES_PATH+"file.xls");
            hwb.write(fileOut);
            fileOut.close();
    

提交回复
热议问题