Error in reading array list from beans
import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Seating {
@SuppressWarnings("unchecked")
public void readExcelFile(String fileName) {
List cellData = new ArrayList();
try {
FileInputStream fis = new File开发者_开发问答InputStream(fileName);
XSSFWorkbook xwb = new XSSFWorkbook(fis);
XSSFSheet sheet = xwb.getSheetAt(0);
Iterator rowIterator = sheet.rowIterator();
while (rowIterator.hasNext()) {
XSSFRow xrow = (XSSFRow) rowIterator.next();
Iterator iterator = xrow.cellIterator();
List cellTempList = new ArrayList();
while (iterator.hasNext()) {
XSSFCell xcell = (XSSFCell) iterator.next();
cellTempList.add(xcell);
}
cellData.add(cellTempList);
}
} catch (Exception e) {
e.printStackTrace();
}
process(cellData);
}
@SuppressWarnings("unchecked")
public void process(List cellData) {
for (int i = 0; i < cellData.size(); i++) {
List cellTempList = (List) cellData.get(i);
for (int j = 0; j < cellTempList.size(); j++) {
XSSFCell xCell = (XSSFCell) cellTempList.get(j);
String stringCellValue = xCell.toString();
System.out.print(stringCellValue + "\t");
}
System.out.println();
}
}
public static void main(String[] args) {
String fileName = "C:" + File.separator + "Documents and Settings"
+ File.separator + "a492161" + File.separator + "Desktop"
+ File.separator + "FIMTArea.xlsx";
new SeatReconcile().readExcelFile(fileName);
}
}
Seat.htm
Seat.jsp
<% String file=request.getParameter("text1"); String cont = SeatingBean.process(file);
out.println(cont);
%>
Type mismatch error pls check and solve this
You probably have an error in the Seat.jsp:
SeatingBean.process(file);
should be
SeatingBean.readExcelFile(file);
Then readExcelFile(...) should also return a String value with the results of the Excel file. But an other solution would be to return the List and Iterate over the list in the jsp page. E.g.,
public List readExcelFile(String fileName) {
...
return cellData;
}
and in Seat.jsp
<%
String file = request.getParameter("text1");
List cellData = SeatingBean.readExcelFile(file);
Iterator i = cellData.iterator();
while (i.hasNext()) {
%>
<%= ""+i.next() %><br/>
<%
}
%>
精彩评论