sc/inc/document.hxx                         |    1 
 sc/inc/fillinfo.hxx                         |    2 
 sc/inc/patattr.hxx                          |   16 +-
 sc/inc/tablestyle.hxx                       |    3 
 sc/source/core/data/column2.cxx             |    3 
 sc/source/core/data/documen4.cxx            |   27 +++
 sc/source/core/data/fillinfo.cxx            |    6 
 sc/source/core/data/patattr.cxx             |  194 ++++++++++++++++------------
 sc/source/core/data/tablestyle.cxx          |   83 +++++++++++
 sc/source/filter/excel/xestyle.cxx          |    2 
 sc/source/filter/inc/stylesbuffer.hxx       |    2 
 sc/source/filter/oox/defaulttablestyles.cxx |   17 ++
 sc/source/filter/oox/stylesbuffer.cxx       |    8 +
 sc/source/ui/inc/output.hxx                 |    5 
 sc/source/ui/view/cellsh1.cxx               |    4 
 sc/source/ui/view/output2.cxx               |   49 ++++---
 16 files changed, 318 insertions(+), 104 deletions(-)

New commits:
commit 1712a0675546789da597a29495979b21cdc357d1
Author:     Balazs Varga <[email protected]>
AuthorDate: Wed Oct 8 08:16:38 2025 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Mon Nov 17 19:01:15 2025 +0100

    Support Font styles in Table styles
    
    Only Font Weight and Font Color are used in the default Table styles
    Individual cells of Table Font styles can be overwritten by direct cell
    font attributes which can be overwritten by Cond formats.
    
    cherry-pick from: 2c317e5fcad18877310a0da2db710b076ef0be7a
    
    Change-Id: I7c8d78bbff8be51b136b746ac71d490bf1077601
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192470
    Reviewed-by: Balazs Varga <[email protected]>
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193674
    Reviewed-by: Andras Timar <[email protected]>
    Tested-by: Andras Timar <[email protected]>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 436a8b3cb113..51ff4348edd9 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1914,6 +1914,7 @@ public:
     SC_DLLPUBLIC const ScPatternAttr*       GetMostUsedPattern( SCCOL nCol, 
SCROW nStartRow, SCROW nEndRow, SCTAB nTab ) const;
     const ScPatternAttr*                    GetSelectionPattern( const 
ScMarkData& rMark );
     std::unique_ptr<ScPatternAttr>          CreateSelectionPattern( const 
ScMarkData& rMark, bool bDeep = true );
+    SC_DLLPUBLIC const SfxItemSet*          GetTableFormatSet( SCCOL nCol, 
SCROW nRow, SCTAB nTab ) const;
     SC_DLLPUBLIC void                       AddCondFormatData( const 
ScRangeList& rRange, SCTAB nTab, sal_uInt32 nIndex );
     void                                    RemoveCondFormatData( const 
ScRangeList& rRange, SCTAB nTab, sal_uInt32 nIndex );
 
diff --git a/sc/inc/fillinfo.hxx b/sc/inc/fillinfo.hxx
index caecd6a7072b..f42d1dd7f92e 100644
--- a/sc/inc/fillinfo.hxx
+++ b/sc/inc/fillinfo.hxx
@@ -117,6 +117,7 @@ struct ScCellInfo
     ScCellInfo()
         : pPatternAttr(nullptr)
         , pConditionSet(nullptr)
+        , pTableFormatSet(nullptr)
         , pDataBar(nullptr)
         , pIconSet(nullptr)
         , maBackground()
@@ -152,6 +153,7 @@ struct ScCellInfo
 
     const ScPatternAttr*        pPatternAttr;
     const SfxItemSet*           pConditionSet;
+    const SfxItemSet*           pTableFormatSet;
     std::optional<Color>        mxColorScale;
     const ScDataBarInfo*        pDataBar;
     const ScIconSetInfo*        pIconSet;
diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx
index 70e72ba403e6..ab09e64ace83 100644
--- a/sc/inc/patattr.hxx
+++ b/sc/inc/patattr.hxx
@@ -185,6 +185,7 @@ public:
                                         const OutputDevice* pOutDev = nullptr,
                                         const Fraction* pScale = nullptr,
                                         const SfxItemSet* pCondSet = nullptr,
+                                        const SfxItemSet* pTableSet = nullptr,
                                         SvtScriptType nScript = 
SvtScriptType::NONE);
 
     static void fillFont( vcl::Font& rFont, const SfxItemSet& rItemSet,
@@ -192,6 +193,7 @@ public:
                                         const OutputDevice* pOutDev = nullptr,
                                         const Fraction* pScale = nullptr,
                                         const SfxItemSet* pCondSet = nullptr,
+                                        const SfxItemSet* pTableSet = nullptr,
                                         SvtScriptType nScript = 
SvtScriptType::NONE, const Color* pBackConfigColor = nullptr,
                                         const Color* pTextConfigColor = 
nullptr);
 
@@ -199,6 +201,7 @@ public:
                             const SfxItemSet& rItemSet,
                             ScAutoFontColorMode eAutoMode,
                             const SfxItemSet* pCondSet = nullptr,
+                            const SfxItemSet* pTableSet = nullptr,
                             const Color* pBackConfigColor = nullptr,
                             const Color* pTextConfigColor = nullptr);
 
@@ -208,19 +211,21 @@ public:
     void fillColor(model::ComplexColor& rComplexColor,
                     ScAutoFontColorMode eAutoMode,
                     const SfxItemSet* pCondSet = nullptr,
+                    const SfxItemSet* pTableSet = nullptr,
                     const Color* pBackConfigColor = nullptr,
                     const Color* pTextConfigColor = nullptr) const
     {
-        fillColor(rComplexColor, maLocalSfxItemSet, eAutoMode, pCondSet, 
pBackConfigColor, pTextConfigColor);
+        fillColor(rComplexColor, maLocalSfxItemSet, eAutoMode, pCondSet, 
pTableSet, pBackConfigColor, pTextConfigColor);
     }
 
     void fillFontOnly(vcl::Font& rFont,
                     const OutputDevice* pOutDev = nullptr,
                     const Fraction* pScale = nullptr,
                     const SfxItemSet* pCondSet = nullptr,
+                    const SfxItemSet* pTableSet = nullptr,
                     SvtScriptType nScript = SvtScriptType::NONE) const
     {
-        fillFontOnly(rFont, maLocalSfxItemSet, pOutDev, pScale, pCondSet, 
nScript);
+        fillFontOnly(rFont, maLocalSfxItemSet, pOutDev, pScale, pCondSet, 
pTableSet, nScript);
     }
 
     /** Fills a font object from the own item set. */
@@ -228,17 +233,18 @@ public:
                     const OutputDevice* pOutDev = nullptr,
                     const Fraction* pScale = nullptr,
                     const SfxItemSet* pCondSet = nullptr,
