这是我从excel表中提取数据并对其进行排序的整个程序。在纠正错误之后,代码中仍然存在问题。 执行正常但没有显示 有人可以找出错误
package com.pack.group;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class demo {
private void readExcelFile(String fileName) {
List cellDataList = new ArrayList();
try {
FileInputStream fileInputStream = new FileInputStream(fileName);
POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream);
HSSFWorkbook workBook = new HSSFWorkbook(fsFileSystem);
HSSFSheet hssfSheet = workBook.getSheetAt(0);
Iterator rowIterator = hssfSheet.rowIterator();
while (rowIterator.hasNext()) {
HSSFRow hssfRow = (HSSFRow) rowIterator.next();
Iterator iterator = hssfRow.cellIterator();
List cellTempList = new ArrayList();
while (iterator.hasNext()) {
HSSFCell hssfCell = (HSSFCell) iterator.next();
cellTempList.add(hssfCell);
}
cellDataList.add(cellTempList);
}
} catch (Exception e) {
e.printStackTrace();
}
printToConsole(cellDataList);
} private void printToConsole(List cellDataList) {
for (int i = 0; i < cellDataList.size(); i++)
{
List cellTempList = (List) cellDataList.get(i);
if(((HSSFCell) cellTempList.get(2)).toString().equals("1")){
{
for (int j = 0; j < cellTempList.size(); j++) {
HSSFCell hssfCell = (HSSFCell) cellTempList.get(j);
String stringCellValue = hssfCell.toString();
System.out.print(stringCellValue + "\t");
}
}
}
else {
i++;
}
System.out.println();
}
}
public static void main(String[] args) {
String fileName = "D:/datasheet.xls";
new demo().readExcelFile(fileName);
}}
答案 0 :(得分:0)
这个条件应该是这样写的。
if(((HSSFCell) cellTempList.get(2)).toString().equals("1")){
//...
}
您试图将布尔值转换为HSSFCell