导入java.io.File;导入java.io.FileInputStream;导入java.util.ArrayList;导入java.util.Iterator;导入java.util.List;
导入org.apache.poi.xssf.usermodel.XSSFCell;导入org.apache.poi.xssf.usermodel.XSSFRow;导入org.apache.poi.xssf.usermodel.XSSFSheet;导入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
<% String file=request.getParameter("text1");String cont =SeatingBean.process(文件);
out.println(cont);%>
类型不匹配错误,请检查并解决此问题
发布于 2011-03-16 16:39:01
您可能在Seat.jsp中有一个错误:
SeatingBean.process(file); 应该是
SeatingBean.readExcelFile(file);然后是readExcelFile(...)还应返回包含Excel文件结果的字符串值。但另一种解决方案是返回列表并迭代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/>
<%
}
%>https://stackoverflow.com/questions/5321781
复制相似问题