reading specific column of excel into java program -


i need read specific column of excel sheet , declare variables in java. program have done reads entire content of excel sheet. need read fixed column c.

this have done:

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);         // first sheet           sheet sheet = w.getsheet(0);         data = new string[sheet.getcolumns()][sheet.getrows()];         // loop on first 10 column , lines    //     system.out.println(sheet.getcolumns() +  " " +sheet.getrows());         (int j = 0; j <sheet.getcolumns(); j++)          {             (int = 0; < sheet.getrows(); i++)              {                 cell cell = sheet.getcell(j, i);                 data[j][i] = cell.getcontents();               //  system.out.println(cell.getcontents());             }         }         (int j = 0; j < data.length; j++)          {             (int = 0; <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(); }  } 

here excel sheet,

from bowl of chits numbered /@v1@/ /@v2@/ , single chit randomly drawn. find probability chit drawn number multiple of /@v3@/ or /@ v4@/?

i need read data , matching pattern /@v1@1, need declare variables. how can this?

what can do, should first columns sheet using sheet.getcolumns() , store columns in list . can match values based on columns. or can column "c".try using below code. let me know if works.

int mastersheetcolumnindex = sheet.getcolumns();     list<string> expectedcolumns = new arraylist<string>();     (int x = 0; x < mastersheetcolumnindex; x++) {         cell celll = sheet.getcell(x, 0);         string d = celll.getcontents();         expectedcolumns.add(d);     }     linkedhashmap<string, list<string>> columndatavalues = new linkedhashmap<string, list<string>>();      list<string> column1 = new arraylist<string>();     // read values driver sheet each column     (int j = 0; j < mastersheetcolumnindex; j++) {         column1 = new arraylist<string>();         (int = 1; < sheet.getrows(); i++) {             cell cell = sheet.getcell(j, i);             column1.add(cell.getcontents());         }         columndatavalues.put(expectedcolumns.get(j), column1);     } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -