sw/inc/calc.hxx                              |    3 
 sw/qa/extras/ooxmlexport/data/tdf123384.fodt |  152 +++++++++++++++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx   |   21 +++
 sw/source/core/bastyp/calc.cxx               |   17 ++-
 4 files changed, 191 insertions(+), 2 deletions(-)

New commits:
commit 389325166a3357d7a4e557dc4c223fe0bb7aeadd
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Jun 10 12:30:00 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jun 10 15:08:22 2025 +0200

    tdf#123384: Add support for MOD formula
    
    Change-Id: I86d30d688b44f537bd42a4018f4ff4cbaa8b4d52
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186325
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx
index ff9fde612ece..736e834b32e3 100644
--- a/sw/inc/calc.hxx
+++ b/sw/inc/calc.hxx
@@ -57,7 +57,7 @@ enum SwCalcOper
     CALC_ROUND=281,         CALC_DATE=282,          CALC_MONTH=283,
     CALC_DAY=284,           CALC_PRODUCT=285,       CALC_AVERAGE=286,
     CALC_COUNT=287,         CALC_SIGN=288,          CALC_ABS=289,
-    CALC_INT=290
+    CALC_INT=290,           CALC_MOD=291,           CALC_MOD_IN=292
 };
 
 // Calculate Operations Strings
@@ -82,6 +82,7 @@ inline constexpr OUString sCalc_Sum  = u"sum"_ustr;
 inline constexpr OUString sCalc_Mean = u"mean"_ustr;
 inline constexpr OUString sCalc_Min  = u"min"_ustr;
 inline constexpr OUString sCalc_Max  = u"max"_ustr;
+inline constexpr OUString sCalc_Mod  = u"mod"_ustr;
 inline constexpr OUString sCalc_Sin  = u"sin"_ustr;
 inline constexpr OUString sCalc_Cos  = u"cos"_ustr;
 inline constexpr OUString sCalc_Tan  = u"tan"_ustr;
diff --git a/sw/qa/extras/ooxmlexport/data/tdf123384.fodt 
b/sw/qa/extras/ooxmlexport/data/tdf123384.fodt
new file mode 100644
index 000000000000..7dd13f6c943a
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf123384.fodt
@@ -0,0 +1,152 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.text">
+ 
<office:meta><dc:date>2025-06-10T12:10:44.078863463</dc:date><meta:editing-duration>PT2M48S</meta:editing-duration><meta:editing-cycles>1</meta:editing-cycles><meta:document-statistic
 meta:table-count="1" meta:image-count="0" meta:object-count="0" 
meta:page-count="1" meta:paragraph-count="6" meta:word-count="6" 
meta:character-count="8" 
meta:non-whitespace-character-count="8"/><meta:generator>LibreOfficeDev/26.2.0.0.alpha0$Linux_X86_64
 
