sw/inc/tblafmt.hxx                     |    3 ++
 sw/qa/python/check_styles.py           |    4 +--
 sw/source/core/doc/tblafmt.cxx         |   39 +++++++++++++++++++++++++++++++++
 sw/source/core/unocore/unostyle.cxx    |    5 +++-
 xmloff/source/table/XMLTableExport.cxx |    2 -
 5 files changed, 49 insertions(+), 4 deletions(-)

New commits:
commit aac70c14c9754108f485a0f06980a377954854ff
Author:     Karthik Godha <[email protected]>
AuthorDate: Mon Feb 23 12:58:39 2026 +0530
Commit:     Karthik Godha <[email protected]>
CommitDate: Mon Feb 23 12:08:21 2026 +0100

    tdf#170771: Export only edited table styles
    
    Instead of exporting all table styles, export only the ones which were
    edited. Note that this will export the edited table style even when it
    is not used in the document, this is intentional.
    
    6fc9264fd967a51a91de401ba871d2642e57f9df was the original commit, but
    got reverted because of a failing test
    
    Change-Id: I3fcc5948a401e1ff4b2c620f21ae265476c89f0f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200028
    Reviewed-by: Karthik Godha <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index 069a8f65c8c5..a4540b1f1ba2 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -59,6 +59,7 @@ public:
 
     /// Comparing based of boxes backgrounds.
     bool operator==(const SwBoxAutoFormat& rRight) const;
+    bool IsSameAs(const SwBoxAutoFormat& rBox) const;
 
     const SvxFrameDirectionItem& GetTextOrientation() const { return 
*m_aTextOrientation; }
     const SwFormatVertOrient& GetVerticalAlignment() const { return 
*m_aVerticalAlignment; }
@@ -145,6 +146,8 @@ public:
                        SvNumberFormatter const*);
     void FillToItemSet(size_t nIndex, SfxItemSet& rItemSet, SvNumberFormatter* 
pNFormatr) const;
 
+    bool NeedsExport();
+
     /// These methods returns what style (row or column) is applied first on 
given Cell
     bool FirstRowEndColumnIsRow();
     bool FirstRowStartColumnIsRow();
diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
index 4145d8052b6e..d78664ac0177 100644
--- a/sw/qa/python/check_styles.py
+++ b/sw/qa/python/check_styles.py
@@ -199,11 +199,11 @@ class CheckStyle(unittest.TestCase):
         xTableStyle = xDoc.createInstance("com.sun.star.style.TableStyle")
         self.assertFalse(xTableStyle.isInUse())
         xDoc.StyleFamilies["TableStyles"].insertByName("Test Table Style", 
xTableStyle)
-        self.assertFalse(xTableStyle.isInUse())
+        self.assertTrue(xTableStyle.isInUse())
         xTable.setPropertyValue("TableTemplateName", "Test Table Style")
         self.assertTrue(xTableStyle.isInUse())
         xTable.setPropertyValue("TableTemplateName", "")
-        self.assertFalse(xTableStyle.isInUse())
+        self.assertTrue(xTableStyle.isInUse())
         xDoc.dispose()
 
     def test_CellFamily(self):
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 5005421b7236..0fcc2e27453c 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -209,6 +209,29 @@ bool SwBoxAutoFormat::operator==(const SwBoxAutoFormat& 
rRight) const
     return GetBackground().GetColor() == rRight.GetBackground().GetColor();
 }
 
+bool SwBoxAutoFormat::IsSameAs(const SwBoxAutoFormat& rRight) const
+{
+    if (GetFont() == rRight.GetFont() && GetHeight() == rRight.GetHeight()
+        && GetWeight() == rRight.GetWeight() && GetPosture() == 
rRight.GetPosture() &&
+
+        GetCJKFont() == rRight.GetCJKFont() && GetCJKHeight() == 
rRight.GetCJKHeight()
+        && GetCJKWeight() == rRight.GetCJKWeight() && GetCJKPosture() == 
rRight.GetCJKPosture() &&
+
+        GetCTLFont() == rRight.GetCTLFont() && GetCTLHeight() == 
rRight.GetCTLHeight()
+        && GetCTLWeight() == rRight.GetCTLWeight() && GetCTLPosture() == 
rRight.GetCTLPosture() &&
+
+        GetUnderline() == rRight.GetUnderline() && GetColor() == 
rRight.GetColor()
+        && GetAdjust() == rRight.GetAdjust() && GetVerJustify() == 
rRight.GetVerJustify() &&
+
+        GetBackground() == rRight.GetBackground() &&
+
+        GetBox() == rRight.GetBox())
+    {
+        return true;
+    }
+    return false;
+}
+
 void SwBoxAutoFormat::SetXObject(rtl::Reference<SwXTextCellStyle> const& 
xObject)
 {
     m_xAutoFormatUnoObject = xObject.get();
@@ -561,6 +584,22 @@ void SwTableAutoFormat::FillToItemSet(size_t nIndex, 
SfxItemSet& rItemSet,
     }
 }
 
+bool SwTableAutoFormat::NeedsExport()
+{
+    const SwTableAutoFormat* rDefaultStyle
+        = SwModule::get()->GetAutoFormatTable().FindAutoFormat(GetName());
+
+    if (!rDefaultStyle || rDefaultStyle->GetParent() != GetParent())
+        return true;
+
+    for (size_t i = 0; i < ELEMENT_COUNT; i++)
+    {
+        if (!m_aBoxAutoFormat[i]->IsSameAs(*rDefaultStyle->GetField(i)))
+            return true;
+    }
+    return false;
+}
+
 bool SwTableAutoFormat::FirstRowEndColumnIsRow()
 {
     if (*GetField(FIRST_ROW) != GetDefaultBoxFormat()
diff --git a/sw/source/core/unocore/unostyle.cxx 
b/sw/source/core/unocore/unostyle.cxx
index bb441e5a0209..48e5884d2744 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -4565,6 +4565,9 @@ sal_Bool SAL_CALL SwXTextTableStyle::isInUse()
     if (!m_bPhysical)
         return false;
 
+    if (m_pTableAutoFormat->NeedsExport())
+        return true;
+
     for (const SwTableFormat* pFormat : 
*m_pDocShell->GetDoc()->GetTableFrameFormats())
     {
         if(pFormat->IsUsed())
@@ -4934,7 +4937,7 @@ sal_Bool SAL_CALL SwXTextCellStyle::isInUse()
     if (!xStyle.is())
         return false;
 
-    return true;
+    return xStyle->isInUse();
 }
 
 OUString SAL_CALL SwXTextCellStyle::getParentStyle() { return m_sParentName; }
diff --git a/xmloff/source/table/XMLTableExport.cxx 
b/xmloff/source/table/XMLTableExport.cxx
index 94c36fb3aee2..1fe589003885 100644
--- a/xmloff/source/table/XMLTableExport.cxx
+++ b/xmloff/source/table/XMLTableExport.cxx
@@ -609,7 +609,7 @@ void XMLTableExport::exportTableTemplates()
             {
             }
 
-            if (!xTableStyle->isInUse() && !bPhysical && !mbWriter)
+            if (!xTableStyle->isInUse() && !bPhysical)
                 continue;
 
             const TableStyleElement* pElements;

Reply via email to