summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-11-16 18:23:25 +0100
committerEike Rathke <erack@redhat.com>2016-11-16 18:24:00 +0100
commit83cbbc6d664d949f6405409713c5bda1a5be559f (patch)
treed7d06317429e5b22c14ebe7d7522d6afcc174a90 /sc
parented5a8df72ac2d14aa2f5d1f87543fcfff9ad9d7d (diff)
tdf#96475 restore the EmptyDisplayedAsString condition during load
So also "empty" result cells with a number format applied are displayed empty, instead of 1899-12-30 for example. Change-Id: I5280d0213b8a809a04c5cb152ded58028706493a
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/formulacell.hxx7
-rw-r--r--sc/inc/formularesult.hxx7
-rw-r--r--sc/inc/token.hxx4
-rw-r--r--sc/source/core/data/formulacell.cxx5
-rw-r--r--sc/source/core/tool/formularesult.cxx50
-rw-r--r--sc/source/core/tool/token.cxx7
-rw-r--r--sc/source/filter/xml/xmlcelli.cxx23
-rw-r--r--sc/source/filter/xml/xmlcelli.hxx1
8 files changed, 86 insertions, 18 deletions
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 180c85661284..d17e1e0db2f1 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -341,6 +341,13 @@ public:
SetHybridString() or SetHybridFormula(), use SetHybridDouble() first
for performance reasons.*/
void SetHybridString( const svl::SharedString& r );
+ /** For import only: set an empty cell result to be displayed as empty string.
+ If for whatever reason you have to use both, SetHybridDouble() and
+ SetHybridEmptyDisplayedAsString() or SetHybridFormula(), use
+ SetHybridDouble() first for performance reasons and use
+ SetHybridEmptyDisplayedAsString() last because SetHybridDouble() and
+ SetHybridString() will override it.*/
+ void SetHybridEmptyDisplayedAsString();
/** For import only: set a temporary formula string to be compiled later.
If for whatever reason you have to use both, SetHybridDouble() and
SetHybridString() or SetHybridFormula(), use SetHybridDouble() first
diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx
index 0a977dcf043a..033d45eccb1f 100644
--- a/sc/inc/formularesult.hxx
+++ b/sc/inc/formularesult.hxx
@@ -188,7 +188,7 @@ public:
const OUString& GetHybridFormula() const;
/** Should only be used by import filters, best in the order
- SetHybridDouble(), SetHybridString(), or only SetHybridString() for
+ SetHybridDouble(), SetHybridString(), or only SetHybridFormula() for
formula string to be compiled later. */
SC_DLLPUBLIC void SetHybridDouble( double f );
@@ -198,6 +198,11 @@ public:
SC_DLLPUBLIC void SetHybridString( const svl::SharedString & rStr );
/** Should only be used by import filters, best in the order
+ SetHybridDouble(), SetHybridFormula(),
+ SetHybridEmptyDisplayedAsString() must be last. */
+ SC_DLLPUBLIC void SetHybridEmptyDisplayedAsString();
+
+ /** Should only be used by import filters, best in the order
SetHybridDouble(), SetHybridString()/SetHybridFormula(), or only
SetHybridFormula() for formula string to be compiled later. */
SC_DLLPUBLIC void SetHybridFormula( const OUString & rFormula );
diff --git a/sc/inc/token.hxx b/sc/inc/token.hxx
index 94a1da8b0db1..e8d313a7da64 100644
--- a/sc/inc/token.hxx
+++ b/sc/inc/token.hxx
@@ -388,11 +388,13 @@ private:
double mfDouble;
svl::SharedString maString;
OUString maFormula;
+ bool mbEmptyDisplayedAsString;
public:
ScHybridCellToken(
- double f, const svl::SharedString & rStr, const OUString & rFormula );
+ double f, const svl::SharedString & rStr, const OUString & rFormula, bool bEmptyDisplayedAsString );
const OUString& GetFormula() const { return maFormula; }
+ bool IsEmptyDisplayedAsString() const { return mbEmptyDisplayedAsString; }
virtual double GetDouble() const override;
virtual svl::SharedString GetString() const override;
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 5750aa3409e4..1c95096d1158 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2464,6 +2464,11 @@ void ScFormulaCell::SetHybridString( const svl::SharedString& r )
aResult.SetHybridString( r);
}
+void ScFormulaCell::SetHybridEmptyDisplayedAsString()
+{
+ aResult.SetHybridEmptyDisplayedAsString();
+}
+
void ScFormulaCell::SetHybridFormula( const OUString& r,
const formula::FormulaGrammar::Grammar eGrammar )
{
diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx
index 2c1b646f605a..7af64f35c3db 100644
--- a/sc/source/core/tool/formularesult.cxx
+++ b/sc/source/core/tool/formularesult.cxx
@@ -243,14 +243,27 @@ bool ScFormulaResult::IsEmptyDisplayedAsString() const
{
if (mbEmpty)
return mbEmptyDisplayedAsString;
- if (GetType() == formula::svMatrixCell)
+ switch (GetType())
{
- // don't need to test for mpToken here, GetType() already did it
- const ScEmptyCellToken* p = dynamic_cast<const ScEmptyCellToken*>(
- static_cast<const ScMatrixCellResultToken*>(
- mpToken)->GetUpperLeftToken().get());
- if (p)
- return p->IsDisplayedAsString();
+ case formula::svMatrixCell:
+ {
+ // don't need to test for mpToken here, GetType() already did it
+ const ScEmptyCellToken* p = dynamic_cast<const ScEmptyCellToken*>(
+ static_cast<const ScMatrixCellResultToken*>(
+ mpToken)->GetUpperLeftToken().get());
+ if (p)
+ return p->IsDisplayedAsString();
+ }
+ break;
+ case formula::svHybridCell:
+ {
+ const ScHybridCellToken* p = dynamic_cast<const ScHybridCellToken*>(mpToken);
+ if (p)
+ return p->IsEmptyDisplayedAsString();
+ }
+ break;
+ default:
+ break;
}
return false;
}
@@ -505,7 +518,7 @@ void ScFormulaResult::SetHybridDouble( double f )
svl::SharedString aString = GetString();
OUString aFormula( GetHybridFormula());
mpToken->DecRef();
- mpToken = new ScHybridCellToken( f, aString, aFormula);
+ mpToken = new ScHybridCellToken( f, aString, aFormula, false);
mpToken->IncRef();
}
}
@@ -525,7 +538,24 @@ void ScFormulaResult::SetHybridString( const svl::SharedString& rStr )
ResetToDefaults();
if (mbToken && mpToken)
mpToken->DecRef();
- mpToken = new ScHybridCellToken( f, rStr, aFormula);
+ mpToken = new ScHybridCellToken( f, rStr, aFormula, false);
+ mpToken->IncRef();
+ mbToken = true;
+}
+
+void ScFormulaResult::SetHybridEmptyDisplayedAsString()
+{
+ // Obtain values before changing anything.
+ double f = GetDouble();
+ OUString aFormula( GetHybridFormula());
+ svl::SharedString aStr = GetString();
+ ResetToDefaults();
+ if (mbToken && mpToken)
+ mpToken->DecRef();
+ // XXX NOTE: we can't use mbEmpty and mbEmptyDisplayedAsString here because
+ // GetType() intentionally returns svEmptyCell if mbEmpty==true. So stick
+ // it into the ScHybridCellToken.
+ mpToken = new ScHybridCellToken( f, aStr, aFormula, true);
mpToken->IncRef();
mbToken = true;
}
@@ -538,7 +568,7 @@ void ScFormulaResult::SetHybridFormula( const OUString & rFormula )
ResetToDefaults();
if (mbToken && mpToken)
mpToken->DecRef();
- mpToken = new ScHybridCellToken( f, aStr, rFormula);
+ mpToken = new ScHybridCellToken( f, aStr, rFormula, false);
mpToken->IncRef();
mbToken = true;
}
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 9e3c956ab743..880be0951c6c 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1154,11 +1154,14 @@ void ScMatrixFormulaCellToken::ResetResult()
}
ScHybridCellToken::ScHybridCellToken(
- double f, const svl::SharedString & rStr, const OUString & rFormula ) :
+ double f, const svl::SharedString & rStr, const OUString & rFormula, bool bEmptyDisplayedAsString ) :
FormulaToken( formula::svHybridCell ),
mfDouble( f ), maString( rStr ),
- maFormula( rFormula )
+ maFormula( rFormula ),
+ mbEmptyDisplayedAsString( bEmptyDisplayedAsString)
{
+ // caller, make up your mind..
+ assert( !bEmptyDisplayedAsString || (f == 0.0 && rStr.getString().isEmpty()));
}
double ScHybridCellToken::GetDouble() const { return mfDouble; }
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index f224852edbc6..6ac6a4c3f5a0 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -165,7 +165,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
mbCheckWithCompilerForError(false),
mbEditEngineHasText(false),
mbHasFormatRuns(false),
- mbHasStyle(false)
+ mbHasStyle(false),
+ mbPossibleEmptyDisplay(false)
{
rtl::math::setNan(&fValue); // NaN by default
@@ -1028,6 +1029,8 @@ void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const
else if (rtl::math::isFinite(fValue))
{
pFCell->SetHybridDouble(fValue);
+ if (mbPossibleEmptyDisplay && fValue == 0.0)
+ pFCell->SetHybridEmptyDisplayedAsString();
pFCell->ResetDirty();
}
}
@@ -1452,12 +1455,24 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
// Libreoffice 4.1+ with ODF1.2 extended write however calcext:value-type="error" in that case
void ScXMLTableRowCellContext::HasSpecialCaseFormulaText()
{
- if (!mbEditEngineHasText || mbNewValueType)
+ if (!mbEditEngineHasText)
return;
- OUString aStr = GetFirstParagraph();
+ const OUString aStr = GetFirstParagraph();
- if (aStr.isEmpty() || aStr.startsWith("Err:"))
+ if (mbNewValueType)
+ {
+ if (aStr.isEmpty())
+ mbPossibleEmptyDisplay = true;
+ return;
+ }
+
+ if (aStr.isEmpty())
+ {
+ mbPossibleErrorCell = true;
+ mbPossibleEmptyDisplay = true;
+ }
+ else if (aStr.startsWith("Err:"))
mbPossibleErrorCell = true;
else if (aStr.startsWith("#"))
mbCheckWithCompilerForError = true;
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index b84be0a45a2e..9765ca7440ac 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -96,6 +96,7 @@ class ScXMLTableRowCellContext : public ScXMLImportContext
bool mbEditEngineHasText;
bool mbHasFormatRuns;
bool mbHasStyle;
+ bool mbPossibleEmptyDisplay;
void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);