我正在编写一个代码,我必须比较excel行之间的数据,如果我找到匹配项,我想将finalIndex
增加1,一旦找到匹配项,我需要合并单元格。
在这里,我无法理解如何保持起始行号的跟踪。
以下是我的代码。请让我知道我该怎么做。
HSSFWorkbook workbook = new HSSFWorkbook(fin);
HSSFSheet sheet = workbook.getSheetAt(0);
int row = sheet.getPhysicalNumberOfRows();
String currentLawName, currentCountry, currentAssociate, previousLawName, previousCountry, previousAssociate;
String currentPages, previousPages;
int startIndex = 0, finalIndex = 0, tempNum = 0;
System.out.println(row);
for (int i = 2; i < row; i++) {
currentAssociate = sheet.getRow(i).getCell(1).toString();
currentLawName = sheet.getRow(i).getCell(3).toString();
currentCountry = sheet.getRow(i).getCell(4).toString();
currentPages = sheet.getRow(i).getCell(5).toString();
previousAssociate = sheet.getRow(i - 1).getCell(1).toString();
previousLawName = sheet.getRow(i - 1).getCell(3).toString();
previousCountry = sheet.getRow(i - 1).getCell(4).toString();
previousPages = sheet.getRow(i - 1).getCell(5).toString();
if (currentAssociate.equals(previousAssociate) && currentCountry.equals(previousCountry)
&& currentLawName.equals(previousLawName) && currentPages.equals(previousPages)) {
finalIndex += 1;
} else {
finalIndex = 0;
}
}
System.out.println(finalIndex + "\t" + tempNum);