summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-12-01 19:46:45 +0100
committerAron Budea <aron.budea@collabora.com>2018-01-19 14:50:21 +0100
commitf7d3af010bb36f4a1fdf8a936d9d60af14feb38e (patch)
tree2e8be0cc7fc6398dccfbbce9d1ba04094e9e70e0
parent545984812e1cad17c28eb412ffd2cd9cf85cda0f (diff)
Resolves: tdf#106322 keep original cell content when assigning number format
... and content can't be parsed as number. Instead of converting 0. Change-Id: Ief0c0a0284762fc0e801d6cc598720a97d733e31 (cherry picked from commit acf7e4c0a3dc0cca986bf4d4b7a65bafe7e70abc) Reviewed-on: https://gerrit.libreoffice.org/45695 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com> (cherry picked from commit fd2cdd325cd59eb1f967136170503145b1d75936)
-rw-r--r--sw/source/core/table/swtable.cxx27
1 files changed, 25 insertions, 2 deletions
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index f77c8a14d305..f4f32acdef75 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -2251,6 +2251,8 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
if( (!bNewIsTextFormat && nOldFormat != nNewFormat) || pNewFormula )
{
+ bool bIsNumFormat = false;
+ OUString aOrigText;
bool bChgText = true;
double fVal = 0;
if( !pNewVal && SfxItemState::SET != GetItemState(
@@ -2263,6 +2265,7 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
sal_uInt32 nTmpFormatIdx = nNewFormat;
OUString aText( GetDoc()->GetNodes()[ nNdPos ]
->GetTextNode()->GetRedlineText());
+ aOrigText = aText;
if( aText.isEmpty() )
bChgText = false;
else
@@ -2272,7 +2275,6 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
// JP 22.04.98: Bug 49659 -
// Special casing for percent
- bool bIsNumFormat = false;
if( css::util::NumberFormat::PERCENT ==
pNumFormatr->GetType( nNewFormat ))
{
@@ -2305,7 +2307,10 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
}
}
else
+ {
fVal = pNewVal->GetValue();
+ bIsNumFormat = true;
+ }
// format contents with the new value assigned and write to paragraph
Color* pCol = nullptr;
@@ -2316,7 +2321,25 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
}
else
{
- pNumFormatr->GetOutputString( fVal, nNewFormat, sNewText, &pCol );
+ if (bIsNumFormat)
+ pNumFormatr->GetOutputString( fVal, nNewFormat, sNewText, &pCol );
+ else
+ {
+ // Original text could not be parsed as
+ // number/date/time/..., so keep the text.
+#if 0
+ // Actually the text should be formatted
+ // according to the format, which may include
+ // additional text from the format, for example
+ // in {0;-0;"BAD: "@}. But other places when
+ // entering a new value or changing text or
+ // changing to a different format of type Text
+ // don't do this (yet?).
+ pNumFormatr->GetOutputString( aOrigText, nNewFormat, sNewText, &pCol );
+#else
+ sNewText = aOrigText;
+#endif
+ }
if( !bChgText )
{