Google Search

How To Read Excel Sheet in Android Using jexcelApi


==>Android Application in jexcelapi through you can easily read excel sheet data and also set the data in Textview  android.

=>If You Want To Read Data To Excelsheet in Android so make Sure Follow Below Steps:-

Step  1:-
Create A new Android Project.

Step  2:- 
paste a bellow code to mainxml file.
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:id="@+id/container" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:background="#ffffff" 
 android:orientation="vertical">

    <TextView         
android:id="@+id/textView" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="Scan" 
 android:textColor="#000000" 
 android:textSize="30dp" />

    <Button 
 android:id="@+id/readdata" 
 android:layout_width="250dp" 
 android:layout_height="80dp" 
 android:layout_gravity="center" 
 android:layout_margin="10dp" 
 android:gravity="center"
 android:text="Read Data" 
 android:onClick="Read" 
 android:textSize="18dp" />

</LinearLayout>



 Step  :-3
if you not have a Assets folder then Create a Assets Folder and Paste in that a ExcelSheet.

Step   4:-
Download A jexcelapi jar file in this link to download https://sourceforge.net/projects/jexcelapi/files/
and also paste this jar file is lib direcrtory.

step  5:-
Paste bellow code to main.javafile

package com.college.barcodedemos;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.io.InputStream;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class MainActivity extends Activity {
    Button Read;
    TextView data;


    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void Read(View v) {
        //Read=(Button)findViewById(R.id.readdata);        try {
            AssetManager am = getAssets();
            InputStream is = am.open("info.xls");
            Workbook wb = Workbook.getWorkbook(is);
            Sheet s = wb.getSheet(0);
            int row = s.getRows();
            int cols = s.getColumns();
            String xx = "";
            for (int i = 0; i < row; i++) {
                for (int c = 0; c < cols; c++) {
                    Cell z = s.getCell(c, i);
                    xx = xx + z.getContents();
                }
                xx = xx + "\n";
            }
            display(xx);

        } catch (Exception e) {

        }

    }

    public void display(String Value) {
        data = (TextView) findViewById(R.id.textView);
        data.setText(Value);
    }
}

Step  6:-

Test The Output
 
Before Click Button  project  output is:-
 
android Read Excel data and set textview
 

 After Clicked Read Data Button output Display this output :-


android excel sheed data read