+                    const SfxItemSet* pTableSet = nullptr,
                     SvtScriptType nScript = SvtScriptType::NONE,
                     const Color* pBackConfigColor = nullptr,
                     const Color* pTextConfigColor = nullptr) const
     {
-        fillFont(rFont, maLocalSfxItemSet, eAutoMode, pOutDev, pScale, 
pCondSet, nScript, pBackConfigColor, pTextConfigColor);
+        fillFont(rFont, maLocalSfxItemSet, eAutoMode, pOutDev, pScale, 
pCondSet, pTableSet, nScript, pBackConfigColor, pTextConfigColor);
     }
 
     /** Converts all Calc items contained in rSrcSet to edit engine items and 
puts them into rEditSet. */
-    SC_DLLPUBLIC static void             FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet = nullptr );
+    SC_DLLPUBLIC static void             FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet = nullptr, 
const SfxItemSet* pTableSet = nullptr );
     /** Converts all Calc items contained in the own item set to edit engine 
items and puts them into pEditSet. */
-    SC_DLLPUBLIC void                    FillEditItemSet( SfxItemSet* 
pEditSet, const SfxItemSet* pCondSet = nullptr ) const;
+    SC_DLLPUBLIC void                    FillEditItemSet( SfxItemSet* 
pEditSet, const SfxItemSet* pCondSet = nullptr, const SfxItemSet* pTableSet = 
nullptr ) const;
 
     /** Converts all edit engine items contained in rEditSet to Calc items and 
puts them into rDestSet. */
     SC_DLLPUBLIC static void             GetFromEditItemSet( SfxItemSet& 
rDestSet, const SfxItemSet& rEditSet );
diff --git a/sc/inc/tablestyle.hxx b/sc/inc/tablestyle.hxx
index fd39336e71a1..e14bbb486aaf 100644
--- a/sc/inc/tablestyle.hxx
+++ b/sc/inc/tablestyle.hxx
@@ -173,6 +173,9 @@ public:
         return nullptr;
     }
 
+    const SfxItemSet* GetTableCellItemSet(const ScDBData& rDBData, SCCOL nCol, 
SCROW nRow,
+                                          SCROW nRowIndex) const;
+
     void SetRowStripeSize(sal_Int32 nFirstRowStripeSize, sal_Int32 
nSecondRowStripeSize);
     void SetColStripeSize(sal_Int32 nFirstColStripeSize, sal_Int32 
nSecondColStripeSize);
 
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index a045f0bfc6e0..ef26baa5bf04 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -285,7 +285,8 @@ tools::Long ScColumn::GetNeededSize(
         vcl::Font aFont;
         aFont.SetKerning(FontKerning::NONE); // like 
ScDrawStringsVars::SetPattern
         // font color doesn't matter here
-        pPattern->fillFontOnly(aFont, pDev, &aFontZoom, pCondSet, nScript);
+        const SfxItemSet* pTableSet = rDocument.GetTableFormatSet( nCol, nRow, 
nTab );
+        pPattern->fillFontOnly(aFont, pDev, &aFontZoom, pCondSet, pTableSet, 
nScript);
         pDev->SetFont(aFont);
     }
 
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index af2044861f36..9fa423eee0fa 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -29,6 +29,7 @@
 #include <document.hxx>
 #include <docsh.hxx>
 #include <table.hxx>
+#include <dbdata.hxx>
 #include <globstr.hrc>
 #include <scresid.hxx>
 #include <subtotal.hxx>
@@ -47,6 +48,7 @@
 #include <externalrefmgr.hxx>
 #include <attrib.hxx>
 #include <formulacell.hxx>
+#include <tablestyle.hxx>
 #include <tokenarray.hxx>
 #include <tokenstringcontext.hxx>
 #include <memory>
@@ -791,6 +793,31 @@ const SfxPoolItem* ScDocument::GetEffItem(
     return nullptr;
 }
 
