Skip to main content

Converting SQLite database into excel file



You will learn:

·         To export the SQLite database into excel file

Prerequisite:

·         You should have knowledge of SQLite database

Follow the steps:

1.       Add the dependency in build.gradle and sync your project
api 'com.ajts.androidmads.SQLite2Excel:library:1.0.1'

2.       Add the permission in AndroidManifest.xml file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

3.       Specify the path where you want to store the excel file
String path  = Environment.getExternalStorageDirectory().getPath() + "/Backup/";
File file = new File(path);
if (!file.exists()) {
    file.mkdirs();
}

4.       Instantiate the SQLiteToExcel library with context, database name and path of the file to be stored in your activity or fragment
SQLiteToExcel sqLiteToExcel = new SQLiteToExcel(getApplicationContext(), "guestinfo.db", path);
sqLiteToExcel.exportAllTables(
"guestInfo.xls", new SQLiteToExcel.ExportListener() {
   
@Override
   
public void onStart() {
    }

   
@Override
   
public void onCompleted(String filePath) {
        Toast.makeText(getApplicationContext(),
"Success", Toast.LENGTH_SHORT).show();
    }

   
@Override
   
public void onError(Exception e) {
        Toast.makeText(getApplicationContext(), e.toString(), Toast.
LENGTH_SHORT).show();
    }

Result:

You are now ready to export the SQLite database file as a excel file

Comments