I wanted to read contents excel files in my web-based project(J2EE-JSP+Servlets) which are located inside the web server's folder..
So, I have made a java file, which i will call through a JSP page using JSTL library.
I need to have the path of excel sheet in that java file, so that i can read the contents of that excel sheet. The excel sheet is located in web server's folder..
Also, i will be reading the contents of excel file through POI library,, i was able to achieve this in J2SE development, is it possible here?? Sample code below--
so, with which method, i will be able to retrieve the path for the same..
Code:
POIFSFileSystem fs = null;
try {
fs = new POIFSFileSystem(new FileInputStream("**some path here of sheet**"));
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
HSSFWorkbook wb = null;
try {
wb = new HSSFWorkbook(fs);
} catch (IOException ex) {
ex.printStackTrace();
}
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell1,cell2,cell3;
int rows; // No of rows, stores the no. of rows for an excel sheet
int cols; // No of columns, stores the no. of columns for an excel sheet
rows = sheet.getPhysicalNumberOfRows();
cols = 5;
for(int r = 0; r < rows; r++) {
row = sheet.getRow(r);
if(row != null) {
cell1 = row.getCell(1);
cell2 = row.getCell(2);
cell3 = row.getCell(4);
//System.out.println(cell1.getStringCellValue()+" "+cell2.getStringCellValue()+" "+cell3.getStringCellValue());
}
}