LibreOffice_project/7d011eceac3222c67c9be61cf2a163e99ee74745</meta:generator></office:meta>
+ <office:font-face-decls>
+  <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation 
Serif'" style:font-family-generic="roman" style:font-pitch="variable"/>
+  <style:font-face style:name="Noto Sans1" svg:font-family="'Noto Sans'" 
style:font-family-generic="system" style:font-pitch="variable"/>
+  <style:font-face style:name="Noto Serif CJK SC" svg:font-family="'Noto Serif 
CJK SC'" style:font-family-generic="system" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#3465a4" 
draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" 
draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" 
draw:start-line-spacing-vertical="0.283cm" 
draw:end-line-spacing-horizontal="0.283cm" 
draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" loext:tab-stop-distance="0cm" 
style:writing-mode="lr-tb" style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="en" fo:country="US" style:letter-kerning="true" 
style:font-name-asian="Noto Serif CJK SC" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Noto Sans1" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" 
fo:hyphenation-keep="auto" loext:hyphenation-keep-type="column" 
loext:hyphenation-keep-line="false" style:text-autospace="ideograph-alpha" 
style:punctuation-wrap="hanging" style:line-break="strict" 
style:tab-stop-distance="1.251cm" style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="en" fo:country="US" style:letter-kerning="true" 
style:font-name-asian="Noto Serif CJK SC" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Noto Sans1" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" 
loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" 
loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="collapsing"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="auto"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+  <text:outline-style style:name="Outline">
+   <text:outline-level-style text:level="1" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="2" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="3" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="4" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="5" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="6" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="7" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="8" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="9" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="10" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+  </text:outline-style>
+  <text:notes-configuration text:note-class="footnote" style:num-format="1" 
text:start-value="0" text:footnotes-position="page" 
text:start-numbering-at="document"/>
+  <text:notes-configuration text:note-class="endnote" style:num-format="i" 
text:start-value="0"/>
+  <text:linenumbering-configuration text:number-lines="false" 
text:offset="0.499cm" style:num-format="1" text:number-position="left" 
text:increment="5"/>
+  </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="Table1" style:family="table">
+   <style:table-properties style:width="17cm" table:align="margins"/>
+  </style:style>
+  <style:style style:name="Table1.A" style:family="table-column">
+   <style:table-column-properties style:column-width="5.667cm" 
style:rel-column-width="21845*"/>
+  </style:style>
+  <style:style style:name="Table1.2" style:family="table-row">
+   <style:table-row-properties style:min-row-height="0.413cm"/>
+  </style:style>
+  <style:style style:name="Table1.A2" style:family="table-cell" 
style:data-style-name="N0"/>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:text-properties/>
+  </style:style>
+  <style:style style:name="P2" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:text-properties/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm" style:writing-mode="lr-tb" 
style:footnote-max-height="0cm" loext:margin-gutter="0cm">
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+  <number:number-style style:name="N0">
+   <number:number number:min-integer-digits="1"/>
+  </number:number-style>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:sequence-decls>
+    <text:sequence-decl text:display-outline-level="0" 
text:name="Illustration"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
+   </text:sequence-decls>
+   <table:table table:name="Table1" table:style-name="Table1">
+    <table:table-column table:style-name="Table1.A" 
table:number-columns-repeated="3"/>
+    <table:table-row>
+     <table:table-cell office:value-type="string">
+      <text:p text:style-name="P1">18</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string">
+      <text:p text:style-name="P1">4</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string">
+      <text:p text:style-name="P1">17</text:p>
+     </table:table-cell>
+    </table:table-row>
+    <table:table-row table:style-name="Table1.2">
+     <table:table-cell table:style-name="Table1.A2" 
table:formula="ooow:MOD(&lt;A1&gt;|&lt;B1&gt;)" office:value-type="float" 
office:value="2">
+      <text:p text:style-name="P2">2</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="Table1.A2" 
table:formula="ooow:MOD(&lt;A1&gt;|&lt;C1&gt;)" office:value-type="float" 
office:value="1">
+      <text:p text:style-name="P1">1</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="Table1.A2" 
table:formula="ooow:MOD(&lt;B1&gt;|&lt;C1&gt;)" office:value-type="float" 
office:value="4">
+      <text:p text:style-name="P2">4</text:p>
+     </table:table-cell>
+    </table:table-row>
+   </table:table>
+   <text:p text:style-name="Standard"/>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 9655b415f9ef..3142592b0fd5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -343,6 +343,27 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf123354)
     CPPUNIT_ASSERT_EQUAL(u"0"_ustr, 
xEnumerationAccess3->getPresentation(false).trim());
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf123384)
+{
+    loadAndReload("tdf123384.fodt");
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
+    uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
+
+    // Tests new cell formula MOD
+    uno::Reference<text::XTextField> 
xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"MOD((<A1>)|(<B1>))"_ustr, 
xEnumerationAccess1->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(u"2"_ustr, 
xEnumerationAccess1->getPresentation(false).trim());
+
+    uno::Reference<text::XTextField> 
xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"MOD((<B1>)|(<C1>))"_ustr, 
xEnumerationAccess2->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(u"4"_ustr, 
xEnumerationAccess2->getPresentation(false).trim());
+
+    uno::Reference<text::XTextField> 
xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"MOD((<A1>)|(<C1>))"_ustr, 
xEnumerationAccess3->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(u"1"_ustr, 
xEnumerationAccess3->getPresentation(false).trim());
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf123355)
 {
     auto verify = [this]() {
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 94a09679ab0e..f31ebce0050a 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -84,6 +84,7 @@ CalcOp constexpr aOpTable[] = {
 /* MAX */     {{sCalc_Max},        CALC_MAX},   // Maximum value
 /* MEAN */    {{sCalc_Mean},       CALC_MEAN},  // Mean
 /* MIN */     {{sCalc_Min},        CALC_MIN},   // Minimum value
+/* MOD */     {{sCalc_Mod},        CALC_MOD},   // Modulo value
 /* MUL */     {{sCalc_Mul},        CALC_MUL},   // Multiplication
 /* NEQ */     {{sCalc_Neq},        CALC_NEQ},   // Not equal
 /* NOT */     {{sCalc_Not},        CALC_NOT},   // log. NOT
@@ -620,6 +621,9 @@ SwCalcOper SwCalc::GetToken()
                 case CALC_MAX:
                     m_eCurrListOper = CALC_MAX_IN;
                     break;
+                case CALC_MOD:
+                    m_eCurrListOper = CALC_MOD_IN;
+                    break;
                 case CALC_DATE:
                     m_eCurrListOper = CALC_MONTH;
                     break;
@@ -845,6 +849,16 @@ SwSbxValue SwCalc::Term()
                 left = left.GetDouble() > e.GetDouble() ? left : e;
             }
             break;
+        case CALC_MOD_IN:
+            {
+                GetToken();
+                SwSbxValue e = Prim();
+                if ( e.GetDouble() == 0.0)
+                    m_eError = SwCalcError::DivByZero;
+                else
+                    left.PutLong(left.GetLong() % e.GetLong());
+            }
+            break;
         case CALC_MONTH:
             {
                 GetToken();
@@ -1171,8 +1185,9 @@ SwSbxValue SwCalc::PrimFunc(bool &rChkPow)
         case CALC_DATE:
         case CALC_MIN:
         case CALC_MAX:
+        case CALC_MOD:
         {
-            SAL_INFO("sw.calc", "sum/product/date/min/max");
+            SAL_INFO("sw.calc", "sum/product/date/min/max/mod");
             GetToken();
             SwSbxValue nErg = Expr();
             return nErg;

Reply via email to