//This function reads data from excel and returns as hash table
public static Object[][] getData(String sheetName,Xls_Reader xls){
int rowCount = xls.getRowCount(sheetName)-1;
int columnCount=xls.getColumnCount(sheetName);
System.out.println("rowCount="+rowCount);
int c=0;
for(int k=2;k<rowCount+2;k++){
if(!xls.getCellData(sheetName, 0, k).equalsIgnoreCase("Y"))
c++;
}
int d=0;
int row=rowCount-c;
System.out.println(row+"--"+columnCount);
Object[][] data = new Object[row][1];
Hashtable<String,String> table=null;
for(int i=2;i<=rowCount+1;i++){
if(xls.getCellData(sheetName, 0, i).equalsIgnoreCase("Y")){
table=new Hashtable<String,String>();
for(int j=0;j<columnCount;j++){
String key=xls.getCellData(sheetName, j, 1).trim();
String val=xls.getCellData(sheetName, j, i).trim();//.split(",")[0];
//System.out.println(key+"--"+val);
table.put(key, val);
}
//System.out.println(d);
data[d][0]=table;
d++;
}
}
return data;
}
public static Object[][] getData(String sheetName,Xls_Reader xls){
int rowCount = xls.getRowCount(sheetName)-1;
int columnCount=xls.getColumnCount(sheetName);
System.out.println("rowCount="+rowCount);
int c=0;
for(int k=2;k<rowCount+2;k++){
if(!xls.getCellData(sheetName, 0, k).equalsIgnoreCase("Y"))
c++;
}
int d=0;
int row=rowCount-c;
System.out.println(row+"--"+columnCount);
Object[][] data = new Object[row][1];
Hashtable<String,String> table=null;
for(int i=2;i<=rowCount+1;i++){
if(xls.getCellData(sheetName, 0, i).equalsIgnoreCase("Y")){
table=new Hashtable<String,String>();
for(int j=0;j<columnCount;j++){
String key=xls.getCellData(sheetName, j, 1).trim();
String val=xls.getCellData(sheetName, j, i).trim();//.split(",")[0];
//System.out.println(key+"--"+val);
table.put(key, val);
}
//System.out.println(d);
data[d][0]=table;
d++;
}
}
return data;
}
No comments:
Post a Comment