title: reading specific column of excel into java program
body: <p>I need to read specific column of an excel sheet and then declare the variables in java. The       program that I have done reads the entire content of excel sheet. But I need to read a fixed column   like C.</p>
  
  <p>This is what I have done:</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import jxl.Cell; 
  import jxl.Sheet;
  import jxl.Workbook;
  import jxl.read.biff.BiffException;
  
  public class JavaApplication4 
  {
  
  private String inputFile;
  String[][] data = null;
  public void setInputFile(String inputFile) 
  {
      this.inputFile = inputFile;
  }
  
  public String[][] read() throws IOException  
  {
      File inputWorkbook = new File(inputFile);
      Workbook w;
  
      try 
      {
          w = Workbook.getWorkbook(inputWorkbook);
          // Get the first sheet
  
  
          Sheet sheet = w.getSheet(0);
          data = new String[sheet.getColumns()][sheet.getRows()];
          // Loop over first 10 column and lines
     //     System.out.println(sheet.getColumns() +  " " +sheet.getRows());
          for (int j = 0; j &lt;sheet.getColumns(); j++) 
          {
              for (int i = 0; i &lt; sheet.getRows(); i++) 
              {
                  Cell cell = sheet.getCell(j, i);
                  data[j][i] = cell.getContents();
                //  System.out.println(cell.getContents());
              }
          }
  
         for (int j = 0; j &lt; data.length; j++) 
          {
              for (int i = 0; i &lt;data[j].length; i++) 
              {
  
                  System.out.println(data[j][i]);
              }
          } 
  
      } 
  
      catch (BiffException e) 
      {
          e.printStackTrace();
      }
  return data;
  }
  
  public static void main(String[] args) throws IOException 
  {
      JavaApplication4 test = new JavaApplication4();
      test.setInputFile("C://users/admin/Desktop/Content.xls");
      test.read();
  }
  
  }
  </code></pre>
  
  <p>Here is my excel sheet,</p>
  
  <p>From a bowl of chits numbered  <code>/@v1@/</code> to <code>/@v2@/</code> , a single chit is randomly drawn. Find the    probability that the chit drawn is a number that is a multiple of <code>/@v3@/</code> or <code>/@ v4@/</code>?</p>
  
  <p>I need to read this data and by matching the pattern <code>/@v1@1</code>, I need to declare the variables. How can I do this?</p>