Come posso confrontare due documenti ODS a livello di programmazione in Java?

StackOverflow https://stackoverflow.com/questions/9351186

  •  27-10-2019
  •  | 
  •  

Domanda

Sto generando un foglio di calcolo ODS come output da un programma Java. Attualmente sto cercando di impostare casi di test per lo stesso. Per questo, devo confrontare le uscite previste e effettive. Attualmente sto usando ODFToolKit per creare il documento.

Come posso confrontare i due fogli di calcolo (previsti e reali) in un programma Java?

È stato utile?

Soluzione

Nel caso in cui qualcuno abbia bisogno della soluzione, eccola

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;  
}  
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top