Easiest way to compare two Excel files in Java?

前端 未结 11 887
面向向阳花
面向向阳花 2021-02-02 14:23

I\'m writing a JUnit test for some code that produces an Excel file (which is binary). I have another Excel file that contains my expected output. What\'s the easiest way to com

11条回答
  •  名媛妹妹
    2021-02-02 14:45

    You might consider using my project simple-excel which provides a bunch of Hamcrest Matchers to do the job.

    When you do something like the following,

    assertThat(actual, WorkbookMatcher.sameWorkbook(expected));
    

    You'd see, for example,

    java.lang.AssertionError:
    Expected: entire workbook to be equal
         but: cell at "C14" contained <"bananas"> expected ,
              cell at "C15" contained <"1,850,000 EUR"> expected <"1,850,000.00 EUR">,
              cell at "D16" contained  expected <"Tue Sep 04 06:30:00">
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
    

    That way, you can run it from your automatted tests and get meaningful feedback whilst you're developing.

    You can read more about it at this article on my site

提交回复
热议问题