我正在尝试将两个Excel文件列匹配到行验证。对我来说,上一个记录不匹配。我检查了列最后一个单元格和行最后一个单元格的值是否相同,并对其进行了修整,但不确定为什么它们不匹配。
以下是我的代码:
public void matchCellValue(int totalRows, int columnIndex, String strFilePath1, String strFilePath2, int row2)
{
try
{
FileInputStream file2 = new FileInputStream(new File(strFilePath2));
XSSFWorkbook workbook2 = new XSSFWorkbook(file2);
XSSFSheet sheet2 = workbook2.getSheetAt(0);
Cell header2 = sheet2.getRow(row2).getCell(0);
FileInputStream file1 = new FileInputStream(new File(strFilePath1));
XSSFWorkbook workbook1 = new XSSFWorkbook(file1);
XSSFSheet sheet1 = workbook1.getSheet("FileLayout");
Cell header1 = sheet1.getRow(0).getCell(0);
int matchValue = 0;
for (int rowIndex = 0; rowIndex < totalRows; rowIndex++) {
matchValue = 0;
Row row = CellUtil.getRow(rowIndex+1, sheet1);
header1 = CellUtil.getCell(row, columnIndex);
header2 = sheet2.getRow(row2).getCell(rowIndex);
if (header2.toString().trim().equals(header1.toString().trim()))
{
matchValue++;
}
if (matchValue != 0) {
objReport.setValidationMessageInReport("PASS", "Requirement Sheet Value " + header1
+ " matched with the value " + header2 + " from Excel File");
} else
{
objReport.setValidationMessageInReport("FAIL", "Requirement Sheet Value " + header1
+ " is not matched with the value " + header2 + " from Excel File");
}
}
} catch (Exception e) {
objReport.setValidationMessageInReport("FAIL", "Method matchInnerText : Failed due to exception : " + e);
}
}