且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

最简单的方法来比较Java中的两个Excel文件?

更新时间:2022-01-01 09:27:37

这里是我最后做的由 DBUnit 完成):

Here's what I ended up doing (with the heavy lifting being done by DBUnit):

/**
 * Compares the data in the two Excel files represented by the given input
 * streams, closing them on completion
 * 
 * @param expected can't be <code>null</code>
 * @param actual can't be <code>null</code>
 * @throws Exception
 */
private void compareExcelFiles(InputStream expected, InputStream actual)
  throws Exception
{
  try {
    Assertion.assertEquals(new XlsDataSet(expected), new XlsDataSet(actual));
  }
  finally {
    IOUtils.closeQuietly(expected);
    IOUtils.closeQuietly(actual);
  }
}

这将比较两个文件中的数据,可能不同的任何不相关元数据的假阴性的风险。希望这有助于某人。

This compares the data in the two files, with no risk of false negatives from any irrelevant metadata that might be different. Hope this helps someone.