formula/source/core/api/FormulaCompiler.cxx | 5 +++-- sc/source/core/data/formulacell.cxx | 4 ++++ sc/source/filter/xml/xmlcelli.cxx | 23 +++++++++++++++++------ sc/source/filter/xml/xmlimprt.cxx | 6 +++--- sc/source/filter/xml/xmlimprt.hxx | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-)
New commits: commit 4164596f43132e7769057170a228d74118ee63c6 Author: Eike Rathke <er...@redhat.com> Date: Fri Jan 6 17:46:02 2017 +0100 read single error constant formula as such, tdf#105024 related ... without creating a token so when writing again no leading '=' is prepended, with which we can enable 5.2 to read such thing correctly, and when re-reading in 5.3 it also doesn't lead to a "real" formula. Change-Id: I26fbd20536436b49b781e2bbb5bba1dc6bafbb37 (cherry picked from commit 4fcbe16959c839bfacf745cfa554b234e639f794) Reviewed-on: https://gerrit.libreoffice.org/32792 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index a3f14b4..bf6fc4e 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -1282,6 +1282,10 @@ void ScFormulaCell::CompileXML( sc::CompileFormulaContext& rCxt, ScProgress& rPr return ; } + // Error constant formula cell stays as is. + if (!pCode->GetLen() && pCode->GetCodeError() != FormulaError::NONE) + return; + // Compilation changes RPN count, remove and reinsert to FormulaTree if it // was in to update its count. bool bWasInFormulaTree = pDocument->IsInFormulaTree( this); diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index ddd8543..3b38ac4 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -1348,12 +1348,22 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos ) // temporary formula string as string tokens ScTokenArray *pCode = new ScTokenArray(); - OUString aFormulaNmsp = maFormula->second; - if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL ) - aFormulaNmsp.clear(); - pCode->AssignXMLString( aText, aFormulaNmsp ); + // Check the special case of a single error constant without leading + // '=' and create an error formula cell without tokens. + FormulaError nError = GetScImport().GetFormulaErrorConstant(aText); + if (nError != FormulaError::NONE) + { + pCode->SetCodeError(nError); + } + else + { + OUString aFormulaNmsp = maFormula->second; + if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL ) + aFormulaNmsp.clear(); + pCode->AssignXMLString( aText, aFormulaNmsp ); + rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() ); + } - rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() ); ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode, eGrammar, MM_NONE); SetFormulaCell(pNewCell); rDoc.setFormulaCell(rCellPos, pNewCell); @@ -1466,7 +1476,8 @@ bool ScXMLTableRowCellContext::IsPossibleErrorString() const return false; else if(mbNewValueType && mbErrorValue) return true; - return mbPossibleErrorCell || ( mbCheckWithCompilerForError && GetScImport().IsFormulaErrorConstant(*maStringValue) ); + return mbPossibleErrorCell || (mbCheckWithCompilerForError && + GetScImport().GetFormulaErrorConstant(*maStringValue) != FormulaError::NONE); } void ScXMLTableRowCellContext::EndElement() diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index d74f871..f1a818689 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -3407,12 +3407,12 @@ void ScXMLImport::ExtractFormulaNamespaceGrammar( reGrammar = eDefaultGrammar; } -bool ScXMLImport::IsFormulaErrorConstant( const OUString& rStr ) const +FormulaError ScXMLImport::GetFormulaErrorConstant( const OUString& rStr ) const { if (!mpComp) - return false; + return FormulaError::NONE; - return mpComp->GetErrorConstant(rStr) > FormulaError::NONE; + return mpComp->GetErrorConstant(rStr); } ScEditEngineDefaulter* ScXMLImport::GetEditEngine() diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index 317fad7..28f9ae9 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -1223,7 +1223,7 @@ public: const OUString& rAttrValue, bool bRestrictToExternalNmsp = false ) const; - bool IsFormulaErrorConstant( const OUString& rStr ) const; + FormulaError GetFormulaErrorConstant( const OUString& rStr ) const; ScEditEngineDefaulter* GetEditEngine(); const ScXMLEditAttributeMap& GetEditAttributeMap() const; commit 03e5263dbedcf7650722f0b1bc18ce069e4ce244 Author: Eike Rathke <er...@redhat.com> Date: Fri Jan 6 17:38:39 2017 +0100 check length of string as this can be called untokenized, tdf#105024 related i.e. during import of ODFF Change-Id: I7f5419d393f89d8a84efca7444e8dde3a3e9199f (cherry picked from commit b36bf9f567f5b531f526dad6776c84e06203396f) Reviewed-on: https://gerrit.libreoffice.org/32791 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index 66c92fb..a271410 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -1188,8 +1188,9 @@ FormulaError FormulaCompiler::GetErrorConstant( const OUString& rName ) const else { // Per convention recognize detailed "#ERRxxx!" constants, always - // untranslated. - if (rName.startsWithIgnoreAsciiCase("#ERR") && rName[rName.getLength()-1] == '!') + // untranslated. Error numbers are sal_uInt16 so at most 5 decimal + // digits. + if (rName.startsWithIgnoreAsciiCase("#ERR") && rName.getLength() <= 10 && rName[rName.getLength()-1] == '!') { sal_uInt32 nErr = rName.copy( 4, rName.getLength() - 5).toUInt32(); if (0 < nErr && nErr <= SAL_MAX_UINT16 && isPublishedFormulaError(static_cast<FormulaError>(nErr))) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits