title: How to read excel file from external storage in android?
body: <p>I wrote a code that will generate graph from excel file(.xls) which would work perfectly but I have to put file in assets folder . Now I want to access file from external storage .</p>
  
  <p>XML Code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.example.pratiksonigra.graphexcel.MainActivity"&gt;
  
  &lt;com.jjoe64.graphview.GraphView
      android:layout_width="wrap_content"
      android:layout_height="350dp"
      android:paddingRight="20dp"
      android:paddingLeft="20dp"
      android:id="@+id/graph1"/&gt;
  
  &lt;Button
      android:id="@+id/button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Refresh"
      android:layout_below="@+id/graph1"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="10dp" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>JAVA Code:</p>
  
  <pre><code>package com.example.pratiksonigra.graphexcel;
  import android.content.res.AssetManager;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  import com.jjoe64.graphview.GraphView;
  import com.jjoe64.graphview.series.BarGraphSeries;
  import com.jjoe64.graphview.series.DataPoint; 
  import com.jjoe64.graphview.series.LineGraphSeries;
  import java.io.InputStream;
  import jxl.Cell;
  import jxl.Sheet;
  import jxl.Workbook;
  public class MainActivity extends AppCompatActivity {
  LineGraphSeries&lt;DataPoint&gt; series;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      Button btn = (Button) findViewById(R.id.button);
      final GraphView graph = (GraphView) findViewById(R.id.graph1);
      graph.getViewport().setXAxisBoundsManual(true);
      graph.getViewport().setYAxisBoundsManual(true);
      graph.getViewport().setMinX(0);
      graph.getViewport().setMaxX(10);
      graph.getViewport().setMaxY(40);
      graph.getViewport().setMinY(0);
  
      btn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              try {
                  graph.removeAllSeries();
                  AssetManager am = getAssets();
                  InputStream is = am.open("book.xls");
                  Workbook wb = Workbook.getWorkbook(is);
                  Sheet s = wb.getSheet(0);
                  Cell z = s.getCell(0, 0);
                  int row = s.getRows();
                  int col = s.getColumns();
                  double x, y;
                  x = 0.0;
                  y = 0.0;
  
                  series = new LineGraphSeries&lt;DataPoint&gt;();
  
                  for (int i = 0; i &lt; row; i++) {
                      for (int j = 0; j &lt; col; j++) {
                          z = s.getCell(j, i);
                          if (j % 2 == 0) {
                              x = Double.parseDouble(z.getContents());
                          } else {
                              y = Double.parseDouble(z.getContents());
                          }
                      }
                      series.appendData(new DataPoint(x, y), true, 15);
                  }
                  graph.addSeries(series);
              } catch (Exception e) {
  
              }
          }
      });
  }
  
  public boolean onSupportNavigateUp() {
      finish();
      return true;
  }
  </code></pre>
  
  <p>}</p>