0
我必須檢查兩個xlsx文件的字符串是否相等必須返回該名稱,但它總是返回null,有人可以幫助我?Java excel - 比較兩個字符串
try
{
FileInputStream fisCod = new FileInputStream(pathC);
XSSFWorkbook wb = new XSSFWorkbook (fisCod);
XSSFSheet sheet = wb.getSheetAt(0);
int lastRow = sheet.getLastRowNum();
for(int i=0; i<lastRow; i++)
{
Row row = sheet.getRow(i);
Cell cell = row.getCell(jobCod);
String tmp = cell.getRichStringCellValue().getString().toLowerCase();
if (tmp.equals(jobName)) //jobName is a String
{
return tmp;
}
else
{
return null;
}
}
fisCod.close();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
什麼是null? 'row'? 'cell'? 'tmp'? 'jobName'?或者你說'tmp.equals(jobName)'總是錯誤的?你有沒有嘗試輸出值來查看任何差異? 'tmp'和'jobName'的值是什麼? – BLaZuRE
如果IF條件不滿足,您將始終得到空值。只是調試它或嘗試與equalsIgnoreCase – Reddy
與equalsIgnoreCase是相同的 –