sc/inc/dbdata.hxx                     |    6 ++++--
 sc/inc/document.hxx                   |    5 +++--
 sc/inc/tablestyle.hxx                 |    1 +
 sc/source/core/data/documen2.cxx      |   13 +++++++++----
 sc/source/core/data/tablestyle.cxx    |   22 +++++++++++++++++++---
 sc/source/core/tool/dbdata.cxx        |   12 +++++++++++-
 sc/source/filter/excel/xedbdata.cxx   |   12 +++++++++---
 sc/source/filter/excel/xestyle.cxx    |    9 ++++++---
 sc/source/filter/oox/stylesbuffer.cxx |    4 ++--
 9 files changed, 64 insertions(+), 20 deletions(-)

New commits:
commit 25eb3cdc34e8a1071e680f70817c0091332b0e17
Author:     Balazs Varga <[email protected]>
AuthorDate: Thu Nov 20 09:03:57 2025 +0100
Commit:     Balazs Varga <[email protected]>
CommitDate: Mon Nov 24 21:38:15 2025 +0100

    Table styles: fix missing border style if have no total row
    
    Also change some table style function to get back pointers
    instead of references to check if they are really exists.
    
    Change-Id: Icec52d11a416cc9831f83bdce979b9530bb0b8b9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194239
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>

diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index aba9d818f77c..d95ad30eb83a 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -193,8 +193,9 @@ public:
 
     SC_DLLPUBLIC ScDBData(const OUString& rName,
              SCTAB nTab,
-             SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
-             bool bByR = true, bool bHasH = true, bool bTotals = false, const 
OUString& rTableType = "worksheet");
+             SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bByR = 
true, bool bHasH = true, bool bTotals = false,
+                          const OUString& rTableType = u"worksheet"_ustr,
+                          const OUString& rTableStyleID = u""_ustr);
     ScDBData(const ScDBData& rData);
     ScDBData(const OUString& rName, const ScDBData& rData);
     SC_DLLPUBLIC virtual ~ScDBData() override;
@@ -324,6 +325,7 @@ public:
 
     SC_DLLPUBLIC void SetTableStyleInfo(const ScTableStyleParam& rParams);
     SC_DLLPUBLIC const ScTableStyleParam* GetTableStyleInfo() const;
+    void RemoveTableStyleInfo();
 
     static ScSubTotalFunc GetSubTotalFuncFromString(std::u16string_view 
sFunction);
     static OUString GetStringFromSubTotalFunc(ScSubTotalFunc eFunc);
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 7ed215ca8565..b2c2c1ab548b 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2778,8 +2778,9 @@ public:
     bool  SetLOKFreezeCol(SCCOL nFreezeCol, SCTAB nTab);
     bool  SetLOKFreezeRow(SCROW nFreezeRow, SCTAB nTab);
 
-    SC_DLLPUBLIC ScTableStyles& GetTableStyles();
-    SC_DLLPUBLIC const ScTableStyles& GetTableStyles() const;
+    SC_DLLPUBLIC ScTableStyles* GetTableStyles();
+    SC_DLLPUBLIC const ScTableStyles* GetTableStyles() const;
+    SC_DLLPUBLIC bool HasTableStyles() const;
 
 private:
 
diff --git a/sc/inc/tablestyle.hxx b/sc/inc/tablestyle.hxx
index 514f23d7ecce..57fbd8046b14 100644
--- a/sc/inc/tablestyle.hxx
+++ b/sc/inc/tablestyle.hxx
@@ -126,6 +126,7 @@ public:
     void AddTableStyle(std::unique_ptr<ScTableStyle> pTableStyle);
     void DeleteTableStyle(const OUString& rName);
     const ScTableStyle* GetTableStyle(const OUString& rName) const;
+    bool HasTableStyle() const { return maTableStyles.size() > 0; }
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 00f7448a11ca..6372d9412018 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1530,14 +1530,19 @@ sc::IconSetBitmapMap& ScDocument::GetIconSetBitmapMap()
     return *m_pIconSetBitmapMap;
 }
 
-ScTableStyles& ScDocument::GetTableStyles()
+ScTableStyles* ScDocument::GetTableStyles()
 {
-    return *mpTableStyles;
+    return mpTableStyles.get();
 }
 
