0
即时通讯设法读取Excel表格,但即时通讯卡陷入特定的单元格和它的无限循环。我想检查天气行中的单元格是否为空,如果它不为空,它应该使用java技术继续进行并使用它。你能修改我的下面的代码并帮助我吗?试图找到单元格null或不在一个Excel中的Excel工作表
公共类的测试{
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
boolean b = false;
FileInputStream file = new FileInputStream(new File("Progress Day 8.xls"));
//Create Workbook instance holding reference to .xlsx file
HSSFWorkbook workbook = new HSSFWorkbook(file);
// System.out.println(workbook.);
//Get first/desired sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(2);
/*//sheet.
System.out.println(sheet.getTopRow());
sheet.g*/
//Iterate through each rows one by one
Iterator<HSSFRow> rowIterator = sheet.rowIterator();
System.out.println("no.of rows:"+sheet.getLastRowNum());
int i=sheet.getLastRowNum();
int j;
while (rowIterator.hasNext())
{
HSSFRow row = rowIterator.next();
//For each row, iterate through all the columns
Iterator<HSSFCell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
HSSFCell cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType())
{
case HSSFCell.CELL_TYPE_NUMERIC:
break;
case HSSFCell.CELL_TYPE_STRING:
{
if(cell.getStringCellValue().equalsIgnoreCase("add"))
{
System.out.println("action");
System.out.println("cellnu:"+cell.getCellNum());
System.out.println("row nu:"+row.getRowNum());
/*
while(cellIterator.hasNext())
{
if(cell.getCellNum()!=8||cell.getCellNum()!=9||cell.getCellNum()!=10||cell.getCellNum()!=13||cell.getCellNum()!=14)
{
if(cell!=null)
{
System.out.println("row:"+row.getRowNum()+ "cell"+cell.getCellNum()+"cell not null");
}
else
{
System.out.println("cell is null");
}
}
else
{
System.out.println("row:"+row.getRowNum()+ "cell"+cell.getCellNum()+"is an exception");
}
}*/
}
else
{
System.out.println("break");
}
break;
}
}
}
}
}
}
你能显示样本输入/预期输出吗? – Sionnach733
检查“”,“”和空。不要只检查null .. – TheLostMind