tdf#126305 XLSX export: fix data validation Error Alert

Excel supports three kinds of error messages: stop,
warning and information, but LO only one of error
message(stop) was exported.

Co-authored-by: Attila Szűcs (NISZ)
Change-Id: Iecf790c104bee39ee29629a13fe4af4d8b29d311
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104021
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
diff --git a/sc/qa/unit/data/ods/tdf126305.ods b/sc/qa/unit/data/ods/tdf126305.ods
new file mode 100644
index 0000000..fdff7d9
--- /dev/null
+++ b/sc/qa/unit/data/ods/tdf126305.ods
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 89a3659..f227479 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -271,7 +271,7 @@ public:
    void testTdf133688_precedents();
    void testTdf91251_missingOverflowRoundtrip();
    void testTdf137000_handle_upright();

    void testTdf126305_DataValidatyErrorAlert();

    CPPUNIT_TEST_SUITE(ScExportTest);
    CPPUNIT_TEST(test);
@@ -437,6 +437,7 @@ public:
    CPPUNIT_TEST(testTdf133688_precedents);
    CPPUNIT_TEST(testTdf91251_missingOverflowRoundtrip);
    CPPUNIT_TEST(testTdf137000_handle_upright);
    CPPUNIT_TEST(testTdf126305_DataValidatyErrorAlert);

    CPPUNIT_TEST_SUITE_END();

@@ -5505,6 +5506,25 @@ void ScExportTest::testTdf137000_handle_upright()
                           "rot");
}

void ScExportTest::testTdf126305_DataValidatyErrorAlert()
{
    ScDocShellRef xShell = loadDoc("tdf126305.", FORMAT_ODS);
    CPPUNIT_ASSERT(xShell.is());

    ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX);
    CPPUNIT_ASSERT(xDocSh.is());

    std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX);
    xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml");
    CPPUNIT_ASSERT(pDoc);

    assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[1]", "errorStyle", "stop");
    assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[2]", "errorStyle", "warning");
    assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[3]", "errorStyle", "information");

    xDocSh->DoClose();
}

CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);

CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index eaa14d7..a04c456f 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -1637,6 +1637,17 @@ const char* lcl_GetOperatorType( sal_uInt32 nFlags )
    return nullptr;
}

const char* lcl_GetErrorType( sal_uInt32 nFlags )
{
    switch (nFlags & EXC_DV_ERROR_MASK)
    {
        case EXC_DV_ERROR_STOP:      return "stop";
        case EXC_DV_ERROR_WARNING:   return "warning";
        case EXC_DV_ERROR_INFO:      return "information";
    }
    return nullptr;
}

} // namespace

XclExpDV::XclExpDV( const XclExpRoot& rRoot, sal_uLong nScHandle ) :
@@ -1846,7 +1857,7 @@ void XclExpDV::SaveXml( XclExpXmlStream& rStrm )
    rWorksheet->startElement( XML_dataValidation,
            XML_allowBlank,         ToPsz( ::get_flag( mnFlags, EXC_DV_IGNOREBLANK ) ),
            XML_error,              XESTRING_TO_PSZ( maErrorText ),
            // OOXTODO: XML_errorStyle,
            XML_errorStyle,         lcl_GetErrorType(mnFlags),
            XML_errorTitle,         XESTRING_TO_PSZ( maErrorTitle ),
            // OOXTODO: XML_imeMode,
            XML_operator,           lcl_GetOperatorType( mnFlags ),