summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-11-15 20:55:01 +0100
committerEike Rathke <erack@redhat.com>2016-11-15 23:51:55 +0100
commitc802fb24368ac9866940f2d987d46357b0e577f3 (patch)
tree1d9bdcba74bd8e10abd8735aaa2848ed5e635e36 /sc
parent50d1373b5b90ba19603a407dabf472801e871522 (diff)
tdf#96475 sort error result between text and empty cell
Error results weren't handled at all and sorted same as numeric 0, which due to "stable sort" resulted in arbitrary looking sort order if 0 values or results where included. Change-Id: Ib7c516b57ea92bc5b813f448d9c2bb5491e43940
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/table3.cxx61
1 files changed, 53 insertions, 8 deletions
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 1336e041b81e..cace30906f52 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1483,12 +1483,35 @@ short ScTable::CompareCell(
{
if (!rCell2.isEmpty())
{
+ bool bErr1 = false;
bool bStr1 = ( eType1 != CELLTYPE_VALUE );
- if (eType1 == CELLTYPE_FORMULA && rCell1.mpFormula->IsValue())
- bStr1 = false;
+ if (eType1 == CELLTYPE_FORMULA)
+ {
+ if (rCell1.mpFormula->GetErrCode() != FormulaError::NONE)
+ {
+ bErr1 = true;
+ bStr1 = false;
+ }
+ else if (rCell1.mpFormula->IsValue())
+ {
+ bStr1 = false;
+ }
+ }
+
+ bool bErr2 = false;
bool bStr2 = ( eType2 != CELLTYPE_VALUE );
- if (eType2 == CELLTYPE_FORMULA && rCell2.mpFormula->IsValue())
- bStr2 = false;
+ if (eType2 == CELLTYPE_FORMULA)
+ {
+ if (rCell2.mpFormula->GetErrCode() != FormulaError::NONE)
+ {
+ bErr2 = true;
+ bStr2 = false;
+ }
+ else if (rCell2.mpFormula->IsValue())
+ {
+ bStr2 = false;
+ }
+ }
if ( bStr1 && bStr2 ) // only compare strings as strings!
{
@@ -1531,10 +1554,32 @@ short ScTable::CompareCell(
nRes = static_cast<short>( pSortCollator->compareString( aStr1, aStr2 ) );
}
}
- else if ( bStr1 ) // String <-> Number
- nRes = 1; // Number in front
- else if ( bStr2 ) // Number <-> String
- nRes = -1; // Number in front
+ else if ( bStr1 ) // String <-> Number or Error
+ {
+ if (bErr2)
+ nRes = -1; // String in front of Error
+ else
+ nRes = 1; // Number in front of String
+ }
+ else if ( bStr2 ) // Number or Error <-> String
+ {
+ if (bErr1)
+ nRes = 1; // String in front of Error
+ else
+ nRes = -1; // Number in front of String
+ }
+ else if (bErr1 && bErr2)
+ {
+ // nothing, two Errors are equal
+ }
+ else if (bErr1) // Error <-> Number
+ {
+ nRes = 1; // Number in front of Error
+ }
+ else if (bErr2) // Number <-> Error
+ {
+ nRes = -1; // Number in front of Error
+ }
else // Mixed numbers
{
double nVal1 = rCell1.getValue();