Part One - Preview, Part Three - Creating Dynamic table UI element
To be able to read any excel sheet, I used the open source API POI found here .
"The Apache POI Project's mission is to create and maintain Java APIs for
manipulating various file formats
based upon the Office Open XML standards (OOXML) and Microsoft's
OLE 2 Compound Document format (OLE2).
In short, you can read and write MS Excel files using Java.
In addition, you can read and write MS Word and MS PowerPoint
files using Java. Apache POI is your Java Excel
solution (for Excel 97-2008). "
So here is where I harnessed the powers of POI by using the following code to extract the data - contents of the excel sheet - and the metadata - number of columns, name of each column, etc - contained in my excel file:
/*File = the excel file we uploaded<br />/ Excel = a jave class to store the table* CELL_TYPE_NUMERIC = 0
<br /> CELL_TYPE_STRING = 1
<br /> CELL_TYPE_FORMULA = 2
<br /> CELL_TYPE_BLANK = 3
<br /> CELL_TYPE_BOOLEAN = 4
<br /> CELL_TYPE_ERROR = 5
<br /> */
*
switch (type)
{
case 0 :
row_of_cells.add(String.valueOf(cell.getNumericCellValue()));
break;
case 1 :
row_of_cells.add(
new String(cell.getRichStringCellValue().getString()));
break;
case 2 :
row_of_cells.add(cell.getCellFormula() + " ");
break;
case 3 :
row_of_cells.add(new String("EmptyCell"));
break;
case 4 :
row_of_cells.add(String.valueOf(cell.getBooleanCellValue()));
break;
case 5 :
row_of_cells.add((new Byte(cell.getErrorCellValue())).toString());
break;
default :
}
}
}
* //add this row of cells into the table
*
excel.getTable().add(row_of_cells);
} //end of row !=null
}
retBool = true;
}
catch (Exception ioe)
{
ioe.printStackTrace();
return false;
}
return retBool;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
36 | |
8 | |
7 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |