diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index a03347afc13dfda4bedf4a623b5011bfaa52c1e8..b231405944da4510a09e2a52f5dc8e4d2891d693 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -186,11 +186,18 @@ void ProteinMatch::countPeptideMassSample(std::vector<size_t> & count_peptide_ma
     }
 }
 
-unsigned int ProteinMatch::countSampleScan(ValidationState state) const {
+unsigned int ProteinMatch::countSampleScan(ValidationState state, const MsRun * p_msrun_id) const {
     std::vector<std::size_t> count_sample_scan;
     for (auto & p_peptide_match : _peptide_match_list) {
         if (p_peptide_match->getValidationState() >= state) {
-            count_sample_scan.push_back(p_peptide_match->getHashSampleScan());
+            if(p_msrun_id == nullptr) {
+                count_sample_scan.push_back(p_peptide_match->getHashSampleScan());
+            }
+            else {
+                if (p_peptide_match->getMsRunP() == p_msrun_id) {
+                    count_sample_scan.push_back(p_peptide_match->getHashSampleScan());
+                }
+            }
         }
     }
     std::sort(count_sample_scan.begin(), count_sample_scan.end());
@@ -310,9 +317,9 @@ pappso::pappso_double ProteinMatch::getEvalue(const MsRun * sp_msrun_id) const {
 
 pappso::pappso_double ProteinMatch::getPAI(const MsRun * sp_msrun_id) const {
     try {
-    pappso::pappso_double PAI =  (pappso::pappso_double) countPeptideMassCharge(ValidationState::validAndChecked ,sp_msrun_id) / (pappso::pappso_double) _protein_sp.get()->countTrypticPeptidesForPAI();
-    return PAI;
-    
+        pappso::pappso_double PAI =  (pappso::pappso_double) countPeptideMassCharge(ValidationState::validAndChecked ,sp_msrun_id) / (pappso::pappso_double) _protein_sp.get()->countTrypticPeptidesForPAI();
+        return PAI;
+
     }
     catch (pappso::PappsoException error) {
         throw pappso::PappsoException(QObject::tr("Error computing PAI for protein %1 :\n%2").arg(this->getProteinXtpSp().get()->getAccession()).arg(error.qwhat()));
diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h
index 3f76d2f8c28073eda0ae260927b525f5c6e50aa3..990a392c0704bb9e34a441ceb84c7938dbca824f 100644
--- a/src/core/proteinmatch.h
+++ b/src/core/proteinmatch.h
@@ -85,7 +85,7 @@ public:
     
     /** @brief count distinct sample + scans implied in this protein identification
      */
-    unsigned int countSampleScan(ValidationState state) const;
+    unsigned int countSampleScan(ValidationState state, const MsRun * p_msrun_id=nullptr) const;
     
     /** @brief count peptide (peptide+mass+sample)
      */
diff --git a/src/output/ods/comparspectrasheet.cpp b/src/output/ods/comparspectrasheet.cpp
index 626af9d4a4f6dc1842ee41d2b6c14438babbfd53..a0ae72dac638400c7c3bd896772bb1dfa623a458 100644
--- a/src/output/ods/comparspectrasheet.cpp
+++ b/src/output/ods/comparspectrasheet.cpp
@@ -75,7 +75,7 @@ void ComparSpectraSheet::writeHeaders(IdentificationGroup * p_ident)  {
     _p_writer->writeCell("accession");
     _p_writer->writeCell("description");
     _p_writer->writeCell("Number of proteins");
-    
+
     for (MsRunSp & msrun_sp: _msrun_list) {
         _p_writer->writeCell(msrun_sp.get()->getSampleName());
     }
@@ -83,8 +83,8 @@ void ComparSpectraSheet::writeHeaders(IdentificationGroup * p_ident)  {
 
 }
 
-void ComparSpectraSheet::writeBestPeptideMatch(const ProteinMatch * p_protein_match,const PeptideMatch * p_peptide_match) {
-
+void ComparSpectraSheet::writeProteinMatch(const ProteinMatch * p_protein_match) {
+    qDebug() << "ComparSpectraSheet::writeProteinMatch begin";
     _p_writer->writeLine();
 
 
@@ -101,14 +101,15 @@ void ComparSpectraSheet::writeBestPeptideMatch(const ProteinMatch * p_protein_ma
     _p_writer->clearTableCellStyleRef();
     _p_writer->writeCell(p_protein_match->getProteinXtpSp().get()->getAccession());
     _p_writer->writeCell(p_protein_match->getProteinXtpSp().get()->getDescription());
-    
+
     _p_writer->writeCell(p_protein_match->getGroupingGroupSp().get()->countProteinInSubgroup(subgroup_number));
-     
+
     for (MsRunSp & msrun_sp: _msrun_list) {
-        _p_writer->writeCell(p_protein_match->countSampleScan(ValidationState::));
+        _p_writer->writeCell(p_protein_match->countSampleScan(ValidationState::validAndChecked, msrun_sp.get()));
     }
-  
-    
+
+
+    qDebug() << "ComparSpectraSheet::writeProteinMatch end";
 
 
 }
@@ -140,52 +141,7 @@ void ComparSpectraSheet::writeIdentificationGroup(IdentificationGroup * p_ident)
     });
 
     for (ProteinMatch * p_protein_match : protein_match_list) {
-
-
-        std::vector<PeptideMatch *> peptide_match_list;
-
-        for (auto & peptide_match: p_protein_match->getPeptideMatchList()) {
-            if (peptide_match->getValidationState() < ValidationState::grouped) continue;
-            peptide_match_list.push_back(peptide_match);
-        }
-        std::sort(peptide_match_list.begin(), peptide_match_list.end(),
-                  [](const PeptideMatch * a, const PeptideMatch * b)
-        {
-            unsigned int arank = a->getGrpPeptideSp().get()->getRank();
-            unsigned int aposition = a->getStart();
-            unsigned int brank = b->getGrpPeptideSp().get()->getRank();
-            unsigned int bposition = b->getStart();
-            return  std::tie(arank, aposition) < std::tie(brank, bposition);
-        });
-
-        const PeptideMatch * p_best_peptide_match = nullptr;
-
-        for (auto & peptide_match:peptide_match_list) {
-            if (p_best_peptide_match == nullptr) {
-                p_best_peptide_match = peptide_match;
-            }
-            //change spectra :
-            unsigned int arank = p_best_peptide_match->getGrpPeptideSp().get()->getRank();
-            unsigned int aposition = p_best_peptide_match->getStart();
-            unsigned int brank = peptide_match->getGrpPeptideSp().get()->getRank();
-            unsigned int bposition = peptide_match->getStart();
-
-            if (std::tie(arank, aposition) != std::tie(brank, bposition)) {
-                //write p_best_peptide_match
-                writeBestPeptideMatch(p_protein_match, p_best_peptide_match);
-                p_best_peptide_match = peptide_match;
-            }
-            else {
-                if (p_best_peptide_match->getEvalue()> peptide_match->getEvalue()) {
-                    p_best_peptide_match = peptide_match;
-                }
-            }
-        }
-
-        if (p_best_peptide_match != nullptr) {
-            writeBestPeptideMatch(p_protein_match, p_best_peptide_match);
-
-        }
+        writeProteinMatch(p_protein_match);
     }
     _p_writer->writeLine();
     _p_writer->writeLine();
diff --git a/src/output/ods/comparspectrasheet.h b/src/output/ods/comparspectrasheet.h
index cb974aab82eb0cd112e05abe4f577c4203e7aae6..9028b600841c4bb522cde3780cf0f284b4280cd5 100644
--- a/src/output/ods/comparspectrasheet.h
+++ b/src/output/ods/comparspectrasheet.h
@@ -42,7 +42,7 @@ public :
 private :
     void writeIdentificationGroup(IdentificationGroup * p_ident);
     void writeHeaders(IdentificationGroup * p_ident);
-    void writeBestPeptideMatch(const ProteinMatch * p_protein_match, const PeptideMatch * p_peptide_match);
+    void writeProteinMatch(const ProteinMatch * p_protein_match);
 
 private :
     OdsExport * _p_ods_export;
diff --git a/src/output/ods/odsexport.cpp b/src/output/ods/odsexport.cpp
index 252a463f897f7e96ebd7c7457ddaa25648d1386b..1fb6963e63f915231416fcfa3352f6f3a7a012f0 100644
--- a/src/output/ods/odsexport.cpp
+++ b/src/output/ods/odsexport.cpp
@@ -33,6 +33,7 @@
 #include "peptidesheet.h"
 #include "spectrasheet.h"
 #include "peptidepossheet.h"
+#include "comparspectrasheet.h"
 #include "infosheet.h"
 #include <QSettings>
 
@@ -74,4 +75,7 @@ void OdsExport::write(CalcWriterInterface * p_writer) {
     if (settings.value("export_ods/peptidepos", "true").toBool()) {
         PeptidePosSheet(this, p_writer, _p_project);
     }
+    if (settings.value("export_ods/comparspectra", "true").toBool()) {
+        ComparSpectraSheet(this, p_writer, _p_project);
+    }
 }