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                 |    4 
 sc/source/ui/view/cellsh1.cxx               |    4 
 sc/source/ui/view/output2.cxx               |   46 ++++--
 16 files changed, 315 insertions(+), 103 deletions(-)

New commits:
commit 2c317e5fcad18877310a0da2db710b076ef0be7a
Author:     Balazs Varga <[email protected]>
AuthorDate: Wed Oct 8 08:16:38 2025 +0200
Commit:     Balazs Varga <[email protected]>
CommitDate: Fri Oct 31 16:25:57 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.
    
    Change-Id: I7c8d78bbff8be51b136b746ac71d490bf1077601
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192470
    Reviewed-by: Balazs Varga <[email protected]>
    Tested-by: Balazs Varga <[email protected]>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 1862113865ba..1b455aad991e 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1890,6 +1890,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 de66e7a370e2..cc249c6bcafe 100644
--- a/sc/inc/fillinfo.hxx
+++ b/sc/inc/fillinfo.hxx
@@ -116,6 +116,7 @@ struct ScCellInfo
     ScCellInfo()
         : pPatternAttr(nullptr)
         , pConditionSet(nullptr)
+        , pTableFormatSet(nullptr)
         , pDataBar(nullptr)
         , pIconSet(nullptr)
         , maBackground()
@@ -151,6 +152,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 e818df60a197..d6cc477ad007 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 c3bf713ad2f4..3a59e5375ca1 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 aee44751d406..d145ef54307c 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 = -(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 7b49d93516f9..ec56062f2459 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 ceff826a43ca..57ae4d4cbcaf 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -549,23 +549,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
 
@@ -592,18 +625,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 );
@@ -658,9 +685,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();
@@ -731,20 +763,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();
@@ -761,18 +786,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
@@ -932,15 +951,39 @@ ScDxfFont ScPatternAttr::GetDxfFont(const SfxItemSet& 
rItemSet, SvtScriptType nS
 }
 
 template <class T>
-static void lcl_populate( std::optional<T>& rxItem, TypedWhichId<T> nWhich, 
const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet )
+static void lcl_populate( std::optional<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.emplace(*pItem);
 }
 
-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
 
@@ -968,35 +1011,23 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& r
 
     if ( pCondSet )
     {
-        lcl_populate(oColorItem, ATTR_FONT_COLOR, rSrcSet, pCondSet);
-        lcl_populate(oFontItem, ATTR_FONT, rSrcSet, pCondSet);
-        lcl_populate(oCjkFontItem, ATTR_CJK_FONT, rSrcSet, pCondSet);
-        lcl_populate(oCtlFontItem, ATTR_CTL_FONT, rSrcSet, pCondSet);
-
-        const SvxFontHeightItem* pFontHeightItem = pCondSet->GetItemIfSet( 
ATTR_FONT_HEIGHT );
-        if (!pFontHeightItem)
-            pFontHeightItem = &rSrcSet.Get( ATTR_FONT_HEIGHT );
+        lcl_populate(oColorItem, ATTR_FONT_COLOR, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(oFontItem, ATTR_FONT, rSrcSet, pCondSet, pTableSet);
+        lcl_populate(oCjkFontItem, ATTR_CJK_FONT, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(oCtlFontItem, 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 );
@@ -1074,16 +1105,25 @@ void ScPatternAttr::FillToEditItemSet( SfxItemSet& 
rEditSet, const SfxItemSet& r
     }
     else        // Everything directly from Pattern
     {
-        oColorItem.emplace(rSrcSet.Get(ATTR_FONT_COLOR));
-        oFontItem.emplace(rSrcSet.Get(ATTR_FONT));
-        oCjkFontItem.emplace(rSrcSet.Get(ATTR_CJK_FONT));
-        oCtlFontItem.emplace(rSrcSet.Get(ATTR_CTL_FONT));
-        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(oColorItem, ATTR_FONT_COLOR, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(oFontItem, ATTR_FONT, rSrcSet, pCondSet, pTableSet);
+        lcl_populate(oCjkFontItem, ATTR_CJK_FONT, rSrcSet, pCondSet, 
pTableSet);
+        lcl_populate(oCtlFontItem, 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();
@@ -1166,10 +1206,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 38aca4a1c7a5..54feefba60a5 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 887cff303152..4ed3d50d5a33 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 8afef4cd41f0..6905b07c762a 100644
--- a/sc/source/filter/inc/stylesbuffer.hxx
+++ b/sc/source/filter/inc/stylesbuffer.hxx
@@ -217,6 +217,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 420547071a75..8269ae7734ad 100644
--- a/sc/source/filter/oox/defaulttablestyles.cxx
+++ b/sc/source/filter/oox/defaulttablestyles.cxx
@@ -102,7 +102,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()
 {
@@ -118,6 +130,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 8a6f5babfecb..4f18faca61e0 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -658,6 +658,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 22527d3addc7..e5e6c80de5d5 100644
--- a/sc/source/ui/inc/output.hxx
+++ b/sc/source/ui/inc/output.hxx
@@ -148,14 +148,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);
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index f75deaa4f91c..57a016110ad7 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2793,7 +2793,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) );
@@ -2808,7 +2808,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 3427fc2296c4..3d2ce2b38362 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->aZoomY;
     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->aZoomY, 
pCondSet, nScript, &aBackConfigColor, &aTextConfigColor );
+        pPattern->fillFont(aFont, eColorMode, pFmtDevice, &pOutput->aZoomY, 
pCondSet, pTableSet, nScript, &aBackConfigColor, &aTextConfigColor );
 
     aFont.SetAlignment(ALIGN_BASELINE);
 
@@ -1543,8 +1544,10 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic)
     tools::Long nNeededWidth = 0;
     const ScPatternAttr* pPattern = nullptr;
     const SfxItemSet* pCondSet = nullptr;
+    const SfxItemSet* pTableSet = nullptr;
     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
@@ -1683,6 +1686,7 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic)
                         ScCellInfo& rCellInfo = pThisRowInfo->cellInfo(nCellX);
                         pPattern = rCellInfo.pPatternAttr;
                         pCondSet = rCellInfo.pConditionSet;
+                        pTableSet = rCellInfo.pTableFormatSet;
 
                         if ( !pPattern )
                         {
@@ -1690,12 +1694,14 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic)
                             // test for null is quicker than using column flags
                             pPattern = mpDoc->GetPattern( nCellX, nCellY, nTab 
);
                             pCondSet = mpDoc->GetCondResult( nCellX, nCellY, 
nTab );
+                            pTableSet = mpDoc->GetTableFormatSet( nCellX, 
nCellY, nTab );
                         }
                     }
                     else        // get from document
                     {
                         pPattern = mpDoc->GetPattern( nCellX, nCellY, nTab );
                         pCondSet = mpDoc->GetCondResult( nCellX, nCellY, nTab 
);
+                        pTableSet = mpDoc->GetTableFormatSet( nCellX, nCellY, 
nTab );
                     }
                     if ( mpDoc->GetPreviewFont() || 
mpDoc->GetPreviewCellStyle() )
                     {
@@ -1736,17 +1742,18 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic)
                         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;
                     }
 
