sc/source/filter/excel/xepivotxml.cxx        |   35 ++++++++++++++++++++-------
 sw/source/filter/ww8/docxattributeoutput.cxx |    6 +++-
 2 files changed, 31 insertions(+), 10 deletions(-)

New commits:
commit daa73e471b2ec1badea8ba1abc08783b0d000ff4
Author:     Noel Grandin <[email protected]>
AuthorDate: Mon Oct 27 13:44:59 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Mar 5 12:04:04 2026 +0100

    mso-test: fix duplicate w:i element
    
    when loading and then saving the document from tdf#99822, we end up with a 
duplicate w:i element,
    which causes ms-office to think the document is corrupt
    
    Change-Id: I6b7867fd4ee52d37502fde86a13294ef457416d7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193035
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit 110d88a1e8f77a3b3c2d8ddb3f203e4858be77e6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200569
    Tested-by: Jenkins
    (cherry picked from commit 6ee28b12844b4f9f9b2de0de236b90e3a9919003)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200773
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 4c892649697f..4c0ac61e07b2 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1570,6 +1570,7 @@ void 
lcl_writeParagraphMarkerProperties(DocxAttributeOutput& rAttributeOutput, c
     // Did we already produce a <w:sz> element?
     bool bFontSizeWritten = false;
     bool bBoldWritten = false;
+    bool bPostureWritten = false;
     while (nWhichId)
     {
         if (aIter.GetItemState(true, &pItem) == SfxItemState::SET)
@@ -1579,12 +1580,15 @@ void 
lcl_writeParagraphMarkerProperties(DocxAttributeOutput& rAttributeOutput, c
                 // Will this item produce a <w:sz> element?
                 bool bFontSizeItem = nWhichId == RES_CHRATR_FONTSIZE || 
nWhichId == RES_CHRATR_CJK_FONTSIZE;
                 bool bBoldItem = nWhichId == RES_CHRATR_WEIGHT || nWhichId == 
RES_CHRATR_CJK_WEIGHT;
-                if (!(bFontSizeWritten && bFontSizeItem) && !(bBoldWritten && 
bBoldItem))
+                bool bPostureItem = nWhichId == RES_CHRATR_POSTURE || nWhichId 
== RES_CHRATR_CJK_POSTURE;
+                if (!(bFontSizeWritten && bFontSizeItem) && !(bBoldWritten && 
bBoldItem) && !(bPostureWritten && bPostureItem))
                     rAttributeOutput.OutputItem(*pItem);
                 if (bFontSizeItem)
                     bFontSizeWritten = true;
                 if (bBoldItem)
                     bBoldWritten = true;
+                if (bPostureItem)
+                    bPostureWritten = true;
             }
             else if (nWhichId == RES_TXTATR_AUTOFMT)
             {
commit 26ecb912feee7fbe1aa9311d658e3fb609fe1603
Author:     Karthik Godha <[email protected]>
AuthorDate: Mon Feb 2 18:15:01 2026 +0530
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Mar 5 12:03:54 2026 +0100

    XLSX: Handle invalid Dates in PivotTable
    
    In Excel, Date can't be later than 9999-12-31.
    
    bug-document: forum-mso-en4-213374.xls
    Change-Id: Ice06439386abd64384e2b5255054b08d610e42a5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198546
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit d223775e011ac1d8253b4488ec2d941b2dd3e8a9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200487
    Tested-by: Jenkins
    Reviewed-by: Karthik Godha <[email protected]>
    (cherry picked from commit 0ab1fda0d8cf63cf53758b1e881aab1f73c523fa)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200782
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sc/source/filter/excel/xepivotxml.cxx 
b/sc/source/filter/excel/xepivotxml.cxx
index bf426177feb1..363e8446d947 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -295,7 +295,21 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( 
XclExpXmlStream& rStrm, const Entr
     pDefStrm->startElement(XML_cacheFields,
         XML_count, OString::number(static_cast<tools::Long>(nCount + 
nGroupFieldCount)));
 
-    auto WriteFieldGroup = [this, &rCache, pDefStrm](size_t i, size_t base) {
+    SvNumberFormatter& rFormatter = GetFormatter();
+
+    // In Excel, DATE can't be later than 9999-12-31.
+    // Number of days from 1900-01-01 to 9999-12-31 is 2958465.
+    constexpr double MAX_DATE = 2.958465e6;
+    auto GetClampedDate = [&](double fVal, double fSub)
+    {
+        if (fVal > MAX_DATE)
+            return GetExcelFormattedDate(fSub, rFormatter);
+        else
+            return GetExcelFormattedDate(fVal, rFormatter);
+    };
+
+    auto WriteFieldGroup = [&rCache, pDefStrm, &GetClampedDate](size_t i, 
size_t base)
+    {
         const sal_Int32 nDatePart = rCache.GetGroupType(i);
         if (!nDatePart)
             return;
@@ -328,15 +342,13 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( 
XclExpXmlStream& rStrm, const Entr
         // fieldGroup element
         pDefStrm->startElement(XML_fieldGroup, XML_base, 
OString::number(base));
 
-        SvNumberFormatter& rFormatter = GetFormatter();
-
         // rangePr element
         const ScDPNumGroupInfo* pGI = rCache.GetNumGroupInfo(i);
         auto pGroupAttList = 
sax_fastparser::FastSerializerHelper::createAttrList();
         pGroupAttList->add(XML_groupBy, sGroupBy);
         // Possible TODO: find out when to write autoStart attribute for years 
grouping
-        pGroupAttList->add(XML_startDate, GetExcelFormattedDate(pGI->mfStart, 
rFormatter).toUtf8());
-        pGroupAttList->add(XML_endDate, GetExcelFormattedDate(pGI->mfEnd, 
rFormatter).toUtf8());
+        pGroupAttList->add(XML_startDate, GetClampedDate(pGI->mfStart, 
0).toUtf8());
+        pGroupAttList->add(XML_endDate, GetClampedDate(pGI->mfEnd, 
MAX_DATE).toUtf8());
         if (pGI->mfStep)
             pGroupAttList->add(XML_groupInterval, 
OString::number(pGI->mfStep));
         pDefStrm->singleElement(XML_rangePr, pGroupAttList);
@@ -457,8 +469,8 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( 
XclExpXmlStream& rStrm, const Entr
 
         if (isContainsDate)
         {
-            pAttList->add(XML_minDate, GetExcelFormattedDate(fMin, 
GetFormatter()).toUtf8());
-            pAttList->add(XML_maxDate, GetExcelFormattedDate(fMax, 
GetFormatter()).toUtf8());
+            pAttList->add(XML_minDate, GetClampedDate(fMin, 0).toUtf8());
+            pAttList->add(XML_maxDate, GetClampedDate(fMax, 
MAX_DATE).toUtf8());
         }
 
         //if (bListItems) // see TODO above
@@ -485,8 +497,13 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( 
XclExpXmlStream& rStrm, const Entr
                     case ScDPItemData::Value:
                         if (isContainsDate)
                         {
-                            pDefStrm->singleElement(XML_d,
-                                XML_v, GetExcelFormattedDate(rItem.GetValue(), 
GetFormatter()).toUtf8());
+                            double fDate = rItem.GetValue();
+                            if (fDate > MAX_DATE)
+                                pDefStrm->singleElement(XML_n, XML_v, 
OString::number(fDate));
+                            else
+                                pDefStrm->singleElement(
+                                    XML_d, XML_v,
+                                    GetExcelFormattedDate(fDate, 
GetFormatter()).toUtf8());
                         }
                         else
                             pDefStrm->singleElement(XML_n,

Reply via email to