Revert "tdf#170515 sc: formula with invalid parameters saved into XLSX"

Invalid XML gets exported with problematic matrix formula,
eg. fdo73235-1.ods as found by crashtesting.

Further problem this error exposed is that in certain cases
normal formula or error results (eg. #VALUE!) turn into
parameter errors (Err:504) in Calc, which are then discarded
by the previous change.

Let's revert the change until these issues are resolved. Affected files:
https://wiki.documentfoundation.org/index.php?title=Development/Crashtesting&oldid=869226
(under sax_fastparser::FastSaxSerializer::endFastElement)

If the change is later reapplied:
- handle matrix formula case as well,
- keep #VALUE! in the formula, don't remove formula completely.

This reverts commit bebe7a0b27.

Change-Id: I19aca20cc447871d89f462af874e46993ed6f4ce
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199635
Tested-by: Jenkins
Reviewed-by: Aron Budea <aron.budea@collabora.com>
This commit is contained in:
Aron Budea
2026-02-19 02:25:38 +01:00
parent 92c6a725b8
commit af485bb975
7 changed files with 4 additions and 46 deletions
Binary file not shown.
-26
View File
@@ -1608,32 +1608,6 @@ CPPUNIT_TEST_FIXTURE(ScExportTest2, testTdf137543XLSX)
u"_xlfn.LET(_xlpm.first,B5:E15,_xlfn.CHOOSEROWS(_xlpm.first, 1, 3, 5, 7, 9, 11))");
}
CPPUNIT_TEST_FIXTURE(ScExportTest2, testTdf170515_invalid_parameters)
{
createScDoc("ods/tdf170515_invalid_parameters.ods");
save(TestFilter::XLSX);
xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
CPPUNIT_ASSERT(pSheet);
// No function must be saved into the XLSX, the parameters are invalid (Err:504 in Calc),
// and Excel fails to open the result
// Function with invalid parameter: =COUNTIF(BASE(1;14);"VV")
CPPUNIT_ASSERT_EQUAL(0,
countXPathNodes(pSheet, "/x:worksheet/x:sheetData/x:row[1]/x:c[1]/x:f"));
// Function with invalid parameter: =COUNTIF("hello";"VV")
CPPUNIT_ASSERT_EQUAL(0,
countXPathNodes(pSheet, "/x:worksheet/x:sheetData/x:row[2]/x:c[1]/x:f"));
// Function with invalid parameter: =COUNTIF(1;"VV")
CPPUNIT_ASSERT_EQUAL(0,
countXPathNodes(pSheet, "/x:worksheet/x:sheetData/x:row[3]/x:c[1]/x:f"));
// Function with invalid parameter: =COUNTIF(TEXT(1;"#");"VV")
CPPUNIT_ASSERT_EQUAL(0,
countXPathNodes(pSheet, "/x:worksheet/x:sheetData/x:row[4]/x:c[1]/x:f"));
// Just check one of them that it has the right text
assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row[1]/x:c[1]/x:v", u"#VALUE!");
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+1 -4
View File
@@ -665,8 +665,7 @@ static const char* lcl_GetErrorString( FormulaError nScErrCode )
}
}
void XclXmlUtils::GetFormulaTypeAndValue( ScFormulaCell& rCell, const char*& rsType,
OUString& rsValue, bool* pbWriteFormula )
void XclXmlUtils::GetFormulaTypeAndValue( ScFormulaCell& rCell, const char*& rsType, OUString& rsValue )
{
sc::FormulaResultValue aResValue = rCell.GetResult();
@@ -675,8 +674,6 @@ void XclXmlUtils::GetFormulaTypeAndValue( ScFormulaCell& rCell, const char*& rsT
case sc::FormulaResultValue::Error:
rsType = "e";
rsValue = ToOUString(lcl_GetErrorString(aResValue.mnError));
if ( pbWriteFormula )
*pbWriteFormula = XclTools::IsFormulaWithErrorValid(aResValue.mnError);
break;
case sc::FormulaResultValue::Value:
rsType = rCell.GetFormatType() == SvNumFormatType::LOGICAL
+2 -2
View File
@@ -943,8 +943,7 @@ void XclExpFormulaCell::SaveXml( XclExpXmlStream& rStrm )
{
const char* sType = nullptr;
OUString sValue;
bool bWriteFormula = true;
XclXmlUtils::GetFormulaTypeAndValue( mrScFmlaCell, sType, sValue, &bWriteFormula );
XclXmlUtils::GetFormulaTypeAndValue( mrScFmlaCell, sType, sValue );
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
rWorksheet->startElement( XML_c,
XML_r, XclXmlUtils::ToOString(rStrm.GetRoot().GetStringBuf(), GetXclPos()).getStr(),
@@ -953,6 +952,7 @@ void XclExpFormulaCell::SaveXml( XclExpXmlStream& rStrm )
// OOXTODO: XML_cm, XML_vm, XML_ph
);
bool bWriteFormula = true;
bool bTagStarted = false;
ScAddress aScPos( static_cast< SCCOL >( GetXclPos().mnCol ),
static_cast< SCROW >( GetXclPos().mnRow ), rStrm.GetRoot().GetCurrScTab() );
-10
View File
@@ -218,16 +218,6 @@ sal_uInt8 XclTools::GetXclErrorCode( FormulaError nScError )
return EXC_ERR_NA;
}
bool XclTools::IsFormulaWithErrorValid( FormulaError nScError )
{
switch ( nScError )
{
// illegal parameter, eg. COUNTIF(1, "x")
case FormulaError::IllegalParameter: return false;
default: return true;
}
}
FormulaError XclTools::GetScErrorCode( sal_uInt8 nXclError )
{
switch( nXclError )
+1 -2
View File
@@ -251,8 +251,7 @@ public:
XclXmlUtils(const XclXmlUtils&) = delete;
XclXmlUtils& operator=(const XclXmlUtils&) = delete;
static void GetFormulaTypeAndValue( ScFormulaCell& rCell, const char*& sType, OUString& rValue,
bool* pbWriteFormula = nullptr );
static void GetFormulaTypeAndValue( ScFormulaCell& rCell, const char*& sType, OUString& rValue);
static OUString GetStreamName( const char* sStreamDir, const char* sStream, sal_Int32 nId );
static OString ToOString( const Color& rColor );
-2
View File
@@ -119,8 +119,6 @@ public:
/** Converts a Calc error code to an Excel error code. */
static sal_uInt8 GetXclErrorCode( FormulaError nScError );
/** Checks if erroneous formula is valid (file can be opened) in Excel */
static bool IsFormulaWithErrorValid( FormulaError nScError );
/** Converts an Excel error code to a Calc error code. */
static FormulaError GetScErrorCode( sal_uInt8 nXclError );