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;
公共课座位{
@SuppressWarnings("unchecked")
public void readExcelFile(String fileName) {
List cellData = new ArrayList();
try {
FileInputStream fis = new FileInputStream(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
&LT;% String file = request.getParameter(“text1”); String cont = SeatingBean.process(file);
out.println(cont);
%GT;
类型不匹配错误请检查并解决此问题
答案 0 :(得分:0)
您可能在Seat.jsp中遇到错误:
SeatingBean.process(file);
应该是
SeatingBean.readExcelFile(file);
然后readExcelFile(...)也应返回带有Excel文件结果的String值。但另一种解决方案是返回List并迭代jsp页面中的列表。如,
public List readExcelFile(String fileName) {
...
return cellData;
}
和Seat.jsp
<%
String file = request.getParameter("text1");
List cellData = SeatingBean.readExcelFile(file);
Iterator i = cellData.iterator();
while (i.hasNext()) {
%>
<%= ""+i.next() %><br/>
<%
}
%>