0

我正在生成一个 ODS 电子表格作为 Java 程序的输出。我目前正在尝试为此设置测试用例。为此,我需要比较预期输出和实际输出。我目前正在使用 ODFToolkit 创建文档。

如何比较 Java 程序中的两个电子表格(预期的和实际的)?

4

1 回答 1

0

如果有人需要解决方案,这里就是

public static boolean contentsAreIdentical(OdfSpreadsheetDocument document1, OdfSpreadsheetDocument document2) {  
    try {  
        ByteArrayInputStream bis1 = (ByteArrayInputStream) document1.getContentStream();  
        ByteArrayInputStream bis2 = (ByteArrayInputStream) document2.getContentStream();  

        if(bis1.available() != bis2.available()) {  
            return false;  
        }  

        while(true){  
            int a = bis1.read();  
                            int b = bis2.read();  
                            if(a != b){  
                                    return false;  
                            }  
                            if(a == -1){  
                                    return true;  
                            }  
                  }  
    } catch (Exception e) {  
        //Do something with exception  
    }  
    return false;  
}  
于 2012-02-27T08:25:22.550 回答