sc/inc/document.hxx                         |    1 
 sc/inc/fillinfo.hxx                         |    6 
 sc/inc/patattr.hxx                          |   16 
 sc/inc/tablestyle.hxx                       |  121 -----
 sc/source/core/data/column2.cxx             |    3 
 sc/source/core/data/documen4.cxx            |   27 +
 sc/source/core/data/fillinfo.cxx            |   26 -
 sc/source/core/data/patattr.cxx             |  194 +++++----
 sc/source/core/data/tablestyle.cxx          |  565 ++++++++++++++++++++++++++++
 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, 823 insertions(+), 223 deletions(-)

New commits:
commit 48ce7b6da06bec57ee5773517c4c0a78bdfd9867
Author:     Balazs Varga <[email protected]>
AuthorDate: Thu Oct 9 10:39:52 2025 +0200
Commit:     Balazs Varga <[email protected]>
CommitDate: Wed Jan 7 17:11:59 2026 +0100

    Improve border style handling for table styles
    
    Recreate BoxItems for individual cells in the Table
    style so FillInfo can handle that if we have Table border,
    Row/Column border Header/Total row etc. style for one cells.
    Handle vertical and horizontal border definitions.
    
    Change-Id: I9388f1d95b1b3bd3a92c7640186e381fa3be63f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192471
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193675
    Reviewed-by: Andras Timar <[email protected]>
    Tested-by: Andras Timar <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196743

diff --git a/sc/inc/fillinfo.hxx b/sc/inc/fillinfo.hxx
index cc249c6bcafe..b34bc52281ec 100644
--- a/sc/inc/fillinfo.hxx
+++ b/sc/inc/fillinfo.hxx
@@ -120,7 +120,7 @@ struct ScCellInfo
         , pDataBar(nullptr)
         , pIconSet(nullptr)
         , maBackground()
-        , pLinesAttr(nullptr)
+        , maLinesAttr()
         , mpTLBRLine(nullptr)
         , mpBLTRLine(nullptr)
         , pShadowAttr(nullptr)
@@ -158,8 +158,8 @@ struct ScCellInfo
     const ScIconSetInfo*        pIconSet;
 
     SfxPoolItemHolder           maBackground;
+    SfxPoolItemHolder           maLinesAttr;
 
-    const SvxBoxItem*           pLinesAttr;         /// original item from 
document.
     const SvxLineItem*          mpTLBRLine;         /// original item from 
document.
     const SvxLineItem*          mpBLTRLine;         /// original item from 
document.
 
diff --git a/sc/inc/tablestyle.hxx b/sc/inc/tablestyle.hxx
index e14bbb486aaf..04b9c36d56e4 100644
--- a/sc/inc/tablestyle.hxx
+++ b/sc/inc/tablestyle.hxx
@@ -11,6 +11,8 @@
 
 #include <memory>
 
+#include <editeng/boxitem.hxx>
+#include <editeng/brushitem.hxx>
 #include "document.hxx"
 #include "scdllapi.h"
 #include "dbdata.hxx"
