Search code examples
javaexceljava-streamcompare

Comparing and extracting changes between two similar Excel files, but with different row order


I'm a beginner in Java and I have a problem.

I have two excels that I need to compare and extract the changes. Excels are practically the same but differ in row order (example below). How to extract information about the change in the red field relative to the previous excel?

Example

Apache Poi compares row by row so it fails. I was thinking about using java stream but I have no experience with it. Is it better to pull into tables? I'm not asking for ready code, but for tips.

Thanks for the help


Solution

  • I think what you need is to do the following:

    1. Upload each excel to the memory.
    2. Tranform each excel row to a Pojo.
    3. Add all rows to list (you will have two lists).
    4. Sort each list separately.
    5. Create a new list with the differences.
    6. Tranform the new list back to exel.