-const ScTableStyles& ScDocument::GetTableStyles() const
+const ScTableStyles* ScDocument::GetTableStyles() const
 {
-    return *mpTableStyles;
+    return mpTableStyles.get();
+}
+
+bool ScDocument::HasTableStyles() const
+{
+    return mpTableStyles->HasTableStyle();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/tablestyle.cxx 
b/sc/source/core/data/tablestyle.cxx
index 29373b9e81ab..bf7c03664d09 100644
--- a/sc/source/core/data/tablestyle.cxx
+++ b/sc/source/core/data/tablestyle.cxx
@@ -521,12 +521,17 @@ std::unique_ptr<SvxBoxItem> 
ScTableStyle::GetBoxItem(const ScDBData& rDBData, SC
                     {
                         const ::editeng::SvxBorderLine* pLLine
                             = pBoxItem->GetLine(SvxBoxItemLine::LEFT);
-                        if (pLLine)
+                        const ::editeng::SvxBorderLine* pBLine = nullptr;
+                        if (aRange.aEnd.Row() == nRow)
+                            pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                        if (pLLine || pBLine)
                         {
                             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);
 
@@ -537,12 +542,17 @@ std::unique_ptr<SvxBoxItem> 
ScTableStyle::GetBoxItem(const ScDBData& rDBData, SC
                     {
                         const ::editeng::SvxBorderLine* pRLine
                             = pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
-                        if (pRLine)
+                        const ::editeng::SvxBorderLine* pBLine = nullptr;
+                        if (aRange.aEnd.Row() == nRow)
+                            pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                        if (pRLine || pBLine)
                         {
                             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);
 
@@ -551,16 +561,22 @@ std::unique_ptr<SvxBoxItem> 
ScTableStyle::GetBoxItem(const ScDBData& rDBData, SC
                     }
                     else
                     {
+                        const ::editeng::SvxBorderLine* pBLine = nullptr;
+                        if (pBoxItem && aRange.aEnd.Row() == nRow)
+                            pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+
                         const ::editeng::SvxBorderLine* pVLine = nullptr;
                         if (pBoxInfoItem)
                             pVLine = pBoxInfoItem->GetVert();
 
-                        if (pVLine)
+                        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);
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index 41dc18afdd24..10336fa9071a 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -285,7 +285,7 @@ bool ScDBData::less::operator() (const 
std::unique_ptr<ScDBData>& left, const st
 ScDBData::ScDBData( const OUString& rName,
                     SCTAB nTab,
                     SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
-                    bool bByR, bool bHasH, bool bTotals, const OUString& 
rTableType) :
+                    bool bByR, bool bHasH, bool bTotals, const OUString& 
rTableType, const OUString& rTableStyleID) :
     // Listeners are to be setup by the "parent" container.
     mpSortParam(new ScSortParam),
     mpQueryParam(new ScQueryParam),
@@ -315,6 +315,11 @@ ScDBData::ScDBData( const OUString& rName,
     nFilteredRowCount(SCSIZE_MAX)
 {
     aUpper = ScGlobal::getCharClass().uppercase(aUpper);
+    if (!rTableStyleID.isEmpty())
+    {
+        mpTableStyles.reset(new ScTableStyleParam());
+        mpTableStyles->maStyleID = rTableStyleID;
+    }
 }
 
 ScDBData::ScDBData( const ScDBData& rData ) :
@@ -1571,6 +1576,11 @@ const ScTableStyleParam* ScDBData::GetTableStyleInfo() 
const
     return mpTableStyles.get();
 }
 
+void ScDBData::RemoveTableStyleInfo()
+{
+    mpTableStyles.reset();
+}
+
 ScSubTotalFunc ScDBData::GetSubTotalFuncFromString(std::u16string_view 
sFunction)
 {
     if (sFunction == u"sum")
diff --git a/sc/source/filter/excel/xedbdata.cxx 
b/sc/source/filter/excel/xedbdata.cxx
index cde80605294a..b2625f5d01e6 100644
--- a/sc/source/filter/excel/xedbdata.cxx
+++ b/sc/source/filter/excel/xedbdata.cxx
@@ -321,10 +321,16 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, 
const Entry& rEntry )
     if (const ScTableStyleParam* pParam = rData.GetTableStyleInfo())
     {
         const OUString& rStyleName = pParam->maStyleID;
-        const ScTableStyle* pTableStyle = 
rStrm.GetRoot().GetDoc().GetTableStyles().GetTableStyle(rStyleName);
-        if (pTableStyle)
+        if (const ScTableStyles* pTableStyles = 
rStrm.GetRoot().GetDoc().GetTableStyles())
         {
-            pTableStrm->singleElement( XML_tableStyleInfo, XML_name, 
rStyleName.toUtf8(), XML_showFirstColumn, ToPsz10(pParam->mbFirstColumn), 
XML_showLastColumn, ToPsz10(pParam->mbLastColumn), XML_showRowStripes, 
ToPsz10(pParam->mbRowStripes), XML_showColumnStripes, 
ToPsz10(pParam->mbColumnStripes));
+            if (const ScTableStyle* pTableStyle = 
pTableStyles->GetTableStyle(rStyleName))
+            {
+                pTableStrm->singleElement(XML_tableStyleInfo, XML_name, 
rStyleName.toUtf8(),
+                                          XML_showFirstColumn, 
ToPsz10(pParam->mbFirstColumn),
+                                          XML_showLastColumn, 
ToPsz10(pParam->mbLastColumn),
+                                          XML_showRowStripes, 
ToPsz10(pParam->mbRowStripes),
+                                          XML_showColumnStripes, 
ToPsz10(pParam->mbColumnStripes));
+            }
         }
     }
 
diff --git a/sc/source/filter/excel/xestyle.cxx 
b/sc/source/filter/excel/xestyle.cxx
index 20b2190c3351..ce5ffc32f97b 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -3381,11 +3381,14 @@ XclExpXmlTableStyles::XclExpXmlTableStyles( const 
XclExpRoot& rRoot):
 
     const ScDBCollection* pDBCollection = GetDoc().GetDBCollection();
     const ScDBCollection::NamedDBs& rDBs = pDBCollection->getNamedDBs();
-    const ScTableStyles& rTableStyles = GetDoc().GetTableStyles();
+    const ScTableStyles* pTableStyles = GetDoc().GetTableStyles();
+    if (!pTableStyles)
+        return;
+
     for (auto itr = rDBs.begin(); itr != rDBs.end(); ++itr)
     {
         const ScTableStyleParam* pParam = itr->get()->GetTableStyleInfo();
-        if (pParam && rTableStyles.GetTableStyle(pParam->maStyleID))
+        if (pParam && pTableStyles->GetTableStyle(pParam->maStyleID))
         {
             aTableStyleNames.insert(pParam->maStyleID);
         }
@@ -3393,7 +3396,7 @@ XclExpXmlTableStyles::XclExpXmlTableStyles( const 
XclExpRoot& rRoot):
 
     for (const OUString& aTableStyleName : aTableStyleNames)
     {
-        const ScTableStyle* pTableStyle = 
rTableStyles.GetTableStyle(aTableStyleName);
+        const ScTableStyle* pTableStyle = 
pTableStyles->GetTableStyle(aTableStyleName);
         maTableStyles.push_back(std::make_unique<XclExpXmlTableStyle>(rRoot, 
pTableStyle));
     }
 }
diff --git a/sc/source/filter/oox/stylesbuffer.cxx 
b/sc/source/filter/oox/stylesbuffer.cxx
index 6d71ecbd3d3a..2380ec987648 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2607,7 +2607,6 @@ void TableStyle::setTableStyleElement(ScTableStyleElement 
eElement, sal_Int32 nD
 void TableStyle::finalizeImport(const DxfVector& rDxfs)
 {
     ::ScDocument& rDoc = getScDocument();
-    ScTableStyles& rStyles = rDoc.GetTableStyles();
     std::unique_ptr<ScTableStyle> pTableStyle = 
std::make_unique<ScTableStyle>(maName, maUIName);
     pTableStyle->SetOOXMLDefault(mbDefaultOOXMLStyle);
     for (const auto& aTableStyleElementInfo : maTableStyleElements)
@@ -2644,7 +2643,8 @@ void TableStyle::finalizeImport(const DxfVector& rDxfs)
                 SAL_WARN("sc", "the stripe count should only be set for row 
and column stripe elements");
         }
     }
-    rStyles.AddTableStyle(std::move(pTableStyle));
+    if (ScTableStyles* pStyles = rDoc.GetTableStyles())
+        pStyles->AddTableStyle(std::move(pTableStyle));
 }
 
 namespace {

Reply via email to