+const SfxItemSet* ScDocument::GetTableFormatSet(SCCOL nCol, SCROW nRow, SCTAB 
nTab) const
+{
+    const ScDBData* pDBData = GetDBAtCursor(nCol, nRow, nTab, 
ScDBDataPortion::AREA);
+    if (pDBData)
+    {
+        const ScTableStyleParam* pTableStyleInfo = 
pDBData->GetTableStyleInfo();
+        if (!pTableStyleInfo)
+            return nullptr;
+
+        const ScTableStyle* pTableStyle = 
mpTableStyles->GetTableStyle(pTableStyleInfo->maStyleName);
+        if (!pTableStyle)
+            return nullptr;
+
+        SCROW nNonEmptyRowsBeforePaintRange = 
-static_cast<SCROW>(pDBData->HasHeader());
+        ScRange aDBRange;
+        pDBData->GetArea(aDBRange);
+        if (aDBRange.aStart.Row() < nRow)
+        {
+            nNonEmptyRowsBeforePaintRange += 
this->CountNonFilteredRows(aDBRange.aStart.Row(), nRow - 1, nTab);
+        }
+        return pTableStyle->GetTableCellItemSet(*pDBData, nCol, nRow, 
nNonEmptyRowsBeforePaintRange);
+    }
+    return nullptr;
+}
+
 const SfxItemSet* ScDocument::GetCondResult( SCCOL nCol, SCROW nRow, SCTAB 
nTab, ScRefCellValue* pCell ) const
 {
     ScConditionalFormatList* pFormatList = GetCondFormList(nTab);
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 482feb3f3c5e..17dca4a5544c 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -458,6 +458,12 @@ void ScDocument::FillInfo(
                 {
                     pInfo->pLinesAttr = pLinesAttr;
                 }
+
+                const SfxItemSet* pPoolItem = 
pTableStyle->GetTableCellItemSet(*pDBData, nCol, nRow, nRowIndex);
+                if (pPoolItem)
+                {
+                    pInfo->pTableFormatSet = pPoolItem;
+                }
             }
 
             ++nRowIndex;
diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index 60225c17532a..3e8f671bb9d7 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -553,23 +553,56 @@ void getFontIDsByScriptType(SvtScriptType nScript,
 void ScPatternAttr::fillFont(
         vcl::Font& rFont, const SfxItemSet& rItemSet, ScAutoFontColorMode 
eAutoMode,
         const OutputDevice* pOutDev, const Fraction* pScale,
-        const SfxItemSet* pCondSet, SvtScriptType nScript,
+        const SfxItemSet* pCondSet, const SfxItemSet* pTableSet, SvtScriptType 
nScript,
         const Color* pBackConfigColor, const Color* pTextConfigColor)
 {
     model::ComplexColor aComplexColor;
 
     //  determine effective font color
-    ScPatternAttr::fillFontOnly(rFont, rItemSet, pOutDev, pScale, pCondSet, 
nScript);
-    ScPatternAttr::fillColor(aComplexColor, rItemSet, eAutoMode, pCondSet, 
pBackConfigColor, pTextConfigColor);
+    ScPatternAttr::fillFontOnly(rFont, rItemSet, pOutDev, pScale, pCondSet, 
pTableSet, nScript);
+    ScPatternAttr::fillColor(aComplexColor, rItemSet, eAutoMode, pCondSet, 
pTableSet, pBackConfigColor, pTextConfigColor);
 
     //  set font effects
     rFont.SetColor(aComplexColor.getFinalColor());
 }
 
+template <class T>
+static const T* lcl_populateresult( TypedWhichId<T> nWhich, const SfxItemSet& 
rSrcSet, const SfxItemSet* pCondSet, const SfxItemSet* pTableSet = nullptr )
+{
+    const T* pItem = nullptr;
+
+    if (pCondSet)
+        pItem = pCondSet->GetItemIfSet(nWhich);
+
+    if (!pItem && pTableSet)
+    {
+        const SfxPoolItem* pThisItem;
+        if (rSrcSet.GetItemState(nWhich, false, &pThisItem) == 
SfxItemState::SET
+            && *pThisItem != 
rSrcSet.GetPool()->GetUserOrPoolDefaultItem(nWhich))
+        {
+            // use the direct cell format value againts the Table style format
+            // if it not a default one (COL_BLACK is the default in case of 
Table Styles)
+            // on the cell level
+            if (sal_uInt16(nWhich) == ATTR_FONT_COLOR
+                && rSrcSet.GetItem(ATTR_FONT_COLOR)->getColor() == COL_BLACK)
+                pItem = pTableSet->GetItemIfSet(nWhich);
+            else
+                pItem = &rSrcSet.Get(nWhich);
+        }
+        else
+            pItem = pTableSet->GetItemIfSet(nWhich);
+    }
+
+    if (!pItem)
+        pItem = &rSrcSet.Get(nWhich);
+
+    return pItem;
+}
+
 void ScPatternAttr::fillFontOnly(
         vcl::Font& rFont, const SfxItemSet& rItemSet,
         const OutputDevice* pOutDev, const Fraction* pScale,
-        const SfxItemSet* pCondSet, SvtScriptType nScript)
+        const SfxItemSet* pCondSet, const SfxItemSet* pTableSet, SvtScriptType 
nScript)
 {
     // Read items
 
@@ -596,18 +629,12 @@ void ScPatternAttr::fillFontOnly(
 
     if (pCondSet)
     {
-        pFontAttr = pCondSet->GetItemIfSet( nFontId );
-        if ( !pFontAttr )
-            pFontAttr = &rItemSet.Get( nFontId );
+        pFontAttr = lcl_populateresult( nFontId, rItemSet, pCondSet, pTableSet 
);
 
-        const SvxFontHeightItem* pFontHeightItem = pCondSet->GetItemIfSet( 
nHeightId );
-        if ( !pFontHeightItem )
-            pFontHeightItem = &rItemSet.Get( nHeightId );
+        const SvxFontHeightItem* pFontHeightItem = lcl_populateresult( 
nHeightId, rItemSet, pCondSet, pTableSet );
         nFontHeight = pFontHeightItem->GetHeight();
 
-        const SvxWeightItem* pFontHWeightItem = pCondSet->GetItemIfSet( 
nWeightId );
-        if ( !pFontHWeightItem )
-            pFontHWeightItem = &rItemSet.Get( nWeightId );
+        const SvxWeightItem* pFontHWeightItem = lcl_populateresult( nWeightId, 
rItemSet, pCondSet, pTableSet );
         eWeight = pFontHWeightItem->GetValue();
 
         const SvxPostureItem* pPostureItem = pCondSet->GetItemIfSet( 
nPostureId );
@@ -662,9 +689,14 @@ void ScPatternAttr::fillFontOnly(
     }
     else    // Everything from rItemSet
     {
-        pFontAttr = &rItemSet.Get( nFontId );
-        nFontHeight = rItemSet.Get( nHeightId ).GetHeight();
-        eWeight = rItemSet.Get( nWeightId ).GetValue();
+        pFontAttr = lcl_populateresult( nFontId, rItemSet, pCondSet, pTableSet 
);
+
+        const SvxFontHeightItem* pFontHeightItem = lcl_populateresult( 
nHeightId, rItemSet, pCondSet, pTableSet );
+        nFontHeight = pFontHeightItem->GetHeight();
+
+        const SvxWeightItem* pFontHWeightItem = lcl_populateresult( nWeightId, 
rItemSet, pCondSet, pTableSet );
+        eWeight = pFontHWeightItem->GetValue();
+
         eItalic = rItemSet.Get( nPostureId ).GetValue();
         eUnder = rItemSet.Get( ATTR_FONT_UNDERLINE ).GetValue();
         eOver = rItemSet.Get( ATTR_FONT_OVERLINE ).GetValue();
@@ -735,20 +767,13 @@ void ScPatternAttr::fillFontOnly(
     rFont.SetTransparent( true );
 }
 
-void ScPatternAttr::fillColor(model::ComplexColor& rComplexColor, const 
SfxItemSet& rItemSet, ScAutoFontColorMode eAutoMode, const SfxItemSet* 
pCondSet, const Color* pBackConfigColor, const Color* pTextConfigColor)
+void ScPatternAttr::fillColor(model::ComplexColor& rComplexColor, const 
SfxItemSet& rItemSet, ScAutoFontColorMode eAutoMode, const SfxItemSet* 
pCondSet, const SfxItemSet* pTableSet, const Color* pBackConfigColor, const 
Color* pTextConfigColor)
 {
-    model::ComplexColor aComplexColor;
+    const SvxColorItem* pColorItem
+        = lcl_populateresult(ATTR_FONT_COLOR, rItemSet, pCondSet, pTableSet);
 
     Color aColor;
-
-    SvxColorItem const* pColorItem = nullptr;
-
-    if (pCondSet)
-        pColorItem = pCondSet->GetItemIfSet(ATTR_FONT_COLOR);
-
-    if (!pColorItem)
-        pColorItem = &rItemSet.Get(ATTR_FONT_COLOR);
-
+    model::ComplexColor aComplexColor;
     if (pColorItem)
     {
         aComplexColor = pColorItem->getComplexColor();
@@ -765,18 +790,12 @@ void ScPatternAttr::fillColor(model::ComplexColor& 
rComplexColor, const SfxItemS
         || eAutoMode == ScAutoFontColorMode::IgnoreAll)
     {
         //  get background color from conditional or own set
+        const SvxBrushItem* pItem
+            = lcl_populateresult(ATTR_BACKGROUND, rItemSet, pCondSet, 
pTableSet);
+
         Color aBackColor;
-        if ( pCondSet )
-        {
-            const SvxBrushItem* pItem = 
pCondSet->GetItemIfSet(ATTR_BACKGROUND);
-            if (!pItem)
-                pItem = &rItemSet.Get(ATTR_BACKGROUND);
+        if (pItem)
             aBackColor = pItem->GetColor();
-        }
-        else
-        {
-            aBackColor = rItemSet.Get(ATTR_BACKGROUND).GetColor();
-        }
 
         //  if background color attribute is transparent, use window color for 
brightness comparisons
         if (aBackColor == COL_TRANSPARENT
@@ -936,15 +955,39 @@ ScDxfFont ScPatternAttr::GetDxfFont(const SfxItemSet& 
rItemSet, SvtScriptType nS
 }
 
 template <class T>
-static void lcl_populate( std::unique_ptr<T>& rxItem, TypedWhichId<T> nWhich, 
const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet )
+static void lcl_populate( std::unique_ptr<T>& rxItem, TypedWhichId<T> nWhich, 
const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet, const SfxItemSet* 
pTableSet = nullptr )
 {
-    const T* pItem = pCondSet->GetItemIfSet( nWhich );
-    if ( !pItem )
-        pItem = &rSrcSet.Get( nWhich );
+    const T* pItem = nullptr;
+
+    if (pCondSet)
+        pItem = pCondSet->GetItemIfSet(nWhich);
+
+    if (!pItem && pTableSet)
+    {
+        const SfxPoolItem* pThisItem;
+        if (rSrcSet.GetItemState(nWhich, false, &pThisItem) == 
SfxItemState::SET
+            && *pThisItem != 
rSrcSet.GetPool()->GetUserOrPoolDefaultItem(nWhich))
+        {
+            // use the direct cell format value againts the Table style format
+            // if it not a default one (COL_BLACK is the default in case of 
Table Styles)
+            // on the cell level
+            if (sal_uInt16(nWhich) == ATTR_FONT_COLOR
+                && rSrcSet.GetItem(ATTR_FONT_COLOR)->getColor() == COL_BLACK)
+                pItem = pTableSet->GetItemIfSet(nWhich);
+            else
+                pItem = &rSrcSet.Get(nWhich);
+        }
+        else
+            pItem = pTableSet->GetItemIfSet(nWhich);
+    }
+
+    if (!pItem)
+        pItem = &rSrcSet.Get(nWhich);
+
     rxItem.reset(pItem->Clone());
 }
 
-void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& 
rSrcSet, const SfxItemSet* pCondSet )
+void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& 
rSrcSet, const SfxItemSet* pCondSet, const SfxItemSet* pTableSet )
 {
     //  Read Items
 
@@ -972,35 +1015,23 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& r
 
     if ( pCondSet )
     {
-        lcl_populate(aColorItem, ATTR_FONT_COLOR, rSrcSet, pCondSet);
-        lcl_populate(aFontItem, ATTR_FONT, rSrcSet, pCondSet);
-        lcl_populate(aCjkFontItem, ATTR_CJK_FONT, rSrcSet, pCondSet);
-        lcl_populate(aCtlFontItem, ATTR_CTL_FONT, rSrcSet, pCondSet);
-
-        const SvxFontHeightItem* pFontHeightItem = pCondSet->GetItemIfSet( 
ATTR_FONT_HEIGHT );
-        if (!pFontHeightItem)
-            pFontHeightItem = &rSrcSet.Get( ATTR_FONT_HEIGHT );
+        lcl_populate(aColorItem, ATTR_FONT_COLOR, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(aFontItem, ATTR_FONT, rSrcSet, pCondSet, pTableSet);
+        lcl_populate(aCjkFontItem, ATTR_CJK_FONT, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(aCtlFontItem, ATTR_CTL_FONT, rSrcSet, pCondSet, 
pTableSet);
+
+        const SvxFontHeightItem* pFontHeightItem = lcl_populateresult( 
ATTR_FONT_HEIGHT, rSrcSet, pCondSet, pTableSet );
         nTHeight = pFontHeightItem->GetHeight();
-        pFontHeightItem = pCondSet->GetItemIfSet( ATTR_CJK_FONT_HEIGHT );
-        if ( !pFontHeightItem )
-            pFontHeightItem = &rSrcSet.Get( ATTR_CJK_FONT_HEIGHT );
+        pFontHeightItem = lcl_populateresult( ATTR_CJK_FONT_HEIGHT, rSrcSet, 
pCondSet, pTableSet );
         nCjkTHeight = pFontHeightItem->GetHeight();
-        pFontHeightItem = pCondSet->GetItemIfSet( ATTR_CTL_FONT_HEIGHT );
-        if ( !pFontHeightItem )
-            pFontHeightItem = &rSrcSet.Get( ATTR_CTL_FONT_HEIGHT );
+        pFontHeightItem = lcl_populateresult( ATTR_CTL_FONT_HEIGHT, rSrcSet, 
pCondSet, pTableSet );
         nCtlTHeight = pFontHeightItem->GetHeight();
 
-        const SvxWeightItem* pWeightItem = pCondSet->GetItemIfSet( 
ATTR_FONT_WEIGHT );
-        if ( !pWeightItem )
-            pWeightItem = &rSrcSet.Get( ATTR_FONT_WEIGHT );
+        const SvxWeightItem* pWeightItem = lcl_populateresult( 
ATTR_FONT_WEIGHT, rSrcSet, pCondSet, pTableSet );
         eWeight = pWeightItem->GetValue();
-        pWeightItem = pCondSet->GetItemIfSet( ATTR_CJK_FONT_WEIGHT );
-        if ( !pWeightItem )
-            pWeightItem = &rSrcSet.Get( ATTR_CJK_FONT_WEIGHT );
+        pWeightItem = lcl_populateresult( ATTR_CJK_FONT_WEIGHT, rSrcSet, 
pCondSet, pTableSet );
         eCjkWeight = pWeightItem->GetValue();
-        pWeightItem = pCondSet->GetItemIfSet( ATTR_CTL_FONT_WEIGHT );
-        if ( !pWeightItem )
-            pWeightItem = &rSrcSet.Get( ATTR_CTL_FONT_WEIGHT );
+        pWeightItem = lcl_populateresult( ATTR_CTL_FONT_WEIGHT, rSrcSet, 
pCondSet, pTableSet );
         eCtlWeight = pWeightItem->GetValue();
 
         const SvxPostureItem* pPostureItem = pCondSet->GetItemIfSet( 
ATTR_FONT_POSTURE );
@@ -1078,16 +1109,25 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& r
     }
     else        // Everything directly from Pattern
     {
-        aColorItem.reset(rSrcSet.Get(ATTR_FONT_COLOR).Clone());
-        aFontItem.reset(rSrcSet.Get(ATTR_FONT).Clone());
-        aCjkFontItem.reset(rSrcSet.Get(ATTR_CJK_FONT).Clone());
-        aCtlFontItem.reset(rSrcSet.Get(ATTR_CTL_FONT).Clone());
-        nTHeight = rSrcSet.Get( ATTR_FONT_HEIGHT ).GetHeight();
-        nCjkTHeight = rSrcSet.Get( ATTR_CJK_FONT_HEIGHT ).GetHeight();
-        nCtlTHeight = rSrcSet.Get( ATTR_CTL_FONT_HEIGHT ).GetHeight();
-        eWeight = rSrcSet.Get( ATTR_FONT_WEIGHT ).GetValue();
-        eCjkWeight = rSrcSet.Get( ATTR_CJK_FONT_WEIGHT ).GetValue();
-        eCtlWeight = rSrcSet.Get( ATTR_CTL_FONT_WEIGHT ).GetValue();
+        lcl_populate(aColorItem, ATTR_FONT_COLOR, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(aFontItem, ATTR_FONT, rSrcSet, pCondSet, pTableSet);
+        lcl_populate(aCjkFontItem, ATTR_CJK_FONT, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(aCtlFontItem, ATTR_CTL_FONT, rSrcSet, pCondSet, 
pTableSet);
+
+        const SvxFontHeightItem* pFontHeightItem = 
lcl_populateresult(ATTR_FONT_HEIGHT, rSrcSet, pCondSet, pTableSet);
+        nTHeight = pFontHeightItem->GetHeight();
+        pFontHeightItem = lcl_populateresult(ATTR_CJK_FONT_HEIGHT, rSrcSet, 
pCondSet, pTableSet);
+        nCjkTHeight = pFontHeightItem->GetHeight();
+        pFontHeightItem = lcl_populateresult(ATTR_CTL_FONT_HEIGHT, rSrcSet, 
pCondSet, pTableSet);
+        nCtlTHeight = pFontHeightItem->GetHeight();
+
+        const SvxWeightItem* pWeightItem = 
lcl_populateresult(ATTR_FONT_WEIGHT, rSrcSet, pCondSet, pTableSet);
+        eWeight = pWeightItem->GetValue();
+        pWeightItem = lcl_populateresult(ATTR_CJK_FONT_WEIGHT, rSrcSet, 
pCondSet, pTableSet);
+        eCjkWeight = pWeightItem->GetValue();
+        pWeightItem = lcl_populateresult(ATTR_CTL_FONT_WEIGHT, rSrcSet, 
pCondSet, pTableSet);
+        eCtlWeight = pWeightItem->GetValue();
+
         eItalic = rSrcSet.Get( ATTR_FONT_POSTURE ).GetValue();
         eCjkItalic = rSrcSet.Get( ATTR_CJK_FONT_POSTURE ).GetValue();
         eCtlItalic = rSrcSet.Get( ATTR_CTL_FONT_POSTURE ).GetValue();
@@ -1170,10 +1210,10 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& r
     rEditSet.Put( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING ) );
 }
 
-void ScPatternAttr::FillEditItemSet( SfxItemSet* pEditSet, const SfxItemSet* 
pCondSet ) const
+void ScPatternAttr::FillEditItemSet( SfxItemSet* pEditSet, const SfxItemSet* 
pCondSet, const SfxItemSet* pTableSet ) const
 {
     if( pEditSet )
-        FillToEditItemSet( *pEditSet, GetItemSet(), pCondSet );
+        FillToEditItemSet( *pEditSet, GetItemSet(), pCondSet, pTableSet );
 }
 
 void ScPatternAttr::GetFromEditItemSet( SfxItemSet& rDestSet, const 
SfxItemSet& rEditSet )
diff --git a/sc/source/core/data/tablestyle.cxx 
b/sc/source/core/data/tablestyle.cxx
index bb032aa06953..5ee0229c9704 100644
--- a/sc/source/core/data/tablestyle.cxx
+++ b/sc/source/core/data/tablestyle.cxx
@@ -20,6 +20,89 @@ ScTableStyle::ScTableStyle(const OUString& rName, const 
std::optional<OUString>&
 {
 }
 
+const SfxItemSet* ScTableStyle::GetTableCellItemSet(const ScDBData& rDBData, 
SCCOL nCol, SCROW nRow,
+                                                    SCROW nRowIndex) const
+{
+    const ScTableStyleParam* pParam = rDBData.GetTableStyleInfo();
+    ScRange aRange;
+    rDBData.GetArea(aRange);
+
+    bool bHasHeader = rDBData.HasHeader();
+    bool bHasTotal = rDBData.HasTotals();
+    if (bHasHeader && mpLastHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aEnd.Col())
+    {
+        return &mpLastHeaderCellPattern->GetItemSet();
+    }
+
+    if (bHasHeader && mpFirstHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aStart.Col())
+    {
+        return &mpFirstHeaderCellPattern->GetItemSet();
+    }
+
+    if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
+    {
+        return &mpTotalRowPattern->GetItemSet();
+    }
+
+    if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
+    {
+        return &mpHeaderRowPattern->GetItemSet();
+    }
+
+    if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
+    {
+        return &mpFirstColumnPattern->GetItemSet();
+    }
+
+    if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
+    {
+        return &mpLastColumnPattern->GetItemSet();
+    }
+
+    if (!bHasTotal || aRange.aEnd.Row() != nRow)
+    {
+        if (pParam->mbRowStripes && nRowIndex >= 0)
+        {
+            sal_Int32 nTotalRowStripPattern = mnFirstRowStripeSize + 
mnSecondRowStripeSize;
+            bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
+            if (mpSecondRowStripePattern && !bFirstRowStripe)
+            {
+                return &mpSecondRowStripePattern->GetItemSet();
+            }
+
+            if (mpFirstRowStripePattern && bFirstRowStripe)
+            {
+                return &mpFirstRowStripePattern->GetItemSet();
+            }
+        }
+
+        if (pParam->mbColumnStripes)
+        {
+            SCCOL nRelativeCol = nCol - aRange.aStart.Col();
+            sal_Int32 nTotalColStripePattern = mnFirstColStripeSize + 
mnSecondColStripeSize;
+            bool bFirstColStripe = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
+            if (mpSecondColumnStripePattern && !bFirstColStripe)
+            {
+                return &mpSecondColumnStripePattern->GetItemSet();
+            }
+
+            if (mpFirstColumnStripePattern && bFirstColStripe)
+            {
+                return &mpFirstColumnStripePattern->GetItemSet();
+            }
+        }
+    }
+
+    if (mpTablePattern)
+    {
+        return &mpTablePattern->GetItemSet();
+    }
+
+    return nullptr;
+}
+
 void ScTableStyle::SetRowStripeSize(sal_Int32 nFirstRowStripeSize, sal_Int32 
nSecondRowStripeSize)
 {
     if (nFirstRowStripeSize >= 1)
diff --git a/sc/source/filter/excel/xestyle.cxx 
b/sc/source/filter/excel/xestyle.cxx
index 9f92e224868e..276de3b7a774 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -897,7 +897,7 @@ vcl::Font XclExpFontHelper::GetFontFromItemSet( const 
XclExpRoot& rRoot, const S
 
     // fill the font object
     vcl::Font aFont;
-    ScPatternAttr::fillFontOnly(aFont, rItemSet, nullptr, nullptr, nullptr, 
nScScript);
+    ScPatternAttr::fillFontOnly(aFont, rItemSet, nullptr, nullptr, nullptr, 
nullptr, nScScript);
     return aFont;
 }
 
diff --git a/sc/source/filter/inc/stylesbuffer.hxx 
b/sc/source/filter/inc/stylesbuffer.hxx
index 3181c80e7313..2078375318ff 100644
--- a/sc/source/filter/inc/stylesbuffer.hxx
+++ b/sc/source/filter/inc/stylesbuffer.hxx
@@ -215,6 +215,8 @@ public:
 
     /** Sets font formatting attributes for the passed element. */
     void                importAttribs( sal_Int32 nElement, const 
AttributeList& rAttribs );
+    /** Sets font formatting attributes for OOXML default table styles. */
+    void                setFontElements( const XlsColor& rColor, bool bWeight 
);
 
     /** Imports the FONT record from the passed stream. */
     void                importFont( SequenceInputStream& rStrm );
diff --git a/sc/source/filter/oox/defaulttablestyles.cxx 
b/sc/source/filter/oox/defaulttablestyles.cxx
index 8d3f9b948a82..e7698b6c1dc9 100644
--- a/sc/source/filter/oox/defaulttablestyles.cxx
+++ b/sc/source/filter/oox/defaulttablestyles.cxx
@@ -101,7 +101,19 @@ void DefaultOOXMLTableStyles::importBorders()
     }
 }
 
-void DefaultOOXMLTableStyles::importFonts() {}
+void DefaultOOXMLTableStyles::importFonts()
+{
+    size_t nFonts = sizeof(aFonts) / sizeof(Font);
+    for (size_t i = 0; i < nFonts; ++i)
+    {
+        auto xFont = std::make_shared<oox::xls::Font>(*this, true);
+
+        const Font& rFontInfo = aFonts[i];
+        xFont->setFontElements(maColors[rFontInfo.nThemeColorId], 
rFontInfo.bBold);
+
+        maFonts.push_back(xFont);
+    }
+}
 
 void DefaultOOXMLTableStyles::importDxfs()
 {
@@ -117,6 +129,9 @@ void DefaultOOXMLTableStyles::importDxfs()
         if (aDxfInfo.nBorderId >= 0)
             xDxf->setBorder(maBorders[aDxfInfo.nBorderId]);
 
+        if (aDxfInfo.nFontId >= 0)
+            xDxf->setFont(maFonts[aDxfInfo.nFontId]);
+
         xDxf->finalizeImport();
         maDxfs.push_back(xDxf);
     }
diff --git a/sc/source/filter/oox/stylesbuffer.cxx 
b/sc/source/filter/oox/stylesbuffer.cxx
index be9c7a4aae56..bca26fb941ed 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -627,6 +627,14 @@ void Font::importAttribs( sal_Int32 nElement, const 
AttributeList& rAttribs )
     }
 }
 
+void Font::setFontElements(const XlsColor& rColor, bool bWeight)
+{
+    maModel.maColor = rColor;
+    maUsedFlags.mbColorUsed = true;
+    maModel.mbBold = bWeight;
+    maUsedFlags.mbWeightUsed = true;
+}
+
 void Font::importFont( SequenceInputStream& rStrm )
 {
     SAL_WARN_IF( mbDxf, "sc", "Font::importFont - unexpected conditional 
formatting flag" );
diff --git a/sc/source/ui/inc/output.hxx b/sc/source/ui/inc/output.hxx
index 265e9d64c97b..f086fdec6e89 100644
--- a/sc/source/ui/inc/output.hxx
+++ b/sc/source/ui/inc/output.hxx
@@ -150,14 +150,16 @@ private:
         ScRefCellValue          maCell;
         const ScPatternAttr*    mpPattern;
         const SfxItemSet*       mpCondSet;
+        const SfxItemSet*       mpTableSet;
         const SfxItemSet*       mpPreviewFontSet;
         const ScPatternAttr*    mpOldPattern;
         const SfxItemSet*       mpOldCondSet;
+        const SfxItemSet*       mpOldTableSet;
         const SfxItemSet*       mpOldPreviewFontSet;
         RowInfo*                mpThisRowInfo;
         sc::MisspellRangeResult maMisspellRanges;
 
-        explicit DrawEditParam(const ScPatternAttr* pPattern, const 
SfxItemSet* pCondSet, bool bCellIsValue);
+        explicit DrawEditParam(const ScPatternAttr* pPattern, const 
SfxItemSet* pCondSet, const SfxItemSet* pTableSet, bool bCellIsValue);
 
         bool readCellContent(const ScDocument* pDoc, bool bShowNullValues, 
bool bShowFormulas, bool bSyntaxMode, bool bUseStyleColor, bool 
bForceAutoColor, bool& rWrapFields);
         void setPatternToEngine(bool bUseStyleColor);
@@ -322,6 +324,7 @@ private:
                            std::vector<std::unique_ptr<ScPatternAttr> >& 
aAltPatterns,
                            const ScPatternAttr*& pOldPattern,
                            const SfxItemSet*& pOldCondSet,
+                           const SfxItemSet*& pOldTableSet,
                            SvtScriptType& nOldScript,
                            ScDrawStringsVars& aVars,
                            bool& bProgress, tools::Long nPosX, tools::Long 
nPosY, bool bTaggedPDF,
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 9d53ed8739ef..34b8981e1651 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2958,7 +2958,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 if ( !aChars.isEmpty() )
                 {
                     vcl::Font aFont;
-                    pTabViewShell->GetSelectionPattern()->fillFontOnly(aFont, 
nullptr, nullptr, nullptr,
+                    pTabViewShell->GetSelectionPattern()->fillFontOnly(aFont, 
nullptr, nullptr, nullptr, nullptr,
                                                                 
pTabViewShell->GetSelectionScriptType() );
                     if ( !aFontName.isEmpty() )
                         aFont = vcl::Font( aFontName, Size(1,1) );
@@ -2973,7 +2973,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
 
                 // font color doesn't matter here
                 vcl::Font aCurFont;
-                pTabViewShell->GetSelectionPattern()->fillFontOnly(aCurFont, 
nullptr, nullptr, nullptr,
+                pTabViewShell->GetSelectionPattern()->fillFontOnly(aCurFont, 
nullptr, nullptr, nullptr, nullptr,
                                                                 
pTabViewShell->GetSelectionScriptType());
 
                 SfxAllItemSet aSet( GetPool() );
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 4432e7003166..a93aa53ba8cb 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -99,6 +99,7 @@ class ScDrawStringsVars
 
     const ScPatternAttr* pPattern;              // attribute
     const SfxItemSet*   pCondSet;               // from conditional formatting
+    const SfxItemSet*   pTableSet;              // from table formatting
 
     vcl::Font           aFont;                  // created from attributes
     FontMetric          aMetric;
@@ -140,7 +141,7 @@ public:
                 //  SetPatternSimple: without Font
 
     void SetPattern(
-        const ScPatternAttr* pNew, const SfxItemSet* pSet, const 
ScRefCellValue& rCell,
+        const ScPatternAttr* pNew, const SfxItemSet* pSet, const SfxItemSet* 
pTSet, const ScRefCellValue& rCell,
         SvtScriptType nScript );
 
     void        SetPatternSimple( const ScPatternAttr* pNew, const SfxItemSet* 
pSet );
@@ -202,6 +203,7 @@ ScDrawStringsVars::ScDrawStringsVars(ScOutputData* pData, 
bool bPTL) :
     pOutput     ( pData ),
     pPattern    ( nullptr ),
     pCondSet    ( nullptr ),
+    pTableSet   ( nullptr ),
     nAscentPixel(0),
     eAttrOrient ( SvxCellOrientation::Standard ),
     eAttrHorJust( SvxCellHorJustify::Standard ),
@@ -245,7 +247,7 @@ void ScDrawStringsVars::SetShrinkScale( tools::Long nScale, 
SvtScriptType nScrip
     if ( !bPixelToLogic )
         aFraction *= pOutput->maZoomY;
     vcl::Font aTmpFont;
-    pPattern->fillFontOnly(aTmpFont, pFmtDevice, &aFraction, pCondSet, 
nScript);
+    pPattern->fillFontOnly(aTmpFont, pFmtDevice, &aFraction, pCondSet, 
pTableSet, nScript);
     // only need font height
     tools::Long nNewHeight = aTmpFont.GetFontHeight();
     if ( nNewHeight > 0 )
@@ -297,9 +299,7 @@ static bool lcl_isNumberFormatText(const ScDocument* pDoc, 
SCCOL nCellX, SCROW n
     return pNumberFormatter->GetType( nCurrentNumberFormat ) == 
SvNumFormatType::TEXT;
 }
 
-void ScDrawStringsVars::SetPattern(
-    const ScPatternAttr* pNew, const SfxItemSet* pSet, const ScRefCellValue& 
rCell,
-    SvtScriptType nScript )
+void ScDrawStringsVars::SetPattern( const ScPatternAttr* pNew, const 
SfxItemSet* pSet, const SfxItemSet* pTSet, const ScRefCellValue& rCell, 
SvtScriptType nScript )
 {
     nMaxDigitWidth = 0;
     nSignWidth     = 0;
@@ -308,6 +308,7 @@ void ScDrawStringsVars::SetPattern(
 
     pPattern = pNew;
     pCondSet = pSet;
+    pTableSet = pTSet;
 
     // evaluate pPattern
 
@@ -329,9 +330,9 @@ void ScDrawStringsVars::SetPattern(
         eColorMode = ScAutoFontColorMode::Print;
 
     if (bPixelToLogic)
-        pPattern->fillFont(aFont, eColorMode, pFmtDevice, nullptr, pCondSet, 
nScript, &aBackConfigColor, &aTextConfigColor);
+        pPattern->fillFont(aFont, eColorMode, pFmtDevice, nullptr, pCondSet, 
pTableSet, nScript, &aBackConfigColor, &aTextConfigColor);
     else
-        pPattern->fillFont(aFont, eColorMode, pFmtDevice, &pOutput->maZoomY, 
pCondSet, nScript, &aBackConfigColor, &aTextConfigColor );
+        pPattern->fillFont(aFont, eColorMode, pFmtDevice, &pOutput->maZoomY, 
pCondSet, pTableSet, nScript, &aBackConfigColor, &aTextConfigColor );
 
     aFont.SetAlignment(ALIGN_BASELINE);
 
@@ -1546,6 +1547,7 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic)
     // variables for GetOutputArea
     const ScPatternAttr* pOldPattern = nullptr;
     const SfxItemSet* pOldCondSet = nullptr;
+    const SfxItemSet* pOldTableSet = nullptr;
     SvtScriptType nOldScript = SvtScriptType::NONE;
 
     // alternative pattern instances in case we need to modify the pattern
@@ -1587,7 +1589,7 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic)
                 if (bTaggedPDF)
                     
pPDF->WrapBeginStructureElement(vcl::pdf::StructElement::TableData, u"TD"_ustr);
                 LayoutStringsImpl(bPixelToLogic, pThisRowInfo, nX, nY, nArrY, 
oFirstNonEmptyCellX, oLastEmptyCellX, nLastContentCol,
-                                  aAltPatterns, pOldPattern, pOldCondSet, 
nOldScript, aVars,
+                                  aAltPatterns, pOldPattern, pOldCondSet, 
pOldTableSet, nOldScript, aVars,
                                   bProgress, nPosX, nPosY, bTaggedPDF, pPDF, 
nLayoutSign, aDX);
                 nPosX += mpRowInfo[0].basicCellInfo(nX).nWidth * nLayoutSign;
                 if (bTaggedPDF)
@@ -1614,6 +1616,7 @@ void ScOutputData::LayoutStringsImpl(bool const 
bPixelToLogic, RowInfo* const pT
             std::vector<std::unique_ptr<ScPatternAttr> >& aAltPatterns,
             const ScPatternAttr*& pOldPattern,
             const SfxItemSet*& pOldCondSet,
+            const SfxItemSet*& pOldTableSet,
             SvtScriptType& nOldScript,
             ScDrawStringsVars& aVars,
             bool& bProgress, tools::Long const nPosX, tools::Long const nPosY,
@@ -1622,6 +1625,7 @@ void ScOutputData::LayoutStringsImpl(bool const 
bPixelToLogic, RowInfo* const pT
 {
     const ScPatternAttr* pPattern = nullptr;
     const SfxItemSet* pCondSet = nullptr;
+    const SfxItemSet* pTableSet = nullptr;
     bool bCellIsValue = false;
     tools::Long nNeededWidth = 0;
     OutputAreaParam aAreaParam;
@@ -1745,6 +1749,7 @@ void ScOutputData::LayoutStringsImpl(bool const 
bPixelToLogic, RowInfo* const pT
             ScCellInfo& rCellInfo = pThisRowInfo->cellInfo(nCellX);
             pPattern = rCellInfo.pPatternAttr;
             pCondSet = rCellInfo.pConditionSet;
+            pTableSet = rCellInfo.pTableFormatSet;
 
             if ( !pPattern )
             {
@@ -1752,12 +1757,14 @@ void ScOutputData::LayoutStringsImpl(bool const 
bPixelToLogic, RowInfo* const pT
                 // test for null is quicker than using column flags
                 pPattern = mpDoc->GetPattern( nCellX, nCellY, mnTab );
                 pCondSet = mpDoc->GetCondResult( nCellX, nCellY, mnTab );
+                pTableSet = mpDoc->GetTableFormatSet( nCellX, nCellY, mnTab );
             }
         }
         else        // get from document
         {
             pPattern = mpDoc->GetPattern( nCellX, nCellY, mnTab );
             pCondSet = mpDoc->GetCondResult( nCellX, nCellY, mnTab );
+            pTableSet = mpDoc->GetTableFormatSet( nCellX, nCellY, mnTab );
         }
         if ( mpDoc->GetPreviewFont() || mpDoc->GetPreviewCellStyle() )
         {
@@ -1798,17 +1805,18 @@ void ScOutputData::LayoutStringsImpl(bool const 
bPixelToLogic, RowInfo* const pT
             nScript = ScGlobal::GetDefaultScriptType();
 
         if ( !ScPatternAttr::areSame(pPattern, pOldPattern) || pCondSet != 
pOldCondSet ||
-             nScript != nOldScript || mbSyntaxMode )
+             pTableSet != pOldTableSet || nScript != nOldScript || 
mbSyntaxMode )
         {
-            if ( StringDiffer(pOldPattern,pPattern) ||
-                 pCondSet != pOldCondSet || nScript != nOldScript || 
mbSyntaxMode )
+            if ( StringDiffer(pOldPattern,pPattern) || pCondSet != pOldCondSet 
||
+                 pTableSet != pOldTableSet || nScript != nOldScript || 
mbSyntaxMode )
             {
-                aVars.SetPattern(pPattern, pCondSet, aCell, nScript);
+                aVars.SetPattern(pPattern, pCondSet, pTableSet, aCell, 
nScript);
             }
             else
                 aVars.SetPatternSimple( pPattern, pCondSet );
             pOldPattern = pPattern;
             pOldCondSet = pCondSet;
+            pOldTableSet = pTableSet;
             nOldScript = nScript;
         }
 
@@ -2496,7 +2504,7 @@ void ScOutputData::ShrinkEditEngine( EditEngine& rEngine, 
const tools::Rectangle
     }
 }
 
-ScOutputData::DrawEditParam::DrawEditParam(const ScPatternAttr* pPattern, 
const SfxItemSet* pCondSet, bool bCellIsValue) :
+ScOutputData::DrawEditParam::DrawEditParam(const ScPatternAttr* pPattern, 
const SfxItemSet* pCondSet, const SfxItemSet* pTableSet, bool bCellIsValue) :
     meHorJustAttr( lcl_GetValue<SvxHorJustifyItem, 
SvxCellHorJustify>(*pPattern, ATTR_HOR_JUSTIFY, pCondSet) ),
     meHorJustContext( meHorJustAttr ),
     meHorJustResult( meHorJustAttr ),
@@ -2515,9 +2523,11 @@ ScOutputData::DrawEditParam::DrawEditParam(const 
ScPatternAttr* pPattern, const
     mpEngine(nullptr),
     mpPattern(pPattern),
     mpCondSet(pCondSet),
+    mpTableSet(pTableSet),
     mpPreviewFontSet(nullptr),
     mpOldPattern(nullptr),
     mpOldCondSet(nullptr),
+    mpOldTableSet(nullptr),
     mpOldPreviewFontSet(nullptr),
     mpThisRowInfo(nullptr)
 {}
@@ -2581,7 +2591,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool 
bUseStyleColor)
     // syntax highlighting mode is ignored here
     // StringDiffer doesn't look at hyphenate, language items
 
-    if (ScPatternAttr::areSame(mpPattern, mpOldPattern) && mpCondSet == 
mpOldCondSet && mpPreviewFontSet == mpOldPreviewFontSet )
+    if (ScPatternAttr::areSame(mpPattern, mpOldPattern) && mpCondSet == 
mpOldCondSet && mpTableSet == mpOldTableSet && mpPreviewFontSet == 
mpOldPreviewFontSet )
         return;
 
     Color nConfBackColor = GetConfBackgroundColor();
@@ -2589,7 +2599,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool 
bUseStyleColor)
             
Application::GetSettings().GetStyleSettings().GetHighContrastMode();
 
     auto pSet = std::make_unique<SfxItemSet>( mpEngine->GetEmptyItemSet() );
-    mpPattern->FillEditItemSet( pSet.get(), mpCondSet );
+    mpPattern->FillEditItemSet( pSet.get(), mpCondSet, mpTableSet );
     if ( mpPreviewFontSet )
     {
         if ( const SvxFontItem* pItem = mpPreviewFontSet->GetItemIfSet( 
ATTR_FONT ) )
@@ -2612,6 +2622,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool 
bUseStyleColor)
     mpEngine->SetDefaults( std::move(pSet) );
     mpOldPattern = mpPattern;
     mpOldCondSet = mpCondSet;
+    mpOldTableSet = mpTableSet;
     mpOldPreviewFontSet = mpPreviewFontSet;
 
     EEControlBits nControl = mpEngine->GetControlWord();
@@ -4483,6 +4494,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
     bool bHyphenatorSet = false;
     const ScPatternAttr* pOldPattern = nullptr;
     const SfxItemSet*    pOldCondSet = nullptr;
+    const SfxItemSet*    pOldTableSet = nullptr;
     const SfxItemSet*    pOldPreviewFontSet = nullptr;
     ScRefCellValue aCell;
 
@@ -4570,6 +4582,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
 
                     const ScPatternAttr* pPattern = nullptr;
                     const SfxItemSet* pCondSet = nullptr;
+                    const SfxItemSet* pTableSet = nullptr;
                     if (bDoCell)
                     {
                         if ( nCellY == nY && nCellX >= mnX1 && nCellX <= mnX2 
&&
@@ -4578,12 +4591,14 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
                             ScCellInfo& rCellInfo = 
pThisRowInfo->cellInfo(nCellX);
                             pPattern = rCellInfo.pPatternAttr;
                             pCondSet = rCellInfo.pConditionSet;
+                            pTableSet = rCellInfo.pTableFormatSet;
                             aCell = rCellInfo.maCell;
                         }
                         else        // get from document
                         {
                             pPattern = mpDoc->GetPattern( nCellX, nCellY, 
mnTab );
                             pCondSet = mpDoc->GetCondResult( nCellX, nCellY, 
mnTab );
+                            pTableSet = mpDoc->GetTableFormatSet( nCellX, 
nCellY, mnTab );
                             GetVisibleCell( nCellX, nCellY, mnTab, aCell );
                         }
                         if (aCell.isEmpty())
@@ -4606,7 +4621,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
                         // fdo#32530: Check if the first character is RTL.
                         OUString aStr = mpDoc->GetString(nCellX, nCellY, 
mnTab);
 
-                        DrawEditParam aParam(pPattern, pCondSet, 
lcl_SafeIsValue(aCell));
+                        DrawEditParam aParam(pPattern, pCondSet, pTableSet, 
lcl_SafeIsValue(aCell));
                         const bool bNumberFormatIsText = 
lcl_isNumberFormatText( mpDoc, nCellX, nCellY, mnTab );
                         aParam.meHorJustContext = getAlignmentFromContext( 
aParam.meHorJustAttr,
                                 aParam.mbCellIsValue, aStr, *pPattern, 
pCondSet, mpDoc, mnTab, bNumberFormatIsText);
@@ -4626,6 +4641,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
                         aParam.mpPreviewFontSet = pPreviewFontSet;
                         aParam.mpOldPattern = pOldPattern;
                         aParam.mpOldCondSet = pOldCondSet;
+                        aParam.mpOldTableSet = pOldTableSet;
                         aParam.mpOldPreviewFontSet = pOldPreviewFontSet;
                         aParam.mpThisRowInfo = pThisRowInfo;
                         if (mpSpellCheckCxt)
@@ -4655,6 +4671,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
                         // Retrieve parameters for next iteration.
                         pOldPattern = aParam.mpOldPattern;
                         pOldCondSet = aParam.mpOldCondSet;
+                        pOldTableSet = aParam.mpOldTableSet;
                         pOldPreviewFontSet = aParam.mpOldPreviewFontSet;
                         bHyphenatorSet = aParam.mbHyphenatorSet;
                     }

Reply via email to