appsfeature / exporter-lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

exporter-lite

Export support in following format: (txt, csv, xls)

  1. Text file
  2. CSV file
  3. Excel file

Library Size : 527KB

Setup

Add this to your project build.gradle

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Dependency

dependencies {
    implementation 'com.github.appsfeature:exporter-lite:x.y'
}

In your activity class:

Prepare List for this library

    public static List<List<String>> getExporterList() {
        List<User> yourList = new ArrayList<>();
        yourList.add(new User("01","Alpha"));
        yourList.add(new User("02","Bita"));

        //add header in your exporting list
        yourList.add(0, new User("Id","Name"));

        //make exporter list
        List<List<String>> exporterList = new ArrayList<>();
        for (User item : yourList){
            exporterList.add(Arrays.asList(item.getId(),item.getName()));
        }
        return exporterList;
    }

Get Sample List

    List<List<String>> exporterList = ExportSample.getExporterList(); 

In your activity class:

Export in Text file

    Exporter.getInstance().TextBuilder(this)
            .setFileName("SampleText")
            .setData(new ExporterData("Hello World!"))
            .setListener(new ExporterCallback<File>() {
                @Override
                public void onSuccess(File result) {
                    ExporterShare.shareFile(MainActivity.this, result);
                }

                @Override
                public void onFailure(Exception e) {
                    Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }).export();

Export in CSV file

    Exporter.getInstance().CsvBuilder(this)
            .setFileName("SampleCsv")
            .setData(new ExporterData(body, false))
            .setListener(new ExporterCallback<File>() {
                @Override
                public void onSuccess(File result) {
                    ExporterShare.shareFile(MainActivity.this, result);
                }

                @Override
                public void onFailure(Exception e) {
                    Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }).export();

Export in Excel file

    Exporter.getInstance().ExcelBuilder(this)
            .setFileName("SampleExcel")
            .setData(new ExporterData(body, true))
            .setListener(new ExporterCallback<File>() {
                @Override
                public void onSuccess(File result) {
                    ExporterShare.shareFile(MainActivity.this, result);
                }

                @Override
                public void onFailure(Exception e) {
                    Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();

                }
            }).export();

For showing list of files.

    Exporter.getInstance().showListOfFiles(this, new ExporterSelector<File>() {
        @Override
        public void onSelect(File result) {
            ExporterShare.shareFile(MainActivity.this, result);
        }
    });

For clear list of files.

    Exporter.getInstance().clearListOfFiles(this);

ChangeLog

Version 1.0:

  • Initial build
  • Library Size
  • Supported format 'txt, csv, xls'
  • compileSdkVersion 30
  • Library : poi-3.17.jar

About


Languages

Language:Java 100.0%