@@ -2482,7 +2489,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 ),
@@ -2501,9 +2508,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)
 {}
@@ -2567,7 +2576,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();
@@ -2575,7 +2584,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool 
bUseStyleColor)
             
Application::GetSettings().GetStyleSettings().GetHighContrastMode();
 
     SfxItemSet aSet( mpEngine->GetEmptyItemSet() );
-    mpPattern->FillEditItemSet( &aSet, mpCondSet );
+    mpPattern->FillEditItemSet( &aSet, mpCondSet, mpTableSet );
     if ( mpPreviewFontSet )
     {
         if ( const SvxFontItem* pItem = mpPreviewFontSet->GetItemIfSet( 
ATTR_FONT ) )
@@ -2598,6 +2607,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool 
bUseStyleColor)
     mpEngine->SetDefaults( std::move(aSet) );
     mpOldPattern = mpPattern;
     mpOldCondSet = mpCondSet;
+    mpOldTableSet = mpTableSet;
     mpOldPreviewFontSet = mpPreviewFontSet;
 
     EEControlBits nControl = mpEngine->GetControlWord();
@@ -4469,6 +4479,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;
 
@@ -4556,6 +4567,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
 
                     const ScPatternAttr* pPattern = nullptr;
                     const SfxItemSet* pCondSet = nullptr;
+                    const SfxItemSet* pTableSet = nullptr;
                     if (bDoCell)
                     {
                         if ( nCellY == nY && nCellX >= nX1 && nCellX <= nX2 &&
@@ -4564,12 +4576,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, nTab 
);
                             pCondSet = mpDoc->GetCondResult( nCellX, nCellY, 
nTab );
+                            pTableSet = mpDoc->GetTableFormatSet( nCellX, 
nCellY, nTab );
                             GetVisibleCell( nCellX, nCellY, nTab, aCell );
                         }
                         if (aCell.isEmpty())
@@ -4592,7 +4606,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
                         // fdo#32530: Check if the first character is RTL.
                         OUString aStr = mpDoc->GetString(nCellX, nCellY, nTab);
 
-                        DrawEditParam aParam(pPattern, pCondSet, 
lcl_SafeIsValue(aCell));
+                        DrawEditParam aParam(pPattern, pCondSet, pTableSet, 
lcl_SafeIsValue(aCell));
                         const bool bNumberFormatIsText = 
lcl_isNumberFormatText( mpDoc, nCellX, nCellY, nTab );
                         aParam.meHorJustContext = getAlignmentFromContext( 
aParam.meHorJustAttr,
                                 aParam.mbCellIsValue, aStr, *pPattern, 
pCondSet, mpDoc, nTab, bNumberFormatIsText);
@@ -4612,6 +4626,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)
@@ -4641,6 +4656,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