Проверка файла Excel, когда последняя запись не соответствует - PullRequest
0 голосов
/ 05 марта 2019

Я пытаюсь сопоставить два столбца файла 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);
                }

            }
...