@@ -40,6 +42,11 @@ template <class T> const T* 
GetItemFromPattern(ScPatternAttr* pPattern, TypedWhi
 class SC_DLLPUBLIC ScTableStyle
 {
 private:
+    ScTableStyle(ScTableStyle const&) = delete;
+    ScTableStyle(ScTableStyle&&) = delete;
+    void operator=(ScTableStyle const&) = delete;
+    void operator=(ScTableStyle&&) = delete;
+
     std::unique_ptr<ScPatternAttr> mpTablePattern;
     std::unique_ptr<ScPatternAttr> mpFirstColumnStripePattern;
     std::unique_ptr<ScPatternAttr> mpSecondColumnStripePattern;
@@ -64,117 +71,12 @@ private:
 public:
     ScTableStyle(const OUString& rName, const std::optional<OUString>& 
rUIName);
 
-    template <class T>
-    const T* GetItem(const ScDBData& rDBData, SCCOL nCol, SCROW nRow, SCROW 
nRowIndex,
-                     TypedWhichId<T> nWhich) 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())
-        {
-            const T* pPoolItem = 
GetItemFromPattern(mpLastHeaderCellPattern.get(), nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (bHasHeader && mpFirstHeaderCellPattern && nRow == 
aRange.aStart.Row()
-            && nCol == aRange.aStart.Col())
-        {
-            const T* pPoolItem = 
GetItemFromPattern(mpFirstHeaderCellPattern.get(), nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
-        {
-            const T* pPoolItem = GetItemFromPattern(mpTotalRowPattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
-        {
-            const T* pPoolItem = GetItemFromPattern(mpHeaderRowPattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
-        {
-            const T* pPoolItem = 
GetItemFromPattern(mpFirstColumnPattern.get(), nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
-        {
-            const T* pPoolItem = GetItemFromPattern(mpLastColumnPattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (!bHasTotal || aRange.aEnd.Row() != nRow)
-        {
-            if (pParam->mbRowStripes && nRowIndex >= 0)
-            {
-                sal_Int32 nTotalRowStripPattern = mnFirstRowStripeSize + 
mnSecondRowStripeSize;
-                bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
-                if (mpSecondRowStripePattern && !bFirstRowStripe)
-                {
-                    const T* pPoolItem = 
GetItemFromPattern(mpSecondRowStripePattern.get(), nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-
-                if (mpFirstRowStripePattern && bFirstRowStripe)
-                {
-                    const T* pPoolItem = 
GetItemFromPattern(mpFirstRowStripePattern.get(), nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-            }
-
-            if (pParam->mbColumnStripes)
-            {
-                SCCOL nRelativeCol = nCol - aRange.aStart.Col();
-                sal_Int32 nTotalColStripePattern = mnFirstColStripeSize + 
mnSecondColStripeSize;
-                bool bFirstColStripe
-                    = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
-                if (mpSecondColumnStripePattern && !bFirstColStripe)
-                {
-                    const T* pPoolItem
-                        = 
GetItemFromPattern(mpSecondColumnStripePattern.get(), nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-
-                if (mpFirstColumnStripePattern && bFirstColStripe)
-                {
-                    const T* pPoolItem
-                        = GetItemFromPattern(mpFirstColumnStripePattern.get(), 
nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-            }
-        }
-
-        if (mpTablePattern)
-        {
-            const T* pPoolItem = GetItemFromPattern(mpTablePattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        return nullptr;
-    }
-
     const SfxItemSet* GetTableCellItemSet(const ScDBData& rDBData, SCCOL nCol, 
SCROW nRow,
                                           SCROW nRowIndex) const;
+    const SvxBrushItem* GetFillItem(const ScDBData& rDBData, SCCOL nCol, SCROW 
nRow,
+                                    SCROW nRowIndex) const;
+    std::unique_ptr<SvxBoxItem> GetBoxItem(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/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 6a83e242db88..e175216a26c3 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -445,18 +445,17 @@ void ScDocument::FillInfo(
 
                 ScCellInfo* pInfo = &pThisRowInfo->cellInfo(nCol);
 
-                const SvxBrushItem* pBackground = 
pTableStyle->GetItem(*pDBData, nCol, nRow, nRowIndex, ATTR_BACKGROUND);
-
+                const SvxBrushItem* pBackground = 
pTableStyle->GetFillItem(*pDBData, nCol, nRow, nRowIndex);
                 if (pBackground)
                 {
                     pInfo->maBackground = SfxPoolItemHolder(*pPool, 
pBackground);
                     pThisRowInfo->bEmptyBack = false;
                 }
 
-                const SvxBoxItem* pLinesAttr = pTableStyle->GetItem(*pDBData, 
nCol, nRow, nRowIndex, ATTR_BORDER);
+                std::unique_ptr<SvxBoxItem> pLinesAttr = 
pTableStyle->GetBoxItem(*pDBData, nCol, nRow, nRowIndex);
                 if (pLinesAttr)
                 {
-                    pInfo->pLinesAttr = pLinesAttr;
+                    pInfo->maLinesAttr = SfxPoolItemHolder(*pPool, 
pLinesAttr.get());
                 }
 
                 const SfxItemSet* pPoolItem = 
pTableStyle->GetTableCellItemSet(*pDBData, nCol, nRow, nRowIndex);
@@ -623,16 +622,16 @@ void ScDocument::FillInfo(
                                 pInfo->bPivotExpandButton = bPivotExpandButton;
                                 pInfo->bPivotPopupButtonMulti = 
bPivotPopupButtonMulti;
                                 pInfo->bFilterActive = bFilterActive;
-                                if (pInfo->pLinesAttr)
+                                if (pInfo->maLinesAttr)
                                 {
                                     if (pExplicitBackground)
                                     {
-                                        pInfo->pLinesAttr = pExplicitLinesAttr;
+                                        pInfo->maLinesAttr = 
SfxPoolItemHolder(*pPool, pExplicitLinesAttr);
                                     }
                                 }
                                 else
                                 {
-                                    pInfo->pLinesAttr = pLinesAttr;
+                                    pInfo->maLinesAttr = 
SfxPoolItemHolder(*pPool, pLinesAttr);
                                 }
                                 pInfo->mpTLBRLine   = pTLBRLine;
                                 pInfo->mpBLTRLine   = pBLTRLine;
@@ -756,7 +755,10 @@ void ScDocument::FillInfo(
 
                             // Border
                     if ( const SvxBoxItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BORDER ) )
-                        pInfo->pLinesAttr = pItem;
+                    {
+                        pInfo->maLinesAttr = SfxPoolItemHolder(*pPool, pItem);
+                        pRowInfo[nArrRow].bEmptyBack = false;
+                    }
 
                     if ( const SvxLineItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BORDER_TLBR ) )
                         pInfo->mpTLBRLine = pItem;
@@ -1013,7 +1015,7 @@ void ScDocument::FillInfo(
         for( SCCOL nCol = nCol1 - 1; nCol <= nCol2 + 1; ++nCol ) // 1 more 
left and right
         {
             const ScCellInfo& rInfo = rThisRowInfo.cellInfo( nCol );
-            const SvxBoxItem* pBox = rInfo.pLinesAttr;
+            const SvxBoxItem* pBox = static_cast<const 
SvxBoxItem*>(rInfo.maLinesAttr.getItem());
             const SvxLineItem* pTLBR = rInfo.mpTLBRLine;
             const SvxLineItem* pBLTR = rInfo.mpBLTRLine;
 
diff --git a/sc/source/core/data/tablestyle.cxx 
b/sc/source/core/data/tablestyle.cxx
index 5ee0229c9704..d7d3ff02a330 100644
--- a/sc/source/core/data/tablestyle.cxx
+++ b/sc/source/core/data/tablestyle.cxx
@@ -103,6 +103,488 @@ const SfxItemSet* ScTableStyle::GetTableCellItemSet(const 
ScDBData& rDBData, SCC
     return nullptr;
 }
 
+const SvxBrushItem* ScTableStyle::GetFillItem(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())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpLastHeaderCellPattern.get(), 
ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (bHasHeader && mpFirstHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aStart.Col())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpFirstHeaderCellPattern.get(), 
ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpHeaderRowPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpFirstColumnPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpLastColumnPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (!bHasTotal || aRange.aEnd.Row() != nRow)
+    {
+        if (pParam->mbRowStripes && nRowIndex >= 0)
+        {
+            sal_Int32 nTotalRowStripPattern = mnFirstRowStripeSize + 
mnSecondRowStripeSize;
+            bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
+            if (mpSecondRowStripePattern && !bFirstRowStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpSecondRowStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+
+            if (mpFirstRowStripePattern && bFirstRowStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpFirstRowStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+        }
+
+        if (pParam->mbColumnStripes)
+        {
+            SCCOL nRelativeCol = nCol - aRange.aStart.Col();
+            sal_Int32 nTotalColStripePattern = mnFirstColStripeSize + 
mnSecondColStripeSize;
+            bool bFirstColStripe = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
+            if (mpSecondColumnStripePattern && !bFirstColStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpSecondColumnStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+
+            if (mpFirstColumnStripePattern && bFirstColStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpFirstColumnStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+        }
+    }
+
+    if (mpTablePattern)
+    {
+        const SvxBrushItem* pPoolItem = 
GetItemFromPattern(mpTablePattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    return nullptr;
+}
+
+std::unique_ptr<SvxBoxItem> ScTableStyle::GetBoxItem(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())
+    {
+        const SvxBoxItem* pPoolItem
+            = GetItemFromPattern(mpLastHeaderCellPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            if (const SvxBoxItem* pBoxItem
+                = GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BORDER))
+            {
+                const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                const ::editeng::SvxBorderLine* pRLine = 
pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                if (pTLine || pRLine)
+                {
+                    std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                      : 
nullptr);
+                    if (!pNewBoxItem)
+                        pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                    if (pTLine)
+                        pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                    if (pRLine)
+                        pNewBoxItem->SetLine(pRLine, SvxBoxItemLine::RIGHT);
+
+                    return pNewBoxItem;
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (bHasHeader && mpFirstHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aStart.Col())
+    {
+        const SvxBoxItem* pPoolItem
+            = GetItemFromPattern(mpFirstHeaderCellPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            if (const SvxBoxItem* pBoxItem
+                = GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BORDER))
+            {
+                const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                const ::editeng::SvxBorderLine* pLLine = 
pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                if (pTLine || pLLine)
+                {
+                    std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                      : 
nullptr);
+                    if (!pNewBoxItem)
+                        pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                    if (pTLine)
+                        pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                    if (pLLine)
+                        pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+
+                    return pNewBoxItem;
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpHeaderRowPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            const SvxBoxItem* pBoxItem = 
GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER);
+            const SvxBoxInfoItem* pBoxInfoItem
+                = GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER_INNER);
+            if (pBoxItem || pBoxInfoItem)
+            {
+                if (pBoxItem && nCol == aRange.aStart.Col())
+                {
+                    const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                    const ::editeng::SvxBorderLine* pLLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                    if (pTLine || pLLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pTLine)
+                            pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                        if (pLLine)
+                            pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else if (pBoxItem && nCol == aRange.aEnd.Col())
+                {
+                    const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                    const ::editeng::SvxBorderLine* pRLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                    if (pTLine || pRLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pTLine)
+                            pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                        if (pRLine)
+                            pNewBoxItem->SetLine(pRLine, 
SvxBoxItemLine::RIGHT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else
+                {
+                    const ::editeng::SvxBorderLine* pTLine = nullptr;
+                    if (pBoxItem)
+                        pTLine = pBoxItem->GetLine(SvxBoxItemLine::TOP);
+
+                    const ::editeng::SvxBorderLine* pVLine = nullptr;
+                    if (pBoxInfoItem)
+                        pVLine = pBoxInfoItem->GetVert();
+
+                    if (pTLine || pVLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pTLine)
+                            pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                        if (pVLine)
+                        {
+                            pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::LEFT);
+                            pNewBoxItem->SetLine(pVLine, 
SvxBoxItemLine::RIGHT);
+                        }
+
+                        return pNewBoxItem;
+                    }
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            const SvxBoxItem* pBoxItem = 
GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER);
+            const SvxBoxInfoItem* pBoxInfoItem
+                = GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER_INNER);
+            if (pBoxItem || pBoxInfoItem)
+            {
+                if (pBoxItem && nCol == aRange.aStart.Col())
+                {
+                    const ::editeng::SvxBorderLine* pBLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                    const ::editeng::SvxBorderLine* pLLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                    if (pBLine || pLLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pBLine)
+                            pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
+                        if (pLLine)
+                            pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else if (pBoxItem && nCol == aRange.aEnd.Col())
+                {
+                    const ::editeng::SvxBorderLine* pBLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                    const ::editeng::SvxBorderLine* pRLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                    if (pBLine || pRLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pBLine)
+                            pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
+                        if (pRLine)
+                            pNewBoxItem->SetLine(pRLine, 
SvxBoxItemLine::RIGHT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else
+                {
+                    const ::editeng::SvxBorderLine* pBLine = nullptr;
+                    if (pBoxItem)
+                        pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+
+                    const ::editeng::SvxBorderLine* pVLine = nullptr;
+                    if (pBoxInfoItem)
+                        pVLine = pBoxInfoItem->GetVert();
+
+                    if (pBLine || pVLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pBLine)
+                            pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
+                        if (pVLine)
+                        {
+                            pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::LEFT);
+                            pNewBoxItem->SetLine(pVLine, 
SvxBoxItemLine::RIGHT);
+                        }
+
+                        return pNewBoxItem;
+                    }
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpFirstColumnPattern.get(), ATTR_BORDER);
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpLastColumnPattern.get(), ATTR_BORDER);
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (!bHasTotal || aRange.aEnd.Row() != nRow)
+    {
+        if (pParam->mbRowStripes && nRowIndex >= 0)
+        {
+            sal_Int32 nTotalRowStripPattern = mnFirstRowStripeSize + 
mnSecondRowStripeSize;
+            bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
+            if (mpSecondRowStripePattern && !bFirstRowStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpSecondRowStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+
+            if (mpFirstRowStripePattern && bFirstRowStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpFirstRowStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+        }
+
+        if (pParam->mbColumnStripes)
+        {
+            SCCOL nRelativeCol = nCol - aRange.aStart.Col();
+            sal_Int32 nTotalColStripePattern = mnFirstColStripeSize + 
mnSecondColStripeSize;
+            bool bFirstColStripe = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
+            if (mpSecondColumnStripePattern && !bFirstColStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpSecondColumnStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+
+            if (mpFirstColumnStripePattern && bFirstColStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpFirstColumnStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+        }
+    }
+
+    if (mpTablePattern)
+    {
+        const SvxBoxItem* pBoxItem = GetItemFromPattern(mpTablePattern.get(), 
ATTR_BORDER);
+        const SvxBoxInfoItem* pBoxInfoItem
+            = GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER_INNER);
+
+        if (pBoxItem || pBoxInfoItem)
+        {
+            std::unique_ptr<SvxBoxItem> pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+            // Start/End col borders
+            if (pBoxItem && nCol == aRange.aStart.Col())
+            {
+                const ::editeng::SvxBorderLine* pLLine = 
pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                if (pLLine)
+                {
+                    pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+                }
+            }
+            else if (pBoxItem && nCol == aRange.aEnd.Col())
+            {
+                const ::editeng::SvxBorderLine* pRLine = 
pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                if (pRLine)
+                {
+                    pNewBoxItem->SetLine(pRLine, SvxBoxItemLine::RIGHT);
+                }
+            }
+            // Start/End row borders
+            if (pBoxItem && nRow == aRange.aStart.Row())
+            {
+                const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                if (pTLine)
+                {
+                    pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                }
+            }
+            else if (pBoxItem && nRow == aRange.aEnd.Row())
+            {
+                const ::editeng::SvxBorderLine* pBLine = 
pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                if (pBLine)
+                {
+                    pNewBoxItem->SetLine(pBLine, SvxBoxItemLine::BOTTOM);
+                }
+            }
+            // Inner borders
+            if (pBoxInfoItem)
+            {
+                const ::editeng::SvxBorderLine* pHLine = 
pBoxInfoItem->GetHori();
+                if (pHLine)
+                {
+                    pNewBoxItem->SetLine(pHLine, SvxBoxItemLine::TOP);
+                    pNewBoxItem->SetLine(pHLine, SvxBoxItemLine::BOTTOM);
+                }
+
+                const ::editeng::SvxBorderLine* pVLine = 
pBoxInfoItem->GetVert();
+                if (pVLine)
+                {
+                    pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::LEFT);
+                    pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::RIGHT);
+                }
+            }
+
+            return pNewBoxItem;
+        }
+    }
+
+    return nullptr;
+}
+
 void ScTableStyle::SetRowStripeSize(sal_Int32 nFirstRowStripeSize, sal_Int32 
nSecondRowStripeSize)
 {
     if (nFirstRowStripeSize >= 1)
commit 8bfc74f63dbff89b888a341d9f7402b4d265b9c5
Author:     Balazs Varga <[email protected]>
AuthorDate: Wed Oct 8 08:16:38 2025 +0200
Commit:     Balazs Varga <[email protected]>
CommitDate: Wed Jan 7 17:11:46 2026 +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]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196742

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 3be6cfd1202f..f80742a0dd1e 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1902,6 +1902,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 f08c29710267..3d47591a13b0 100644
--- a/sc/inc/patattr.hxx
+++ b/sc/inc/patattr.hxx
@@ -188,6 +188,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,
@@ -195,6 +196,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);
 
@@ -202,6 +204,7 @@ public:
                             const SfxItemSet& rItemSet,
                             ScAutoFontColorMode eAutoMode,
                             const SfxItemSet* pCondSet = nullptr,
+                            const SfxItemSet* pTableSet = nullptr,
                             const Color* pBackConfigColor = nullptr,
                             const Color* pTextConfigColor = nullptr);
 
@@ -211,19 +214,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. */
@@ -231,17 +236,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 4347c524efa6..036b9eb3db0d 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 a2d31ef7d3ed..b0664bcae0ed 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 b86a4ac67089..6a83e242db88 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 6f14db0c8c0c..9870c56db403 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::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
 
@@ -972,35 +1015,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 );
@@ -1078,16 +1109,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();
@@ -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 a327e1880df5..bee635eca515 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 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 a34af294b113..320ffa03ee89 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 8c805ea09a92..49bc067e0b77 100644
--- a/sc/source/ui/inc/output.hxx
+++ b/sc/source/ui/inc/output.hxx
@@ -149,14 +149,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);
@@ -321,6 +323,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 7874a18b8e05..5570e6da5281 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2913,7 +2913,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) );
@@ -2928,7 +2928,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 ce0a481a5c33..942672d2a27e 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);
 
@@ -1540,6 +1541,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
@@ -1563,7 +1565,7 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic)
             for (SCCOL nX=nLoopStartX; nX<=mnX2; nX++)
             {
                 LayoutStringsImpl(bPixelToLogic, pThisRowInfo, nX, nY, nArrY, 
oFirstNonEmptyCellX, oLastEmptyCellX, nLastContentCol,
-                                  aAltPatterns, pOldPattern, pOldCondSet, 
nOldScript, aVars,
+                                  aAltPatterns, pOldPattern, pOldCondSet, 
pOldTableSet, nOldScript, aVars,
                                   bProgress, nPosX, nPosY, bTaggedPDF, 
bReopenRowTag, pPDF, nLayoutSign, aDX);
                 nPosX += mpRowInfo[0].basicCellInfo(nX).nWidth * nLayoutSign;
             }
@@ -1586,6 +1588,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,
@@ -1594,6 +1597,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;
@@ -1717,6 +1721,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 )
             {
@@ -1724,12 +1729,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() )
         {
@@ -1770,17 +1777,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;
         }
 
@@ -2506,7 +2514,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 ),
@@ -2525,9 +2533,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)
 {}
@@ -2591,7 +2601,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();
@@ -2599,7 +2609,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 ) )
@@ -2622,6 +2632,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool 
bUseStyleColor)
     mpEngine->SetDefaults( std::move(aSet) );
     mpOldPattern = mpPattern;
     mpOldCondSet = mpCondSet;
+    mpOldTableSet = mpTableSet;
     mpOldPreviewFontSet = mpPreviewFontSet;
 
     EEControlBits nControl = mpEngine->GetControlWord();
@@ -4493,6 +4504,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;
 
@@ -4580,6 +4592,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 
&&
@@ -4588,12 +4601,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())
@@ -4616,7 +4631,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);
@@ -4636,6 +4651,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)
@@ -4665,6 +4681,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