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

Popular posts from this blog

Using Bottom Navigation Drawer in Android

You will learn:  Adding bottom navigation drawer Disabling shifting mode in bottom nav Prerequisite:  Should know to create a new project in Android Studio Follow the steps: 1.        Go to build.gradle (Module: app) and add the following dependency and sync the project         compile 'com.android.support:design:27.1.0' 2.        Go to the layout file and add the following xml code < android.support.design.widget.BottomNavigationView     android :id= "@+id/bottom_nav_view"     android :layout_width= "match_parent"     android :layout_height= "wrap_content"     android :layout_gravity= "start"     design :menu= "@menu/menu_bottom_nav" />   For @menu/menu_bottom_nav : <? xml version= "1.0" encoding= "utf-8" ?> < menu xmlns: android = "http://schem...