import java.io.*;
import javax.swing.*;
import jxl.*; 
import jxl.write.*;
import jxl.format.*;
import java.io.File;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.swing.filechooser.*;
import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.text.*;
import java.util.Locale;

public class excell
{
public static boolean isLetter(char x)
{ boolean x1;
  if((x>='A' && x<='Z') || (x>='a' && x<='z')) x1=true;
  else x1=false;  
  return x1;	
}

public static boolean isNumber(char x)
{ boolean x1;
  if(x>='0' && x<='9') x1=true;
  else x1=false;
  return x1;	
}

public static int charnumber(char x)
{ 
  char b1[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  char b2[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  for(int i=0;i<26;i++)
  {if(x==b1[i] || x==b2[i]) return i;}
  return 0;
}

public static int[] excelcode(String s)
{int len = s.length();
 int n[]=new int[2];
 String s1="";
 char a[]=new char[len];
 int n1[]=new int[2];
 for(int i=0;i<len;i++)
 {a[i]=s.charAt(i);
 }
 if(isLetter(a[0]) && isLetter(a[1]))
 {
 n1[0]=(charnumber(a[0])+1)*26+charnumber(a[1]);
 for(int i=2;i<len;i++) s1+=a[i];
 }
 else
 {n1[0]=charnumber(a[0]);
 for(int i=1;i<len;i++) s1+=a[i];
 }
 n1[1]=Integer.parseInt(s1)-1;
 return n1;
}

public static double[][] read_double_from_excel(String filename, int pageno,String xy0,String xyn)
{int n0[]=excelcode(xy0);
 int n1[]=excelcode(xyn);
 int nx=n1[0]-n0[0]+1;
 int ny=n1[1]-n0[1]+1;
 System.out.println("nx="+nx+"ny="+ny);
 return read_double_from_excel(filename,pageno,n0[0],n0[1],nx,ny);
}
public static double[][] read_double_from_excel(String filename, int pageno,String xy0,int nx,int ny)
{int n0[]=excelcode(xy0);
 return read_double_from_excel(filename,pageno,n0[0],n0[1],nx,ny);
}
public static double[][] read_double_from_excel(String filename, int pageno,int x0,int y0,int nx,int ny)
{
double a[][]=new double[nx][ny];
try{
  File f=new File(filename);
  //excell girdi dosyası	  
  jxl.Workbook workbook = jxl.Workbook.getWorkbook(f);
  int nos=workbook.getNumberOfSheets();
  Sheet sheet= workbook.getSheet(pageno);
  Cell a1 = sheet.getCell(x0,y0);
  NumberCell nc = (NumberCell) a1;
  for(int i=0;i<nx;i++)
  { for(int j=0;j<ny;j++)
   {  a1 = sheet.getCell(x0+i,y0+j);
      nc = (NumberCell) a1;
      a[i][j] = nc.getValue();
   }
 
  }
}catch(jxl.read.biff.BiffException be) {System.err.println("BiffException");}
catch(IOException bio) {System.err.println("Input output exception");}
  return a;
}

public static void main(String args[]) throws IOException
{
 double a[][]=read_double_from_excel("a.xls",2,"D1",2,40);
 System.out.println(Matrix.toStringT(a));
 Plot pp=new Plot(a);
 pp.plot(); 
 }
}