Repository.mk                              |    1 
 include/svx/TableAutoFmt.hxx               |  209 ++++
 include/svx/TableStylesParser.hxx          |  155 +++
 include/svx/dialog/TableAutoFmtDlg.hxx     |   86 +
 include/svx/dialog/TableAutoFmtPreview.hxx |   80 +
 include/svx/dialog/TableStylesDlg.hxx      |  117 ++
 include/svx/strings.hrc                    |   16 
 include/svx/svxids.hrc                     |    2 
 include/svx/svxtableitems.hxx              |   73 +
 svx/Library_svx.mk                         |    6 
 svx/Module_svx.mk                          |    1 
 svx/Package_xml.mk                         |   16 
 svx/UIConfig_svx.mk                        |    3 
 svx/sdi/svx.sdi                            |   15 
 svx/source/dialog/TableAutoFmtDlg.cxx      |  342 +++++++
 svx/source/dialog/TableStylesDlg.cxx       |  850 ++++++++++++++++++
 svx/source/table/tableautofmt.cxx          |  517 +++++++++++
 svx/source/table/tableautofmtpreview.cxx   |  832 ++++++++++++++++++
 svx/source/table/tablestyles.xml           | 1081 +++++++++++++++++++++++
 svx/source/table/tablestylesparser.cxx     |  912 +++++++++++++++++++
 svx/uiconfig/ui/stringinput.ui             |  122 ++
 svx/uiconfig/ui/tableautofmtdlg.ui         |  461 ++++++++++
 svx/uiconfig/ui/tablestylesdlg.ui          | 1329 +++++++++++++++++++++++++++++
 xmloff/inc/xmlprop.hxx                     |    1 
 xmloff/source/text/txtprmap.cxx            |    1 
 25 files changed, 7228 insertions(+)

New commits:
commit 4fb31ea85f94c0cffba2282a119811833e584570
Author:     Karthik <[email protected]>
AuthorDate: Wed Aug 20 15:46:47 2025 +0530
Commit:     Heiko Tietze <[email protected]>
CommitDate: Wed Feb 4 14:02:33 2026 +0100

    tdf#105933 GSoC: New Dialog to Edit Table Styles
    
    - Introduce 'SvxAutoFormat' which combines the common funtionality of
    Writer and Calc Autoformats.
    - Replace module specific 'AutoFormat' dialog and preview with shared
    dialog and preview in 'svx'.
    - tdf#49437: Load and Save Autoformats through XML instead of
    'autotbl.fmt'.
    - New Dialog to edit and create table styles shared b/w Writer and Calc.
    
    Change-Id: I7fa108e527141c05703e0e14298eea818fd10378
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190024
    Tested-by: Heiko Tietze <[email protected]>
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <[email protected]>

diff --git a/Repository.mk b/Repository.mk
index b7403fc80902..fad3c37955e6 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -1043,6 +1043,7 @@ $(eval $(call 
gb_Helper_register_packages_for_install,ooo,\
            favicon \
            unoembind \
        ) \
+       svx_xml \
 ))
 
 $(eval $(call gb_Helper_register_packages_for_install,ooo_fonts,\
diff --git a/include/svx/TableAutoFmt.hxx b/include/svx/TableAutoFmt.hxx
new file mode 100644
index 000000000000..67c5f80314fe
--- /dev/null
+++ b/include/svx/TableAutoFmt.hxx
@@ -0,0 +1,209 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include <svl/itemprop.hxx>
+#include <i18nlangtag/lang.h>
+#include <svx/autoformathelper.hxx>
+#include <bitset>
+
+namespace Autoformat
+{
+enum PropertyIndex : sal_uInt8
+{
+    PROP_FONT = 0,
+    PROP_HEIGHT,
+    PROP_WEIGHT,
+    PROP_POSTURE,
+    PROP_CJK_FONT,
+    PROP_CJK_HEIGHT,
+    PROP_CJK_WEIGHT,
+    PROP_CJK_POSTURE,
+    PROP_CTL_FONT,
+    PROP_CTL_HEIGHT,
+    PROP_CTL_WEIGHT,
+    PROP_CTL_POSTURE,
+    PROP_UNDERLINE,
+    PROP_COLOR,
+    PROP_BOX,
+    PROP_BACKGROUND,
+    PROP_HOR_JUSTIFY,
+    PROP_VER_JUSTIFY,
+    PROP_PADDING,
+    PROP_COUNT
+};
+
+enum Elements : sal_uInt8
+{
+    FIRST_ROW = 0,
+    LAST_ROW,
+    FIRST_COL,
+    LAST_COL,
+    BODY,
+    EVEN_ROW,
+    ODD_ROW,
+    EVEN_COL,
+    ODD_COL,
+    BACKGROUND,
+    FIRST_ROW_EVEN_COL,
+    LAST_ROW_EVEN_COL,
+    FIRST_ROW_END_COL,
+    FIRST_ROW_START_COL,
+    LAST_ROW_END_COL,
+    LAST_ROW_START_COL,
+    ELEMENT_COUNT
+};
+}
+
+using namespace Autoformat;
+
+class SVX_DLLPUBLIC SvxAutoFormatDataField : public AutoFormatBase
+{
+private:
+    // number format
+    rtl::OUString maNumFormatString;
+    LanguageType meSysLanguage;
+    LanguageType meNumFormatLanguage;
+
+    std::bitset<Autoformat::PROP_COUNT> mSetProperties;
+
+public:
+    SvxAutoFormatDataField(){};
+    SvxAutoFormatDataField(const SvxAutoFormatDataField& rCopy);
+
+    void GetValueFormat(OUString& rFormat, LanguageType& rLng, LanguageType& 
rSys) const;
+    const OUString& GetNumFormatString() const noexcept { return 
maNumFormatString; }
+    const LanguageType& GetSysLanguage() const noexcept { return 
meSysLanguage; }
+    const LanguageType& GetNumFormatLanguage() const noexcept { return 
meNumFormatLanguage; }
+
+    void SetValueFormat(const OUString& rFormat, LanguageType eLng, 
LanguageType eSys);
+    void SetNumFormatString(const OUString& rNew) { maNumFormatString = rNew; }
+    void SetSysLanguage(const LanguageType& rNew) noexcept { meSysLanguage = 
rNew; }
+    void SetNumFormatLanguage(const LanguageType& rNew) noexcept { 
meNumFormatLanguage = rNew; }
+
+    bool IsPropertySet(PropertyIndex prop) const noexcept
+    {
+        return prop < PROP_COUNT && mSetProperties[prop];
+    }
+    void SetPropertyFlag(PropertyIndex prop, bool set = true) noexcept
+    {
+        if (prop < PROP_COUNT)
+            mSetProperties[prop] = set;
+    }
+    std::bitset<PROP_COUNT> GetPropertySet() const { return mSetProperties; }
+    void SetPropertySet(std::bitset<PROP_COUNT> aSet) { mSetProperties = aSet; 
}
+};
+
+class SVX_DLLPUBLIC SvxAutoFormatData
+{
+private:
+    OUString maName;
+
+    // Common flags of Calc and Writer.
+    bool mbInclFont : 1;
+    bool mbInclJustify : 1;
+    bool mbInclFrame : 1;
+    bool mbInclBackground : 1;
+    // Calc specific flags
+    bool mbInclValueFormat : 1;
+    bool mbInclWidthHeight : 1;
+
+    bool mbUseFirstRowStyles : 1;
+    bool mbUseLastRowStyles : 1;
+    bool mbUseFirstColStyles : 1;
+    bool mbUseLastColStyles : 1;
+    bool mbUseBandedRowStyles : 1;
+    bool mbUseBandedColStyles : 1;
+
+    OUString maParent;
+
+public:
+    SvxAutoFormatData();
+    SvxAutoFormatData(const SvxAutoFormatData& rData);
+    virtual ~SvxAutoFormatData() = default;
+
+    bool IsFont() const noexcept { return mbInclFont; }
+    bool IsJustify() const noexcept { return mbInclJustify; }
+    bool IsFrame() const noexcept { return mbInclFrame; }
+    bool IsBackground() const noexcept { return mbInclBackground; }
+    bool IsValueFormat() const noexcept { return mbInclValueFormat; }
+    bool IsWidthHeight() const noexcept { return mbInclWidthHeight; }
+
+    bool UseFirstRowStyles() const noexcept { return mbUseFirstRowStyles; }
+    bool UseLastRowStyles() const noexcept { return mbUseLastRowStyles; }
+    bool UseFirstColStyles() const noexcept { return mbUseFirstColStyles; }
+    bool UseLastColStyles() const noexcept { return mbUseLastColStyles; }
+    bool UseBandedRowStyles() const noexcept { return mbUseBandedRowStyles; }
+    bool UseBandedColStyles() const noexcept { return mbUseBandedColStyles; }
+
+    void SetFont(const bool bNew) noexcept { mbInclFont = bNew; }
+    void SetJustify(const bool bNew) noexcept { mbInclJustify = bNew; }
+    void SetFrame(const bool bNew) noexcept { mbInclFrame = bNew; }
+    void SetBackground(const bool bNew) noexcept { mbInclBackground = bNew; }
+    void SetValueFormat(const bool bNew) noexcept { mbInclValueFormat = bNew; }
+    void SetWidthHeight(const bool bNew) noexcept { mbInclWidthHeight = bNew; }
+    void SetParent(const OUString& rParentName) { maParent = rParentName; }
+
+    void SetUseFirstRowStyles(const bool bNew) noexcept { mbUseFirstRowStyles 
= bNew; }
+    void SetUseFirstColStyles(const bool bNew) noexcept { mbUseFirstColStyles 
= bNew; }
+    void SetUseLastRowStyles(const bool bNew) noexcept { mbUseLastRowStyles = 
bNew; }
+    void SetUseLastColStyles(const bool bNew) noexcept { mbUseLastColStyles = 
bNew; }
+    void SetUseBandedRowStyles(const bool bNew) noexcept { 
mbUseBandedRowStyles = bNew; }
+    void SetUseBandedColStyles(const bool bNew) noexcept { 
mbUseBandedColStyles = bNew; }
+
+    const OUString& GetName() const noexcept { return maName; }
+    const OUString& GetParent() const noexcept { return maParent; }
+
+    virtual void SetName(const OUString& rName) { maName = rName; }
+    virtual SvxAutoFormatDataField* GetField(size_t nIndex) = 0;
+    virtual const SvxAutoFormatDataField* GetField(size_t nIndex) const = 0;
+    virtual SvxAutoFormatDataField* GetDefaultField() const = 0;
+    virtual bool SetField(size_t nIndex, const SvxAutoFormatDataField& aField) 
= 0;
+    virtual SvxAutoFormatData* MakeCopy() const = 0;
+
+    void FillToItemSet(size_t nIndex, SfxItemSet& rItemSet) const;
+    void MergeStyle(const SvxAutoFormatData& pData);
+    void ResetAutoFormat(SvxAutoFormatData& pOld);
+
+    SvxAutoFormatData& operator=(const SvxAutoFormatData& rCopy);
+};
+
+class SVX_DLLPUBLIC SvxAutoFormat
+{
+public:
+    virtual ~SvxAutoFormat();
+
+    virtual const SvxAutoFormatData* GetData(size_t nIndex) const = 0;
+    virtual SvxAutoFormatData* GetData(size_t nIndex) = 0;
+    virtual bool InsertAutoFormat(SvxAutoFormatData* pFormat) = 0;
+    virtual SvxAutoFormatData* ReleaseAutoFormat(const OUString& rName) = 0;
+    virtual SvxAutoFormatData* FindAutoFormat(const OUString& rName) const = 0;
+    virtual SvxAutoFormatData* GetDefaultData() = 0;
+    virtual SvxAutoFormatDataField* GetDefaultField() = 0;
+    virtual const SvxAutoFormatData* GetResolvedStyle(const SvxAutoFormatData* 
pData) const = 0;
+    virtual size_t size() const = 0;
+    virtual void ResetParent(const OUString& rName);
+
+    static const SfxItemPropertySet& GetTablePropertySet();
+
+    bool Load(bool bWriter);
+    bool Save();
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/TableStylesParser.hxx 
b/include/svx/TableStylesParser.hxx
new file mode 100644
index 000000000000..bc97f9cac3cd
--- /dev/null
+++ b/include/svx/TableStylesParser.hxx
@@ -0,0 +1,155 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include <svx/svxdllapi.h>
+#include <bitset>
+#include <editeng/borderline.hxx>
+#include <xmloff/xmlexp.hxx>
+#include <xmloff/prstylei.hxx>
+#include <xmloff/table/XMLTableImport.hxx>
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/xmlnamespace.hxx>
+
+class SvxAutoFormat;
+class SvxAutoFormatData;
+class SvxAutoFormatDataField;
+
+struct TableStyle
+{
+    rtl::OUString sParentName;
+    std::unique_ptr<SvxAutoFormatDataField> pDataField;
+};
+
+class SvxTableStylesImport : public SvXMLImport
+{
+private:
+    SvxAutoFormat& mpAutoFormat;
+    std::map<OUString, TableStyle> maCellStyles;
+    XMLTableTemplateMap maTableTemplates;
+    std::map<OUString, std::bitset<6>> maTableStyles;
+
+public:
+    SvxTableStylesImport(const 
css::uno::Reference<css::uno::XComponentContext>& rContext,
+                         SvxAutoFormat& rAutoFormat);
+    virtual ~SvxTableStylesImport() override;
+
+    // Override from SvXMLImport
+    virtual SvXMLImportContext* CreateFastContext(
+        sal_Int32 nElement,
+        const css::uno::Reference<css::xml::sax::XFastAttributeList>& 
xAttrList) override;
+
+    void addCellStyle(const OUString& rName, const OUString& rParentName,
+                      std::unique_ptr<SvxAutoFormatDataField> pField);
+    const TableStyle* getCellStyle(const OUString& rName);
+    void addTableTemplate(const OUString& rsStyleName, const XMLTableTemplate& 
xTableTemplate,
+                          std::bitset<6>& rUseSet);
+    SvxAutoFormat& GetFormat() { return mpAutoFormat; }
+    void finishStyles();
+};
+
+class SvxTableStylesContext : public SvXMLStylesContext
+{
+private:
+    mutable std::unique_ptr<SvXMLImportPropertyMapper> mxTableCellPropMapper;
+    SvxTableStylesImport* mpImport;
+
+public:
+    SvxTableStylesContext(SvxTableStylesImport& rImport);
+
+    virtual SvXMLStyleContext* CreateStyleChildContext(
+        sal_Int32 nElement,
+        const css::uno::Reference<css::xml::sax::XFastAttributeList>& 
xAttrList) override;
+
+    virtual SvXMLStyleContext* CreateStyleStyleChildContext(
+        XmlStyleFamily nFamily, sal_Int32 nElement,
+        const css::uno::Reference<css::xml::sax::XFastAttributeList>& 
xAttrList) override;
+
+    virtual SvXMLImportPropertyMapper*
+    GetImportPropertyMapper(XmlStyleFamily nFamily) const override;
+
+    virtual void SAL_CALL endFastElement(sal_Int32 Element) override;
+};
+
+class SvxTableTemplateContext : public SvXMLStyleContext
+{
+private:
+    XMLTableTemplate maTableTemplate;
+    OUString msTemplateName;
+    SvxTableStylesImport* mpImport;
+    std::bitset<6> maUseSet;
+
+protected:
+    virtual void SetAttribute(sal_Int32 nElement, const OUString& rValue) 
override;
+
+public:
+    SvxTableTemplateContext(SvXMLImport& rImport, SvxTableStylesImport& 
rSvxImport);
+
+    virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL 
createFastChildContext(
+        sal_Int32 nElement,
+        const css::uno::Reference<css::xml::sax::XFastAttributeList>& 
AttrList) override;
+
+    virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+};
+
+class SvxCellStyleContext : public XMLPropStyleContext
+{
+private:
+    std::unique_ptr<SvxAutoFormatDataField> mpField;
+    SvxTableStylesImport* mpImport;
+
+public:
+    explicit SvxCellStyleContext(SvXMLImport& rImport, SvxTableStylesContext& 
rStyles,
+                                 SvxTableStylesImport& rSvxImport);
+
+    virtual void Finish(bool bOverwrite) override;
+
+    void setPropertyValue(OUString& rPropName, const css::uno::Any& aValue);
+};
+
+class SVX_DLLPUBLIC SvxTableStylesExport : public SvXMLExport
+{
+private:
+    SvxAutoFormat& mpAutoFormat;
+    std::map<OUString, std::unique_ptr<SvxAutoFormatDataField>> maCellStyles;
+
+    void exportTableTemplate(const SvxAutoFormatData& rData);
+    void exportCellStyle(const SvxAutoFormatDataField& rField, OUString& 
rStyleName,
+                         OUString& rParentName);
+    void exportCellProperties(const SvxAutoFormatDataField& rField,
+                              const SvxAutoFormatDataField& rParent);
+    void exportParaProperties(const SvxAutoFormatDataField& rField,
+                              const SvxAutoFormatDataField& rParent);
+    void exportTextProperties(const SvxAutoFormatDataField& rField,
+                              const SvxAutoFormatDataField& rParent);
+
+public:
+    SvxTableStylesExport(
+        const css::uno::Reference<css::uno::XComponentContext>& rContext, 
OUString const& rFileName,
+        const css::uno::Reference<com::sun::star::xml::sax::XDocumentHandler>& 
xHandler,
+        SvxAutoFormat& rAutoFormat);
+
+    virtual void ExportAutoStyles_() override {}
+    virtual void ExportMasterStyles_() override {}
+    virtual void ExportContent_() override {}
+
+    void ExportStyles();
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/dialog/TableAutoFmtDlg.hxx 
b/include/svx/dialog/TableAutoFmtDlg.hxx
new file mode 100644
index 000000000000..c611d39a8629
--- /dev/null
+++ b/include/svx/dialog/TableAutoFmtDlg.hxx
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <vcl/weld/DialogController.hxx>
+#include <vcl/weld/MetricSpinButton.hxx>
+#include <vcl/weld/TreeView.hxx>
+#include "TableAutoFmtPreview.hxx"
+
+class SVX_DLLPUBLIC SvxTableAutoFmtDlg : public weld::GenericDialogController
+{
+private:
+    // Resource strings
+    OUString maStrTitle;
+    OUString maStrLabel;
+    OUString maStrClose;
+    OUString maStrDelMsg;
+    OUString maStrDelTitle;
+    OUString maStrRename;
+
+    // Core Data
+    SvxAutoFormat& mpFormat;
+    OUString maFormatName;
+    size_t mnIndex;
+    bool mbWriter;
+    bool mbRTL;
+
+    // Preview
+    SvxAutoFmtPreview maWndPreview;
+
+    // UI Controls
+    std::unique_ptr<weld::TreeView> mxLbFormat;
+    std::unique_ptr<weld::Button> mxBtnCancel;
+    std::unique_ptr<weld::Button> mxBtnAdd;
+    std::unique_ptr<weld::Button> mxBtnEdit;
+    std::unique_ptr<weld::Button> mxBtnRemove;
+    std::unique_ptr<weld::Button> mxBtnRename;
+    std::unique_ptr<weld::CheckButton> mxBtnNumFormat;
+    std::unique_ptr<weld::CheckButton> mxBtnBorder;
+    std::unique_ptr<weld::CheckButton> mxBtnFont;
+    std::unique_ptr<weld::CheckButton> mxBtnPattern;
+    std::unique_ptr<weld::CheckButton> mxBtnAlignment;
+    std::unique_ptr<weld::CheckButton> mxBtnAdjust;
+    std::unique_ptr<weld::CustomWeld> mxWndPreview;
+
+    DECL_LINK(CheckHdl, weld::Toggleable&, void);
+    DECL_LINK(AddHdl, weld::Button&, void);
+    DECL_LINK(EditHdl, weld::Button&, void);
+    DECL_LINK(RemoveHdl, weld::Button&, void);
+    DECL_LINK(RenameHdl, weld::Button&, void);
+    DECL_LINK(SelFormatHdl, weld::TreeView&, void);
+    DECL_LINK(DblClkHdl, weld::TreeView&, bool);
+
+    OUString GenerateUniqueStyleName();
+
+    void Init();
+    void UpdateChecks();
+    void PopulateFormatList();
+    void UpdateUIState();
+
+public:
+    SvxTableAutoFmtDlg(SvxAutoFormat& rFormat, const OUString& sFormatName, 
weld::Window* pParent,
+                       bool bWriter, bool bRTL);
+
+    size_t GetIndex() const { return mnIndex; }
+    OUString GetCurrFormatName();
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/dialog/TableAutoFmtPreview.hxx 
b/include/svx/dialog/TableAutoFmtPreview.hxx
new file mode 100644
index 000000000000..9b6cc5fb0d92
--- /dev/null
+++ b/include/svx/dialog/TableAutoFmtPreview.hxx
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include <com/sun/star/i18n/XBreakIterator.hdl>
+#include <svl/numformat.hxx>
+#include <svx/framelinkarray.hxx>
+#include <svx/TableAutoFmt.hxx>
+#include <vcl/weld/customweld.hxx>
+
+class SVX_DLLPUBLIC SvxAutoFmtPreview : public weld::CustomWidgetController
+{
+public:
+    SvxAutoFmtPreview(bool bRTL);
+
+    void NotifyChange(const SvxAutoFormatData* rNewData);
+
+private:
+    static const tools::Long FRAME_OFFSET = 4;
+    static const size_t GRID_SIZE = 5;
+
+    const SvxAutoFormatData* mpCurrentData;
+    svx::frame::Array maArray; /// Implementation to draw the frame borders.
+    bool mbFitWidth;
+    bool mbRTL;
+    Size maPreviousSize;
+    tools::Long mnLabelColWidth;
+    tools::Long mnDataColWidth1;
+    tools::Long mnDataColWidth2;
+    tools::Long mnRowHeight;
+    const OUString maStrJan;
+    const OUString maStrFeb;
+    const OUString maStrMar;
+    const OUString maStrNorth;
+    const OUString maStrMid;
+    const OUString maStrSouth;
+    const OUString maStrSum;
+    std::unique_ptr<SvNumberFormatter> mxNumFormat;
+
+    css::uno::Reference<css::i18n::XBreakIterator> mxBreakIter;
+
+    void Init();
+    virtual void Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& rRect) override;
+    virtual void Resize() override;
+    void CalcCellArray(bool bFitWidth);
+    void CalcLineMap();
+    void PaintCells(vcl::RenderContext& rRenderContext);
+
+    sal_uInt8 GetFormatIndex(size_t nCol, size_t nRow);
+    const SvxBoxItem& GetBoxItem(size_t nCol, size_t nRow) const;
+    const SvxLineItem& GetDiagItem(size_t nCol, size_t nRow, bool bTLBR) const;
+
+    void DrawString(vcl::RenderContext& rRenderContext, size_t nCol, size_t 
nRow);
+    void DrawBackground(vcl::RenderContext& rRenderContext);
+
+    void MakeFonts(vcl::RenderContext const& rRenderContext, sal_uInt8 nIndex, 
vcl::Font& rFont,
+                   vcl::Font& rCJKFont, vcl::Font& rCTLFont);
+
+    void setStyleFromBorderPriority(size_t nCol, size_t nRow);
+    void setStyleFromBorder(sal_uInt8 nElement, size_t nCol, size_t nRow, bool 
reset);
+    bool compareTextAttr(int nIndex);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/dialog/TableStylesDlg.hxx 
b/include/svx/dialog/TableStylesDlg.hxx
new file mode 100644
index 000000000000..c5faebd7376d
--- /dev/null
+++ b/include/svx/dialog/TableStylesDlg.hxx
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include <svtools/ctrlbox.hxx>
+#include <svx/colorbox.hxx>
+#include <vcl/weld/DialogController.hxx>
+#include <vcl/weld/MetricSpinButton.hxx>
+#include <vcl/weld/TreeView.hxx>
+#include <svx/dialog/TableAutoFmtPreview.hxx>
+
+class SVX_DLLPUBLIC SvxTableStylesDlg : public weld::GenericDialogController
+{
+private:
+    enum BorderWidth
+    {
+        HAIRLINE = 1,
+        VERY_THIN = 10,
+        THIN = 15,
+        MEDIUM = 30,
+        THICK = 45,
+        EXTRA_THICK = 90
+    };
+
+    enum BorderLayout
+    {
+        TABLE_NO_BORDERS = 1,
+        TABLE_LEFT_BORDER,
+        TABLE_RIGHT_BORDER,
+        TABLE_LEFT_RIGHT_BORDERS,
+        TABLE_TOP_BORDER,
+        TABLE_BOTTOM_BORDER,
+        TABLE_TOP_BOTTOM_BORDERS,
+        TABLE_ALL_BORDERS
+    };
+
+    SvxAutoFmtPreview maWndPreview;
+    SvxAutoFormat& mpFormat;
+    SvxAutoFormatData& mpOriginalData;
+    SvxAutoFormatData& mpData;
+    SvxAutoFormatDataField* mpCurrField;
+    OUString msParentName;
+    bool mbNewStyle;
+    int mnField;
+
+    std::unique_ptr<weld::Toolbar> mpTextStyle;
+    std::unique_ptr<weld::Toolbar> mpNumberFormat;
+    std::unique_ptr<weld::Toolbar> mpHorAlign;
+    std::unique_ptr<weld::Toolbar> mpVerAlign;
+    std::unique_ptr<weld::MetricSpinButton> m_xCellPadding;
+    std::unique_ptr<weld::ComboBox> m_xLinkedWith;
+    std::unique_ptr<weld::ComboBox> m_xBorderWidth;
+    std::unique_ptr<weld::Container> m_xNumberFormat;
+    std::unique_ptr<weld::ComboBox> m_xTextFont;
+    std::unique_ptr<FontSizeBox> m_xTextSize;
+    std::unique_ptr<ColorListBox> m_xCellColor;
+    std::unique_ptr<ColorListBox> m_xBorderColor;
+    std::unique_ptr<ColorListBox> m_xTextColor;
+    std::unique_ptr<SvtLineListBox> m_xBorderStyle;
+    std::unique_ptr<ValueSet> m_xBorderSelector;
+    std::unique_ptr<weld::CustomWeld> m_xBorderSelectorWin;
+    std::unique_ptr<weld::CustomWeld> mxWndPreview;
+    std::unique_ptr<weld::ComboBox> m_xElementBox;
+    std::unique_ptr<weld::Entry> m_xNameEntry;
+    std::unique_ptr<weld::Button> m_xOkayBtn;
+    std::unique_ptr<weld::Button> m_xResetBtn;
+    std::unique_ptr<weld::Button> m_xCancelBtn;
+
+    void InitLineStyles();
+    void InitBorderSelector();
+
+    DECL_LINK(ElementSelHdl, weld::ComboBox&, void);
+    DECL_LINK(LinkedWithSelHdl, weld::ComboBox&, void);
+    DECL_LINK(BorderWidthSelHdl, weld::ComboBox&, void);
+    DECL_LINK(TextFontSelHdl, weld::ComboBox&, void);
+    DECL_LINK(TextSizeSelHdl, weld::ComboBox&, void);
+    DECL_LINK(CellColorSelHdl, ColorListBox&, void);
+    DECL_LINK(BorderColorSelHdl, ColorListBox&, void);
+    DECL_LINK(TextColorSelHdl, ColorListBox&, void);
+    DECL_LINK(TextStyleHdl, const OUString&, void);
+    DECL_LINK(HorAlignHdl, const OUString&, void);
+    DECL_LINK(VerAlignHdl, const OUString&, void);
+    DECL_LINK(BorderLayoutSelHdl, ValueSet*, void);
+    DECL_LINK(BorderStyleHdl, SvtLineListBox&, void);
+    DECL_LINK(PaddingHdl, weld::MetricSpinButton&, void);
+    DECL_LINK(OkayHdl, weld::Button&, void);
+    DECL_LINK(ResetHdl, weld::Button&, void);
+    DECL_LINK(CancelHdl, weld::Button&, void);
+
+    void UpdateWidth(tools::Long nWidth);
+    SvxBoxItem GetValidBox();
+    OUString GetValidFont(size_t nField);
+
+public:
+    SvxTableStylesDlg(weld::Window* pWindow, bool bNewStyle, SvxAutoFormat& 
pFormat,
+                      SvxAutoFormatData& pData, bool bRTL);
+    virtual ~SvxTableStylesDlg() override;
+    SvxAutoFormatData& GetFormat() { return mpData; };
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc
index 48f5b89f0d54..d9e8f2dc5d71 100644
--- a/include/svx/strings.hrc
+++ b/include/svx/strings.hrc
@@ -1883,6 +1883,22 @@
 #define RID_SVXSTR_FOOTER                           NC_("RID_SVXSTR_FOOTER", 
"Footer")
 #define RID_SVXSTR_HEADER                           NC_("RID_SVXSTR_HEADER", 
"Header")
 
+// strings related to table autoformat styles dialog
+#define RID_SVXSTR_ADD_AUTOFORMAT_TITLE                    
NC_("RID_SVXSTR_ADD_AUTOFORMAT_TITLE", "Add AutoFormat" )
+#define RID_SVXSTR_RENAME_AUTOFORMAT_TITLE                 
NC_("RID_SVXSTR_RENAME_AUTOFORMAT_TITLE", "Rename AutoFormat" )
+#define RID_SVXSTR_ADD_AUTOFORMAT_LABEL                    
NC_("RID_SVXSTR_ADD_AUTOFORMAT_LABEL", "Name" )
+#define RID_SVXSTR_DEL_AUTOFORMAT_TITLE                    
NC_("RID_SVXSTR_DEL_AUTOFORMAT_TITLE", "Delete AutoFormat" )
+#define RID_SVXSTR_DEL_AUTOFORMAT_MSG                      
NC_("RID_SVXSTR_DEL_AUTOFORMAT_MSG", "Do you want to delete the following 
AutoFormat?" )
+#define RID_SVXSTR_BTN_AUTOFORMAT_CLOSE                    
NC_("RID_SVXSTR_BTN_AUTOFORMAT_CLOSE", "~Close" )
+#define RID_SVXSTR_JAN                                     
NC_("RID_SVXSTR_JAN", "Jan" )
+#define RID_SVXSTR_FEB                                     
NC_("RID_SVXSTR_FEB", "Feb" )
+#define RID_SVXSTR_MAR                                     
NC_("RID_SVXSTR_MAR", "Mar" )
+#define RID_SVXSTR_NORTH                                   
NC_("RID_SVXSTR_NORTH", "North" )
+#define RID_SVXSTR_MID                                     
NC_("RID_SVXSTR_MID", "Mid" )
+#define RID_SVXSTR_SOUTH                                   
NC_("RID_SVXSTR_SOUTH", "South" )
+#define RID_SVXSTR_SUM                                     
NC_("RID_SVXSTR_SUM", "Total" )
+#define RID_SVXSTR_INVALID_AUTOFORMAT_NAME                 
NC_("RID_SVXSTR_INVALID_AUTOFORMAT_NAME", "You have entered an invalid name.
The desired AutoFormat could not be created. 
Try again using a different name. 
(The name shouldn't contain '.' or '-')")
+
 /*--------------------------------------------------------------------
     Description: GraphicSizeCheck strings
  --------------------------------------------------------------------*/
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc
index 9d318e8da829..237205995053 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -1123,6 +1123,8 @@ class XFillGradientItem;
 
 #define SID_ATTR_RESIZE_ALL_PAGES                       
TypedWhichId<SfxBoolItem>( SID_SVX_START + 1257 )
 
+#define SID_RESET_AUTOFORMATS                           ( SID_SVX_START + 1258 
)
+
 // IMPORTANT NOTE: adjust SID_SVX_FIRSTFREE, when adding new slot id
 #define SID_SVX_FIRSTFREE                               ( SID_SVX_START + 1257 
+ 1 )
 
diff --git a/include/svx/svxtableitems.hxx b/include/svx/svxtableitems.hxx
new file mode 100644
index 000000000000..0c5aedc8b368
--- /dev/null
+++ b/include/svx/svxtableitems.hxx
@@ -0,0 +1,73 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include <editeng/boxitem.hxx>
+#include <editeng/brushitem.hxx>
+#include <editeng/colritem.hxx>
+#include <editeng/contouritem.hxx>
+#include <editeng/crossedoutitem.hxx>
+#include <editeng/fhgtitem.hxx>
+#include <editeng/fontitem.hxx>
+#include <editeng/justifyitem.hxx>
+#include <editeng/lineitem.hxx>
+#include <editeng/postitem.hxx>
+#include <editeng/shdditem.hxx>
+#include <editeng/udlnitem.hxx>
+#include <editeng/wghtitem.hxx>
+#include <svl/typedwhich.hxx>
+#include <svx/algitem.hxx>
+
+class SvxFontItem;
+class SvxFontHeightItem;
+class SvxWeightItem;
+class SvxPostureItem;
+class SvxUnderlineItem;
+class SvxBrushItem;
+class SvxVerJustifyItem;
+class SvxColorItem;
+class SvxBoxItem;
+class SvxLineItem;
+
+inline constexpr sal_uInt16 SVX_TABLE_START(3000);
+
+inline constexpr TypedWhichId<SvxFontItem> SVX_TABLE_FONT(SVX_TABLE_START + 1);
+inline constexpr TypedWhichId<SvxFontHeightItem> 
SVX_TABLE_FONT_HEIGHT(SVX_TABLE_START + 2);
+inline constexpr TypedWhichId<SvxWeightItem> 
SVX_TABLE_FONT_WEIGHT(SVX_TABLE_START + 3);
+inline constexpr TypedWhichId<SvxPostureItem> 
SVX_TABLE_FONT_POSTURE(SVX_TABLE_START + 4);
+inline constexpr TypedWhichId<SvxFontItem> SVX_TABLE_CJK_FONT(SVX_TABLE_START 
+ 5);
+inline constexpr TypedWhichId<SvxFontHeightItem> 
SVX_TABLE_CJK_FONT_HEIGHT(SVX_TABLE_START + 6);
+inline constexpr TypedWhichId<SvxWeightItem> 
SVX_TABLE_CJK_FONT_WEIGHT(SVX_TABLE_START + 7);
+inline constexpr TypedWhichId<SvxPostureItem> 
SVX_TABLE_CJK_FONT_POSTURE(SVX_TABLE_START + 8);
+inline constexpr TypedWhichId<SvxFontItem> SVX_TABLE_CTL_FONT(SVX_TABLE_START 
+ 9);
+inline constexpr TypedWhichId<SvxFontHeightItem> 
SVX_TABLE_CTL_FONT_HEIGHT(SVX_TABLE_START + 10);
+inline constexpr TypedWhichId<SvxWeightItem> 
SVX_TABLE_CTL_FONT_WEIGHT(SVX_TABLE_START + 11);
+inline constexpr TypedWhichId<SvxPostureItem> 
SVX_TABLE_CTL_FONT_POSTURE(SVX_TABLE_START + 12);
+inline constexpr TypedWhichId<SvxUnderlineItem> 
SVX_TABLE_FONT_UNDERLINE(SVX_TABLE_START + 13);
+inline constexpr TypedWhichId<SvxColorItem> 
SVX_TABLE_FONT_COLOR(SVX_TABLE_START + 14);
+inline constexpr TypedWhichId<SvxBrushItem> 
SVX_TABLE_BACKGROUND(SVX_TABLE_START + 15);
+inline constexpr TypedWhichId<SvxHorJustifyItem> 
SVX_TABLE_HOR_JUSTIFY(SVX_TABLE_START + 16);
+inline constexpr TypedWhichId<SvxVerJustifyItem> 
SVX_TABLE_VER_JUSTIFY(SVX_TABLE_START + 17);
+inline constexpr TypedWhichId<SvxBoxItem> SVX_TABLE_BOX(SVX_TABLE_START + 18);
+inline constexpr TypedWhichId<SvxLineItem> 
SVX_TABLE_PARA_ADJUST(SVX_TABLE_START + 19);
+inline constexpr TypedWhichId<SvxMarginItem> SVX_TABLE_MARGIN(SVX_TABLE_START 
+ 20);
+
+inline constexpr sal_uInt16 SVX_TABLE_LAST(SVX_TABLE_PARA_ADJUST);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index 87bffaaa54e8..bc810480b69f 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -76,6 +76,7 @@ $(eval $(call gb_Library_use_libraries,svx,\
     vcl \
     xo \
     xmlscript \
+    sax \
 ))
 
 $(eval $(call gb_Library_use_externals,svx,\
@@ -183,6 +184,8 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
     svx/source/dialog/txenctab \
     svx/source/dialog/weldeditview \
     svx/source/dialog/signaturelinehelper \
+    svx/source/dialog/TableAutoFmtDlg \
+    svx/source/dialog/TableStylesDlg \
     svx/source/engine3d/float3d \
     svx/source/fmcomp/dbaobjectex \
     svx/source/form/databaselocationinput \
@@ -265,6 +268,9 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
     svx/source/table/tablertfexporter \
     svx/source/table/tablertfimporter \
        svx/source/table/tablehtmlimporter \
+       svx/source/table/tableautofmt \
+       svx/source/table/tableautofmtpreview \
+       svx/source/table/tablestylesparser \
     svx/source/tbxctrls/bulletsnumbering \
     svx/source/tbxctrls/colrctrl \
     svx/source/tbxctrls/SvxColorChildWindow \
diff --git a/svx/Module_svx.mk b/svx/Module_svx.mk
index d89aaad42994..089e9a919d57 100644
--- a/svx/Module_svx.mk
+++ b/svx/Module_svx.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_Module_add_targets,svx,\
     Library_svx \
     Library_svxcore \
     Package_document_themes \
+    Package_xml \
 ))
 
 ifeq ($(gb_Side),host)
diff --git a/svx/Package_xml.mk b/svx/Package_xml.mk
new file mode 100644
index 000000000000..fbb995565dbc
--- /dev/null
+++ b/svx/Package_xml.mk
@@ -0,0 +1,16 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Package_Package,svx_xml,$(SRCDIR)/svx/source/table))
+
+$(eval $(call gb_Package_add_files,svx_xml,$(LIBO_SHARE_FOLDER)/svx,\
+       tablestyles.xml \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index d09cbb46bdcc..137ceb7eb4a9 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -152,6 +152,9 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
        svx/uiconfig/ui/xmlsecstatmenu \
        svx/uiconfig/ui/xformspage \
        svx/uiconfig/ui/zoommenu \
+       svx/uiconfig/ui/tableautofmtdlg \
+       svx/uiconfig/ui/tablestylesdlg \
+       svx/uiconfig/ui/stringinput \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 95dff19d728e..cdaab0ad1e75 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -357,6 +357,21 @@ SfxVoidItem AutoFormat SID_AUTOFORMAT
     GroupId = SfxGroupId::Format;
 ]
 
+SfxVoidItem ResetAutoFormats SID_RESET_AUTOFORMATS
+(SfxStringItem aFormatName SID_AUTOFORMAT, SfxStringItem aOldName 
SID_RESET_AUTOFORMATS)
+[
+    AutoUpdate = FALSE,
+    FastCall = TRUE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+
+    AccelConfig = FALSE,
+    MenuConfig = FALSE,
+    ToolBoxConfig = FALSE,
+    GroupId = SfxGroupId::Table;
+]
 
 
 SfxStringItem BackgroundImage SID_GALLERY_BG_BRUSH
diff --git a/svx/source/dialog/TableAutoFmtDlg.cxx 
b/svx/source/dialog/TableAutoFmtDlg.cxx
new file mode 100644
index 000000000000..1e221e7c8abb
--- /dev/null
+++ b/svx/source/dialog/TableAutoFmtDlg.cxx
@@ -0,0 +1,342 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <comphelper/dispatchcommand.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <svx/dialog/TableStylesDlg.hxx>
+#include <svx/dialog/TableAutoFmtDlg.hxx>
+#include <sfx2/basedlgs.hxx>
+#include <svx/dialmgr.hxx>
+#include <svx/strings.hrc>
+#include <vcl/svapp.hxx>
+
+namespace
+{
+constexpr size_t DEFAULT_STYLE = 0;
+
+class SvxStringInputDlg : public SfxDialogController
+{
+private:
+    std::unique_ptr<weld::Label> mxLabel;
+    std::unique_ptr<weld::Entry> mxEdInput; // Edit obtains the focus.
+
+public:
+    SvxStringInputDlg(weld::Window* pParent, const OUString& rTitle, const 
OUString& rEditTitle,
+                      const OUString& rDefault)
+        : SfxDialogController(pParent, u"svx/ui/stringinput.ui"_ustr, 
u"StringInputDialog"_ustr)
+        , mxLabel(m_xBuilder->weld_label(u"name"_ustr))
+        , mxEdInput(m_xBuilder->weld_entry(u"edit"_ustr))
+    {
+        mxLabel->set_label(rEditTitle);
+        m_xDialog->set_title(rTitle);
+        mxEdInput->set_text(rDefault);
+        mxEdInput->select_region(0, -1);
+    }
+
+    OUString GetInputString() const { return mxEdInput->get_text(); }
+};
+}
+
+// AutoFormat-Dialog:
+SvxTableAutoFmtDlg::SvxTableAutoFmtDlg(SvxAutoFormat& rFormat, const OUString& 
sFormatName,
+                                       weld::Window* pParent, bool bWriter, 
bool bRTL)
+    : weld::GenericDialogController(pParent, u"svx/ui/tableautofmtdlg.ui"_ustr,
+                                    u"AutoFormatTableDialog"_ustr)
+    , maStrTitle(SvxResId(RID_SVXSTR_ADD_AUTOFORMAT_TITLE))
+    , maStrLabel(SvxResId(RID_SVXSTR_ADD_AUTOFORMAT_LABEL))
+    , maStrClose(SvxResId(RID_SVXSTR_BTN_AUTOFORMAT_CLOSE))
+    , maStrDelMsg(SvxResId(RID_SVXSTR_DEL_AUTOFORMAT_MSG))
+    , maStrDelTitle(SvxResId(RID_SVXSTR_DEL_AUTOFORMAT_TITLE))
+    , maStrRename(SvxResId(RID_SVXSTR_RENAME_AUTOFORMAT_TITLE))
+    , mpFormat(rFormat)
+    , maFormatName(sFormatName)
+    , mnIndex(0)
+    , mbWriter(bWriter)
+    , mbRTL(bRTL)
+    , maWndPreview(bRTL)
+    , mxLbFormat(m_xBuilder->weld_tree_view(u"formatlb"_ustr))
+    , mxBtnCancel(m_xBuilder->weld_button(u"cancel"_ustr))
+    , mxBtnAdd(m_xBuilder->weld_button(u"add"_ustr))
+    , mxBtnEdit(m_xBuilder->weld_button(u"edit"_ustr))
+    , mxBtnRemove(m_xBuilder->weld_button(u"remove"_ustr))
+    , mxBtnRename(m_xBuilder->weld_button(u"rename"_ustr))
+    , mxBtnNumFormat(m_xBuilder->weld_check_button(u"numformatcb"_ustr))
+    , mxBtnBorder(m_xBuilder->weld_check_button(u"bordercb"_ustr))
+    , mxBtnFont(m_xBuilder->weld_check_button(u"fontcb"_ustr))
+    , mxBtnPattern(m_xBuilder->weld_check_button(u"patterncb"_ustr))
+    , mxBtnAlignment(m_xBuilder->weld_check_button(u"alignmentcb"_ustr))
+    , mxBtnAdjust(m_xBuilder->weld_check_button(u"autofitcb"_ustr))
+    , mxWndPreview(new weld::CustomWeld(*m_xBuilder, u"preview"_ustr, 
maWndPreview))
+{
+    const int nWidth = mxLbFormat->get_approximate_digit_width() * 32;
+    const int nHeight = mxLbFormat->get_height_rows(8);
+    mxLbFormat->set_size_request(nWidth, nHeight);
+    mxWndPreview->set_size_request(nWidth, nHeight);
+
+    Init();
+}
+
+void SvxTableAutoFmtDlg::Init()
+{
+    Link<weld::Toggleable&, void> aLk(LINK(this, SvxTableAutoFmtDlg, 
CheckHdl));
+    mxLbFormat->connect_selection_changed(LINK(this, SvxTableAutoFmtDlg, 
SelFormatHdl));
+    mxBtnNumFormat->connect_toggled(aLk);
+    mxBtnBorder->connect_toggled(aLk);
+    mxBtnFont->connect_toggled(aLk);
+    mxBtnPattern->connect_toggled(aLk);
+    mxBtnAlignment->connect_toggled(aLk);
+
+    mxBtnAdd->connect_clicked(LINK(this, SvxTableAutoFmtDlg, AddHdl));
+    mxBtnEdit->connect_clicked(LINK(this, SvxTableAutoFmtDlg, EditHdl));
+    mxBtnRemove->connect_clicked(LINK(this, SvxTableAutoFmtDlg, RemoveHdl));
+    mxBtnRename->connect_clicked(LINK(this, SvxTableAutoFmtDlg, RenameHdl));
+
+    if (!mpFormat.size())
+    {
+        SAL_WARN("svx", "No 'Table Styles' in 'tablestyles.xml'");
+        return;
+    }
+
+    mnIndex = DEFAULT_STYLE;
+    PopulateFormatList();
+    mxLbFormat->select(mnIndex);
+    SelFormatHdl(*mxLbFormat);
+
+    // Hide adjust button in Writer
+    if (mbWriter)
+    {
+        mxBtnAdjust->set_visible(false);
+    }
+
+    UpdateUIState();
+    UpdateChecks();
+}
+
+void SvxTableAutoFmtDlg::PopulateFormatList()
+{
+    mxLbFormat->freeze();
+    mxLbFormat->clear();
+
+    for (size_t i = 0; i < mpFormat.size(); ++i)
+    {
+        if (const SvxAutoFormatData* rFormat = mpFormat.GetData(i))
+        {
+            if (rFormat->GetName() == maFormatName)
+                mnIndex = i;
+            mxLbFormat->append_text(rFormat->GetName());
+        }
+    }
+
+    mxLbFormat->thaw();
+}
+
+void SvxTableAutoFmtDlg::UpdateUIState()
+{
+    const bool bCanModify = mnIndex != DEFAULT_STYLE;
+    mxBtnRename->set_sensitive(bCanModify);
+    mxBtnRemove->set_sensitive(bCanModify);
+}
+
+void SvxTableAutoFmtDlg::UpdateChecks()
+{
+    if (const SvxAutoFormatData* pData = mpFormat.GetData(mnIndex))
+    {
+        mxBtnNumFormat->set_active(pData->IsValueFormat());
+        mxBtnBorder->set_active(pData->IsFrame());
+        mxBtnFont->set_active(pData->IsFont());
+        mxBtnPattern->set_active(pData->IsBackground());
+        mxBtnAlignment->set_active(pData->IsJustify());
+        mxBtnAdjust->set_active(pData->IsWidthHeight());
+    }
+}
+
+OUString SvxTableAutoFmtDlg::GenerateUniqueStyleName()
+{
+    OUString sBase = "Untitled";
+    OUString sName = sBase + "1";
+    int nCounter = 1;
+
+    while (mpFormat.FindAutoFormat(sName))
+    {
+        nCounter++;
+        sName = sBase + OUString::number(nCounter);
+    }
+    return sName;
+}
+
+// Event Handlers
+IMPL_LINK(SvxTableAutoFmtDlg, CheckHdl, weld::Toggleable&, rBtn, void)
+{
+    SvxAutoFormatData* rData = mpFormat.GetData(mnIndex);
+    if (!rData)
+        return;
+
+    const bool bCheck = rBtn.get_active();
+
+    if (&rBtn == mxBtnNumFormat.get())
+        rData->SetValueFormat(bCheck);
+    else if (&rBtn == mxBtnBorder.get())
+        rData->SetFrame(bCheck);
+    else if (&rBtn == mxBtnFont.get())
+        rData->SetFont(bCheck);
+    else if (&rBtn == mxBtnPattern.get())
+        rData->SetBackground(bCheck);
+    else if (&rBtn == mxBtnAlignment.get())
+        rData->SetJustify(bCheck);
+    else
+        rData->SetWidthHeight(bCheck);
+
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(rData));
+}
+
+IMPL_LINK_NOARG(SvxTableAutoFmtDlg, RemoveHdl, weld::Button&, void)
+{
+    OUString aMessage = maStrDelMsg + "
'" + mxLbFormat->get_selected_text() + "'
";
+
+    std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
+        m_xDialog.get(), VclMessageType::Question, VclButtonsType::OkCancel, 
maStrDelTitle));
+    xBox->set_secondary_text(aMessage);
+
+    if (xBox->run() == RET_OK)
+    {
+        mpFormat.ReleaseAutoFormat(mxLbFormat->get_selected_text());
+        mxLbFormat->remove(mnIndex--);
+        UpdateUIState();
+        SelFormatHdl(*mxLbFormat);
+    }
+}
+
+IMPL_LINK_NOARG(SvxTableAutoFmtDlg, RenameHdl, weld::Button&, void)
+{
+    bool bOk = false;
+    while (!bOk)
+    {
+        SvxStringInputDlg aDlg(m_xDialog.get(), maStrRename, maStrLabel,
+                               mxLbFormat->get_selected_text());
+        if (aDlg.run() == RET_OK)
+        {
+            const OUString aFormatName(aDlg.GetInputString().trim());
+
+            // Check for empty string and duplicate names
+            if (aFormatName.isEmpty() || aFormatName.indexOf(".") != -1
+                || aFormatName.indexOf("-") != -1 || 
mpFormat.FindAutoFormat(aFormatName))
+            {
+                std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(
+                    m_xDialog.get(), VclMessageType::Error, VclButtonsType::Ok,
+                    SvxResId(RID_SVXSTR_INVALID_AUTOFORMAT_NAME)));
+                xBox->run();
+                continue;
+            }
+
+            // Perform rename
+            if (SvxAutoFormatData* pData = 
mpFormat.FindAutoFormat(mxLbFormat->get_selected_text()))
+            {
+                pData->SetName(aFormatName);
+                mxLbFormat->set_text(mnIndex, aFormatName);
+                mxLbFormat->select(mnIndex);
+            }
+
+            bOk = true;
+        }
+        else
+        {
+            bOk = true;
+        }
+    }
+}
+
+IMPL_LINK_NOARG(SvxTableAutoFmtDlg, SelFormatHdl, weld::TreeView&, void)
+{
+    mnIndex = mxLbFormat->get_selected_index();
+    UpdateChecks();
+    UpdateUIState();
+
+    if (const SvxAutoFormatData* pData = mpFormat.GetData(mnIndex))
+        maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(pData));
+}
+
+OUString SvxTableAutoFmtDlg::GetCurrFormatName()
+{
+    const SvxAutoFormatData* pData = mpFormat.GetData(mnIndex);
+    return pData ? pData->GetName() : OUString();
+}
+
+IMPL_LINK_NOARG(SvxTableAutoFmtDlg, AddHdl, weld::Button&, void)
+{
+    SvxAutoFormatData* pNewData = mpFormat.GetDefaultData();
+    pNewData->SetName(GenerateUniqueStyleName());
+    pNewData->SetParent(mxLbFormat->get_selected_text());
+
+    bool bNewStyle = true;
+    SvxTableStylesDlg aDlg(m_xDialog.get(), bNewStyle, mpFormat, *pNewData, 
mbRTL);
+
+    aDlg.getDialog()->set_modal(true);
+    if (aDlg.run() == RET_OK)
+    {
+        mpFormat.InsertAutoFormat(pNewData);
+        mxLbFormat->append_text(pNewData->GetName());
+        mxLbFormat->select_text(pNewData->GetName());
+        SelFormatHdl(*mxLbFormat);
+    }
+    aDlg.getDialog()->set_modal(false);
+
+    if (!mbWriter)
+        mpFormat.Save();
+}
+
+IMPL_LINK_NOARG(SvxTableAutoFmtDlg, EditHdl, weld::Button&, void)
+{
+    bool bNewStyle = false;
+    OUString sOldName = mpFormat.GetData(mnIndex)->GetName();
+    SvxTableStylesDlg aDlg(m_xDialog.get(), bNewStyle, mpFormat, 
*mpFormat.GetData(mnIndex), mbRTL);
+
+    aDlg.getDialog()->set_modal(true);
+    if (aDlg.run() == RET_OK)
+    {
+        // If name of the format is changed then update the parent-style of 
formats which inherit this style
+        OUString sNewName = mpFormat.GetData(mnIndex)->GetName();
+        if (sOldName != sNewName)
+        {
+            for (size_t i = 0; i < mpFormat.size(); i++)
+            {
+                if (mpFormat.GetData(i)->GetParent() == sOldName)
+                    mpFormat.GetData(i)->SetParent(sNewName);
+            }
+        }
+
+        mxLbFormat->set_text(mnIndex, mpFormat.GetData(mnIndex)->GetName());
+        SelFormatHdl(*mxLbFormat);
+
+        // For Writer this will reapply the styles to the tables
+        if (mbWriter)
+        {
+            css::uno::Sequence<css::beans::PropertyValue> aArgs
+                = { comphelper::makePropertyValue(u"aFormatName"_ustr, 
sNewName),
+                    comphelper::makePropertyValue(u"aOldName"_ustr, sOldName) 
};
+            comphelper::dispatchCommand(u".uno:ResetAutoFormats"_ustr, aArgs);
+        }
+        else
+        {
+            mpFormat.Save();
+        }
+    }
+    aDlg.getDialog()->set_modal(false);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/dialog/TableStylesDlg.cxx 
b/svx/source/dialog/TableStylesDlg.cxx
new file mode 100644
index 000000000000..5232204f201f
--- /dev/null
+++ b/svx/source/dialog/TableStylesDlg.cxx
@@ -0,0 +1,850 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/*
+ This Dialog is part of GSoC 2025 "New Dialog to Edit Table Styles" project.
+ The Dialog is based on the design teams proposal
+ (https://design.blog.documentfoundation.org/2015/12/13/style-your-tables/)
+ */
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+#include <editeng/adjustitem.hxx>
+#include <vcl/svapp.hxx>
+#include <bitmaps.hlst>
+#include <editeng/editids.hrc>
+#include <editeng/flstitem.hxx>
+#include <sfx2/objsh.hxx>
+#include <svtools/ctrltool.hxx>
+#include <svx/dialmgr.hxx>
+#include <svx/strings.hrc>
+#include <svx/svxtableitems.hxx>
+#include <svx/dialog/TableStylesDlg.hxx>
+#include <tools/fldunit.hxx>
+#include <vcl/weld/Toolbar.hxx>
+
+static void lcl_GetDefaultFontHeight(OUString& sName, OUString& sSize)
+{
+    using namespace css;
+    SfxObjectShell* pDocSh = SfxObjectShell::Current();
+    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(pDocSh->GetModel(),
+                                                                         
uno::UNO_QUERY);
+
+    if (xStyleFamiliesSupplier.is())
+    {
+        uno::Reference<container::XNameAccess> xStyleFamilies
+            = xStyleFamiliesSupplier->getStyleFamilies();
+
+        // Use CellStyles for Calc and ParagraphStyles for Writer
+        if (xStyleFamilies->hasByName(u"CellStyles"_ustr))
+        {
+            uno::Reference<container::XNameAccess> xCellStyles;
+            xStyleFamilies->getByName(u"CellStyles"_ustr) >>= xCellStyles;
+
+            if (xCellStyles->hasByName(u"Text"_ustr))
+            {
+                uno::Reference<beans::XPropertySet> xProps;
+                xCellStyles->getByName(u"Text"_ustr) >>= xProps;
+
+                if (xProps.is())
+                {
+                    OUString sFontName;
+                    xProps->getPropertyValue(u"CharFontName"_ustr) >>= 
sFontName;
+                    if (!sFontName.isEmpty())
+                        sName = sFontName;
+
+                    float fSize = 0;
+                    xProps->getPropertyValue(u"CharHeight"_ustr) >>= fSize;
+                    if (fSize > 0)
+                        sSize = OUString::number(static_cast<int>(fSize)) + u" 
pt"_ustr;
+
+                    return;
+                }
+            }
+        }
+
+        if (xStyleFamilies->hasByName(u"ParagraphStyles"_ustr))
+        {
+            uno::Reference<container::XNameAccess> xParaStyles;
+            xStyleFamilies->getByName(u"ParagraphStyles"_ustr) >>= xParaStyles;
+
+            if (xParaStyles->hasByName(u"Table Contents"_ustr))
+            {
+                uno::Reference<beans::XPropertySet> xProps;
+                xParaStyles->getByName(u"Table Contents"_ustr) >>= xProps;
+
+                if (xProps.is())
+                {
+                    OUString sFontName;
+                    xProps->getPropertyValue(u"CharFontName"_ustr) >>= 
sFontName;
+                    if (!sFontName.isEmpty())
+                        sName = sFontName;
+
+                    float fSize = 0;
+                    xProps->getPropertyValue(u"CharHeight"_ustr) >>= fSize;
+                    if (fSize > 0)
+                        sSize = OUString::number(static_cast<int>(fSize)) + u" 
pt"_ustr;
+
+                    return;
+                }
+            }
+        }
+    }
+}
+
+SvxTableStylesDlg::~SvxTableStylesDlg() = default;
+
+SvxTableStylesDlg::SvxTableStylesDlg(weld::Window* pParent, bool bNewStyle, 
SvxAutoFormat& pFormat,
+                                     SvxAutoFormatData& pData, bool bRTL)
+    : weld::GenericDialogController(pParent, u"svx/ui/tablestylesdlg.ui"_ustr,
+                                    u"TableStylesDialog"_ustr)
+    , maWndPreview(bRTL)
+    , mpFormat(pFormat)
+    , mpOriginalData(pData)
+    , mpData(*pData.MakeCopy())
+    , msParentName(pData.GetParent())
+    , mbNewStyle(bNewStyle)
+    , mpTextStyle(m_xBuilder->weld_toolbar(u"charstyletb"_ustr))
+    , mpNumberFormat(m_xBuilder->weld_toolbar(u"numbertb"_ustr))
+    , mpHorAlign(m_xBuilder->weld_toolbar(u"charhoritb"_ustr))
+    , mpVerAlign(m_xBuilder->weld_toolbar(u"charverttb"_ustr))
+    , 
m_xCellPadding(m_xBuilder->weld_metric_spin_button(u"cellpaddingsb"_ustr, 
FieldUnit::INCH))
+    , m_xLinkedWith(m_xBuilder->weld_combo_box(u"linkedwithbox"_ustr))
+    , m_xBorderWidth(m_xBuilder->weld_combo_box(u"borderwidth"_ustr))
+    , m_xNumberFormat(m_xBuilder->weld_container(u"number"_ustr))
+    , m_xTextFont(m_xBuilder->weld_combo_box(u"charnamebox"_ustr))
+    , m_xTextSize(new 
FontSizeBox(m_xBuilder->weld_combo_box(u"charsizebox"_ustr)))
+    , m_xCellColor(new 
ColorListBox(m_xBuilder->weld_menu_button(u"cellcolormb"_ustr),
+                                    [this] { return m_xDialog.get(); }))
+    , m_xBorderColor(new 
ColorListBox(m_xBuilder->weld_menu_button(u"bordercolormb"_ustr),
+                                      [this] { return m_xDialog.get(); }))
+    , m_xTextColor(new 
ColorListBox(m_xBuilder->weld_menu_button(u"charcolormb"_ustr),
+                                    [this] { return m_xDialog.get(); }))
+    , m_xBorderStyle(new 
SvtLineListBox(m_xBuilder->weld_menu_button(u"borderstylemb"_ustr)))
+    , m_xBorderSelector(new ValueSet(nullptr))
+    , m_xBorderSelectorWin(new weld::CustomWeld(*m_xBuilder, u"borders"_ustr, 
*m_xBorderSelector))
+    , mxWndPreview(new weld::CustomWeld(*m_xBuilder, u"previewarea"_ustr, 
maWndPreview))
+    , m_xElementBox(m_xBuilder->weld_combo_box(u"elementbox"_ustr))
+    , m_xNameEntry(m_xBuilder->weld_entry(u"basicnameentry"_ustr))
+    , m_xOkayBtn(m_xBuilder->weld_button(u"ok"_ustr))
+    , m_xResetBtn(m_xBuilder->weld_button(u"reset"_ustr))
+    , m_xCancelBtn(m_xBuilder->weld_button(u"cancel"_ustr))
+
+{
+    m_xNameEntry->set_text(mpData.GetName());
+    if (mpData.GetName() == "Default Style")
+    {
+        m_xNameEntry->set_sensitive(false);
+        m_xLinkedWith->set_sensitive(false);
+    }
+
+    SfxObjectShell* pDocSh = SfxObjectShell::Current();
+    const SfxPoolItem* pFontItem;
+    const FontList* pFontList = nullptr;
+
+    pFontItem = pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST);
+    pFontList = static_cast<const SvxFontListItem*>(pFontItem)->GetFontList();
+
+    m_xTextFont->freeze();
+    sal_uInt16 nFontCount = pFontList->GetFontNameCount();
+    for (sal_uInt16 i = 0; i < nFontCount; ++i)
+    {
+        const FontMetric& rFontMetric = pFontList->GetFontName(i);
+        m_xTextFont->append_text(rFontMetric.GetFamilyName());
+    }
+    m_xTextFont->thaw();
+
+    OUString sFontName = "Liberation Sans", sFontSize = "12 pt";
+    lcl_GetDefaultFontHeight(sFontName, sFontSize);
+    m_xTextFont->set_active(m_xTextFont->find_text(sFontName));
+    m_xTextSize->Fill(pFontList);
+    m_xTextSize->set_active_or_entry_text(sFontSize);
+
+    {
+        m_xLinkedWith->freeze();
+        OUString sFormatName = mpData.GetName();
+        for (size_t i = 0; i < mpFormat.size(); i++)
+        {
+            OUString sName = mpFormat.GetData(i)->GetName();
+            OUString sParent = mpFormat.GetData(i)->GetParent();
+            if (!sFormatName.equals(sName) && !sFormatName.equals(sParent))
+                m_xLinkedWith->append_text(sName);
+        }
+        m_xLinkedWith->thaw();
+        m_xLinkedWith->set_active_text(mpData.GetParent());
+    }
+
+    m_xNameEntry->select_region(0, -1);
+    m_xElementBox->set_active(0);
+    m_xNumberFormat->set_visible(false);
+
+    m_xBorderColor->SelectEntry(COL_BLACK);
+    m_xCellColor->SelectEntry(COL_BLACK);
+    m_xTextColor->SelectEntry(COL_BLACK);
+
+    mxWndPreview->set_size_request(300, 200);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+
+    InitLineStyles();
+    InitBorderSelector();
+
+    m_xElementBox->connect_changed(LINK(this, SvxTableStylesDlg, 
ElementSelHdl));
+    m_xLinkedWith->connect_changed(LINK(this, SvxTableStylesDlg, 
LinkedWithSelHdl));
+    m_xTextFont->connect_changed(LINK(this, SvxTableStylesDlg, 
TextFontSelHdl));
+    m_xTextSize->connect_changed(LINK(this, SvxTableStylesDlg, 
TextSizeSelHdl));
+    m_xCellColor->SetSelectHdl(LINK(this, SvxTableStylesDlg, CellColorSelHdl));
+    m_xBorderColor->SetSelectHdl(LINK(this, SvxTableStylesDlg, 
BorderColorSelHdl));
+    m_xTextColor->SetSelectHdl(LINK(this, SvxTableStylesDlg, TextColorSelHdl));
+    mpTextStyle->connect_clicked(LINK(this, SvxTableStylesDlg, TextStyleHdl));
+    mpHorAlign->connect_clicked(LINK(this, SvxTableStylesDlg, HorAlignHdl));
+    mpVerAlign->connect_clicked(LINK(this, SvxTableStylesDlg, VerAlignHdl));
+    m_xBorderWidth->connect_changed(LINK(this, SvxTableStylesDlg, 
BorderWidthSelHdl));
+    m_xBorderStyle->SetSelectHdl(LINK(this, SvxTableStylesDlg, 
BorderStyleHdl));
+    m_xCellPadding->connect_value_changed(LINK(this, SvxTableStylesDlg, 
PaddingHdl));
+    m_xOkayBtn->connect_clicked(LINK(this, SvxTableStylesDlg, OkayHdl));
+    m_xResetBtn->connect_clicked(LINK(this, SvxTableStylesDlg, ResetHdl));
+    m_xCancelBtn->connect_clicked(LINK(this, SvxTableStylesDlg, CancelHdl));
+
+    ElementSelHdl(*m_xElementBox);
+}
+
+void SvxTableStylesDlg::InitLineStyles()
+{
+    using namespace ::com::sun::star::table::BorderLineStyle;
+
+    static struct
+    {
+        SvxBorderLineStyle mnStyle;
+        SvtLineListBox::ColorFunc mpColor1Fn;
+        SvtLineListBox::ColorFunc mpColor2Fn;
+        SvtLineListBox::ColorDistFunc mpColorDistFn;
+    } const aLines[]
+        = { // Simple lines
+            { SvxBorderLineStyle::SOLID, &sameColor, &sameColor, 
&sameDistColor },
+            { SvxBorderLineStyle::DOTTED, &sameColor, &sameColor, 
&sameDistColor },
+            { SvxBorderLineStyle::DASHED, &sameColor, &sameColor, 
&sameDistColor },
+            { SvxBorderLineStyle::FINE_DASHED, &sameColor, &sameColor, 
&sameDistColor },
+            { SvxBorderLineStyle::DASH_DOT, &sameColor, &sameColor, 
&sameDistColor },
+            { SvxBorderLineStyle::DASH_DOT_DOT, &sameColor, &sameColor, 
&sameDistColor },
+
+            // Double lines
+            { SvxBorderLineStyle::DOUBLE, &sameColor, &sameColor, 
&sameDistColor },
+            { SvxBorderLineStyle::DOUBLE_THIN, &sameColor, &sameColor, 
&sameDistColor },
+
+            { SvxBorderLineStyle::EMBOSSED, 
&editeng::SvxBorderLine::threeDLightColor,
+              &editeng::SvxBorderLine::threeDDarkColor, &sameDistColor },
+            { SvxBorderLineStyle::ENGRAVED, 
&editeng::SvxBorderLine::threeDDarkColor,
+              &editeng::SvxBorderLine::threeDLightColor, &sameDistColor },
+
+            { SvxBorderLineStyle::OUTSET, &editeng::SvxBorderLine::lightColor,
+              &editeng::SvxBorderLine::darkColor, &sameDistColor },
+            { SvxBorderLineStyle::INSET, &editeng::SvxBorderLine::darkColor,
+              &editeng::SvxBorderLine::lightColor, &sameDistColor }
+          };
+
+    m_xBorderStyle->SetSourceUnit(FieldUnit::TWIP);
+
+    for (size_t i = 0; i < std::size(aLines); ++i)
+    {
+        
m_xBorderStyle->InsertEntry(editeng::SvxBorderLine::getWidthImpl(aLines[i].mnStyle),
+                                    aLines[i].mnStyle, THIN, 
aLines[i].mpColor1Fn,
+                                    aLines[i].mpColor2Fn, 
aLines[i].mpColorDistFn);
+    }
+
+    m_xBorderStyle->SetWidth(THIN);
+    m_xBorderStyle->SelectEntry(SvxBorderLineStyle::SOLID);
+}
+
+void SvxTableStylesDlg::InitBorderSelector()
+{
+    m_xBorderSelector->SetStyle(m_xBorderSelector->GetStyle() | WB_ITEMBORDER 
| WB_DOUBLEBORDER);
+    m_xBorderSelector->SetColCount(4);
+    m_xBorderSelector->SetLineCount(2);
+
+    struct
+    {
+        OUString IconId;
+        TranslateId LabelId;
+    } const aBorderStyles[] = { { RID_SVXBMP_FRAME1, 
RID_SVXSTR_TABLE_PRESET_NONE },
+                                { RID_SVXBMP_FRAME2, 
RID_SVXSTR_PARA_PRESET_ONLYLEFT },
+                                { RID_SVXBMP_FRAME3, 
RID_SVXSTR_PARA_PRESET_ONLYRIGHT },
+                                { RID_SVXBMP_FRAME4, 
RID_SVXSTR_PARA_PRESET_LEFTRIGHT },
+                                { RID_SVXBMP_FRAME5, 
RID_SVXSTR_PARA_PRESET_ONLYTOP },
+                                { RID_SVXBMP_FRAME6, 
RID_SVXSTR_PARA_PRESET_ONLYBOTTOM },
+                                { RID_SVXBMP_FRAME7, 
RID_SVXSTR_PARA_PRESET_TOPBOTTOM },
+                                { RID_SVXBMP_FRAME8, 
RID_SVXSTR_TABLE_PRESET_OUTER } };
+
+    for (size_t i = 0; i < std::size(aBorderStyles); i++)
+    {
+        m_xBorderSelector->InsertItem(i + 1);
+        m_xBorderSelector->SetItemImage(i + 1, Image(StockImage::Yes, 
aBorderStyles[i].IconId));
+        m_xBorderSelector->SetItemText(i + 1, 
SvxResId(aBorderStyles[i].LabelId));
+    }
+
+    m_xBorderSelector->SetNoSelection();
+    m_xBorderSelector->SetOptimalSize();
+    m_xBorderSelector->Show();
+
+    m_xBorderSelector->SetSelectHdl(LINK(this, SvxTableStylesDlg, 
BorderLayoutSelHdl));
+}
+
+SvxBoxItem SvxTableStylesDlg::GetValidBox()
+{
+    SvxBoxItem aBox = 
mpFormat.GetResolvedStyle(&mpData)->GetField(mnField)->GetBox(),
+               aCurrBox = mpCurrField->GetBox();
+
+    if (aCurrBox.GetTop() || aCurrBox.GetRight() || aCurrBox.GetBottom() || 
aCurrBox.GetLeft())
+        return aCurrBox;
+    else
+        return aBox;
+}
+
+OUString SvxTableStylesDlg::GetValidFont(size_t nField)
+{
+    OUString sFont = mpData.GetField(nField)->GetFont().GetFamilyName();
+    if (!sFont.isEmpty())
+        return sFont;
+
+    switch (nField)
+    {
+        case FIRST_ROW:
+            return GetValidFont(ODD_ROW);
+        case FIRST_COL:
+            return GetValidFont(ODD_COL);
+        case LAST_ROW:
+        case LAST_COL:
+        case EVEN_ROW:
+        case EVEN_COL:
+        case ODD_ROW:
+        case ODD_COL:
+            return GetValidFont(BODY);
+        case FIRST_ROW_START_COL:
+        case FIRST_ROW_END_COL:
+        case FIRST_ROW_EVEN_COL:
+            return GetValidFont(FIRST_ROW);
+        case LAST_ROW_START_COL:
+        case LAST_ROW_END_COL:
+        case LAST_ROW_EVEN_COL:
+            return GetValidFont(LAST_ROW);
+        case BODY:
+            return GetValidFont(BACKGROUND);
+        default:
+            return "";
+    }
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, ElementSelHdl, weld::ComboBox&, void)
+{
+    mnField = m_xElementBox->get_active();
+    mpCurrField = mpData.GetField(mnField);
+    SvxAutoFormatDataField aField = 
*mpFormat.GetResolvedStyle(&mpData)->GetField(mnField);
+    m_xCellColor->SelectEntry(aField.GetBackground().GetColor());
+
+    tools::Long nWidth = THIN;
+    editeng::SvxBorderLine* aBorder = nullptr;
+    SvxBoxItem aBox = aField.GetBox();
+    if (aBox.GetLeft() && aBox.GetRight() && aBox.GetTop() && aBox.GetBottom())
+    {
+        m_xBorderSelector->SelectItem(TABLE_ALL_BORDERS);
+        aBorder = aBox.GetLeft();
+    }
+    else if (aBox.GetTop() && aBox.GetBottom())
+    {
+        m_xBorderSelector->SelectItem(TABLE_TOP_BOTTOM_BORDERS);
+        aBorder = aBox.GetTop();
+    }
+    else if (aBox.GetLeft() && aBox.GetRight())
+    {
+        m_xBorderSelector->SelectItem(TABLE_LEFT_RIGHT_BORDERS);
+        aBorder = aBox.GetLeft();
+    }
+    else if (aBox.GetLeft())
+    {
+        m_xBorderSelector->SelectItem(TABLE_LEFT_BORDER);
+        aBorder = aBox.GetLeft();
+    }
+    else if (aBox.GetRight())
+    {
+        m_xBorderSelector->SelectItem(TABLE_RIGHT_BORDER);
+        aBorder = aBox.GetRight();
+    }
+    else if (aBox.GetTop())
+    {
+        m_xBorderSelector->SelectItem(TABLE_TOP_BORDER);
+        aBorder = aBox.GetTop();
+    }
+    else if (aBox.GetBottom())
+    {
+        m_xBorderSelector->SelectItem(TABLE_BOTTOM_BORDER);
+        aBorder = aBox.GetBottom();
+    }
+    else
+        m_xBorderSelector->SelectItem(TABLE_NO_BORDERS);
+
+    if (aBorder)
+    {
+        m_xBorderColor->SelectEntry(aBorder->GetColor());
+        nWidth = aBorder->GetWidth();
+        m_xBorderStyle->SelectEntry(aBorder->GetBorderLineStyle());
+        m_xBorderStyle->SetWidth(nWidth);
+    }
+
+    if (aBox.GetTop())
+        m_xBorderColor->SelectEntry(aBox.GetTop()->GetColor());
+    else if (aBox.GetRight())
+        m_xBorderColor->SelectEntry(aBox.GetRight()->GetColor());
+    else if (aBox.GetBottom())
+        m_xBorderColor->SelectEntry(aBox.GetBottom()->GetColor());
+    else if (aBox.GetLeft())
+        m_xBorderColor->SelectEntry(aBox.GetLeft()->GetColor());
+    else
+        m_xBorderColor->SelectEntry(COL_TRANSPARENT);
+
+    OUString sFont = GetValidFont(mnField);
+    if (!sFont.isEmpty())
+        m_xTextFont->set_active_text(sFont);
+
+    m_xTextColor->SelectEntry(aField.GetColor().getColor());
+    
m_xCellPadding->set_value(m_xCellPadding->normalize(aBox.GetSmallestDistance()),
+                              FieldUnit::TWIP);
+
+    mpTextStyle->set_item_active("bold", aField.GetWeight().GetWeight() == 
WEIGHT_BOLD);
+    mpTextStyle->set_item_active("italic", aField.GetPosture().GetPosture() == 
ITALIC_NORMAL);
+    mpTextStyle->set_item_active("underline",
+                                 aField.GetUnderline().GetLineStyle() == 
LINESTYLE_SINGLE);
+
+    mpHorAlign->set_item_active("rightalign", false);
+    mpHorAlign->set_item_active("centeralign", false);
+    mpHorAlign->set_item_active("leftalign", false);
+    switch (aField.GetHorJustify().GetValue())
+    {
+        case SvxCellHorJustify::Right:
+            mpHorAlign->set_item_active("rightalign", true);
+            break;
+        case SvxCellHorJustify::Center:
+            mpHorAlign->set_item_active("centeralign", true);
+            break;
+        default:
+            mpHorAlign->set_item_active("leftalign", true);
+            break;
+    }
+
+    mpVerAlign->set_item_active("bottomalign", false);
+    mpVerAlign->set_item_active("vertcenteralign", false);
+    mpVerAlign->set_item_active("topalign", false);
+    switch (aField.GetVerJustify().GetValue())
+    {
+        case SvxCellVerJustify::Bottom:
+            mpVerAlign->set_item_active("bottomalign", true);
+            break;
+        case SvxCellVerJustify::Center:
+            mpVerAlign->set_item_active("vertcenteralign", true);
+            break;
+        default:
+            mpVerAlign->set_item_active("topalign", true);
+            break;
+    }
+
+    switch (nWidth)
+    {
+        case HAIRLINE:
+            m_xBorderWidth->set_active(0);
+            break;
+        case VERY_THIN:
+            m_xBorderWidth->set_active(1);
+            break;
+        case THIN:
+            m_xBorderWidth->set_active(2);
+            break;
+        case THICK:
+            m_xBorderWidth->set_active(4);
+            break;
+        case EXTRA_THICK:
+            m_xBorderWidth->set_active(5);
+            break;
+        default:
+            m_xBorderWidth->set_active(3);
+            break;
+    }
+
+    if (mpCurrField->IsPropertySet(PROP_FONT))
+        m_xTextFont->set_active_text(mpCurrField->GetFont().GetFamilyName());
+    if (mpCurrField->IsPropertySet(PROP_HEIGHT))
+    {
+        // Convert twips to point
+        OUString sSize = OUString::number(mpCurrField->GetHeight().GetHeight() 
/ 20);
+        m_xTextSize->set_active_or_entry_text(sSize + " pt");
+    }
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, LinkedWithSelHdl, weld::ComboBox&, void)
+{
+    mpData.SetParent(m_xLinkedWith->get_active_text());
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+    ElementSelHdl(*m_xElementBox);
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, CellColorSelHdl, ColorListBox&, void)
+{
+    Color aSel = m_xCellColor->GetSelectEntryColor();
+    SvxBrushItem aBrushItem = mpCurrField->GetBackground();
+    aBrushItem.SetColor(aSel);
+    mpCurrField->SetBackground(aBrushItem);
+    mpCurrField->SetPropertyFlag(PROP_BACKGROUND);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, BorderColorSelHdl, ColorListBox&, void)
+{
+    Color aSel = m_xBorderColor->GetSelectEntryColor();
+
+    SvxBoxItem aBox = GetValidBox();
+    if (aBox.GetTop())
+        aBox.GetTop()->SetColor(aSel);
+    if (aBox.GetBottom())
+        aBox.GetBottom()->SetColor(aSel);
+    if (aBox.GetLeft())
+        aBox.GetLeft()->SetColor(aSel);
+    if (aBox.GetRight())
+        aBox.GetRight()->SetColor(aSel);
+
+    mpCurrField->SetBox(aBox);
+    mpCurrField->SetPropertyFlag(PROP_BOX);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, TextColorSelHdl, ColorListBox&, void)
+{
+    Color aSel = m_xTextColor->GetSelectEntryColor();
+
+    SvxColorItem aColorItem(aSel, SVX_TABLE_FONT_COLOR);
+    mpCurrField->SetColor(aColorItem);
+    mpCurrField->SetPropertyFlag(PROP_COLOR);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK(SvxTableStylesDlg, TextStyleHdl, const OUString&, rStyle, void)
+{
+    bool bActive = mpTextStyle->get_item_active(rStyle);
+
+    if (rStyle == "bold")
+    {
+        SvxWeightItem aNew(bActive ? WEIGHT_BOLD : WEIGHT_NORMAL, 
SVX_TABLE_FONT_WEIGHT);
+        mpCurrField->SetWeight(aNew);
+        mpCurrField->SetPropertyFlag(PROP_WEIGHT);
+    }
+    if (rStyle == "italic")
+    {
+        SvxPostureItem aNew(bActive ? ITALIC_NORMAL : ITALIC_NONE, 
SVX_TABLE_FONT_POSTURE);
+        mpCurrField->SetPosture(aNew);
+        mpCurrField->SetPropertyFlag(PROP_POSTURE);
+    }
+    if (rStyle == "underline")
+    {
+        SvxUnderlineItem aNew(bActive ? LINESTYLE_SINGLE : LINESTYLE_NONE,
+                              SVX_TABLE_FONT_UNDERLINE);
+        mpCurrField->SetUnderline(aNew);
+        mpCurrField->SetPropertyFlag(PROP_UNDERLINE);
+    }
+
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK(SvxTableStylesDlg, HorAlignHdl, const OUString&, rAlign, void)
+{
+    mpHorAlign->set_item_active("rightalign", false);
+    mpHorAlign->set_item_active("centeralign", false);
+    mpHorAlign->set_item_active("leftalign", false);
+
+    SvxHorJustifyItem aNew(mpCurrField->GetHorJustify());
+    SvxAdjustItem aAdjust(mpCurrField->GetAdjust());
+    if (rAlign == "centeralign")
+    {
+        aNew.SetValue(SvxCellHorJustify::Center);
+        aAdjust.SetAdjust(SvxAdjust::Center);
+        mpHorAlign->set_item_active("centeralign", true);
+    }
+    else if (rAlign == "rightalign")
+    {
+        aNew.SetValue(SvxCellHorJustify::Right);
+        aAdjust.SetAdjust(SvxAdjust::Right);
+        mpHorAlign->set_item_active("rightalign", true);
+    }
+    else
+    {
+        aNew.SetValue(SvxCellHorJustify::Left);
+        aAdjust.SetAdjust(SvxAdjust::Left);
+        mpHorAlign->set_item_active("leftalign", true);
+    }
+
+    mpCurrField->SetHorJustify(aNew);
+    mpCurrField->SetAdjust(aAdjust);
+    mpCurrField->SetPropertyFlag(PROP_HOR_JUSTIFY);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK(SvxTableStylesDlg, VerAlignHdl, const OUString&, rAlign, void)
+{
+    mpVerAlign->set_item_active("bottomalign", false);
+    mpVerAlign->set_item_active("vertcenteralign", false);
+    mpVerAlign->set_item_active("topalign", false);
+
+    SvxVerJustifyItem aNew(mpCurrField->GetVerJustify());
+    if (rAlign == "bottomalign")
+    {
+        aNew.SetValue(SvxCellVerJustify::Bottom);
+        mpVerAlign->set_item_active("bottomalign", true);
+    }
+    else if (rAlign == "vertcenteralign")
+    {
+        aNew.SetValue(SvxCellVerJustify::Center);
+        mpVerAlign->set_item_active("vertcenteralign", true);
+    }
+    else
+    {
+        aNew.SetValue(SvxCellVerJustify::Top);
+        mpVerAlign->set_item_active("topalign", true);
+    }
+
+    mpCurrField->SetVerJustify(aNew);
+    mpCurrField->SetPropertyFlag(PROP_VER_JUSTIFY);
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, BorderLayoutSelHdl, ValueSet*, void)
+{
+    sal_uInt16 nSelected = m_xBorderSelector->GetSelectedItemId();
+    SvxBoxItem aBox = GetValidBox();
+    editeng::SvxBorderLine aBorder;
+    if (aBox.GetTop())
+    {
+        aBorder = *aBox.GetTop();
+    }
+    else if (aBox.GetRight())
+    {
+        aBorder = *aBox.GetRight();
+    }
+    else if (aBox.GetBottom())
+    {
+        aBorder = *aBox.GetBottom();
+    }
+    else if (aBox.GetLeft())
+    {
+        aBorder = *aBox.GetLeft();
+    }
+    else
+    {
+        Color aCol = m_xBorderColor->GetSelectEntryColor();
+        if (aCol.IsTransparent())
+            aCol = COL_BLACK;
+        aBorder = *new editeng::SvxBorderLine(&aCol, THIN);
+    }
+
+    aBox.SetLine(nullptr, SvxBoxItemLine::TOP);
+    aBox.SetLine(nullptr, SvxBoxItemLine::RIGHT);
+    aBox.SetLine(nullptr, SvxBoxItemLine::BOTTOM);
+    aBox.SetLine(nullptr, SvxBoxItemLine::LEFT);
+
+    switch (nSelected)
+    {
+        case TABLE_NO_BORDERS:
+            break;
+        case TABLE_LEFT_BORDER:
+            aBox.SetLine(&aBorder, SvxBoxItemLine::LEFT);
+            break;
+        case TABLE_RIGHT_BORDER:
+            aBox.SetLine(&aBorder, SvxBoxItemLine::RIGHT);
+            break;
+        case TABLE_LEFT_RIGHT_BORDERS:
+            aBox.SetLine(&aBorder, SvxBoxItemLine::LEFT);
+            aBox.SetLine(&aBorder, SvxBoxItemLine::RIGHT);
+            break;
+        case TABLE_TOP_BORDER:
+            aBox.SetLine(&aBorder, SvxBoxItemLine::TOP);
+            break;
+        case TABLE_BOTTOM_BORDER:
+            aBox.SetLine(&aBorder, SvxBoxItemLine::BOTTOM);
+            break;
+        case TABLE_TOP_BOTTOM_BORDERS:
+            aBox.SetLine(&aBorder, SvxBoxItemLine::TOP);
+            aBox.SetLine(&aBorder, SvxBoxItemLine::BOTTOM);
+            break;
+        case TABLE_ALL_BORDERS:
+            aBox.SetLine(&aBorder, SvxBoxItemLine::TOP);
+            aBox.SetLine(&aBorder, SvxBoxItemLine::RIGHT);
+            aBox.SetLine(&aBorder, SvxBoxItemLine::BOTTOM);
+            aBox.SetLine(&aBorder, SvxBoxItemLine::LEFT);
+            break;
+    }
+
+    mpCurrField->SetBox(aBox);
+    m_xBorderColor->SelectEntry(aBorder.GetColor());
+    mpCurrField->SetPropertyFlag(PROP_BOX);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+void SvxTableStylesDlg::UpdateWidth(tools::Long nWidth)
+{
+    SvxBoxItem aBox = GetValidBox();
+    if (aBox.GetTop())
+        aBox.GetTop()->SetWidth(nWidth);
+    if (aBox.GetBottom())
+        aBox.GetBottom()->SetWidth(nWidth);
+    if (aBox.GetLeft())
+        aBox.GetLeft()->SetWidth(nWidth);
+    if (aBox.GetRight())
+        aBox.GetRight()->SetWidth(nWidth);
+
+    SvxAutoFormatDataField* pCurrField = mpData.GetField(mnField);
+    pCurrField->SetBox(aBox);
+    pCurrField->SetPropertyFlag(PROP_BOX);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, BorderWidthSelHdl, weld::ComboBox&, void)
+{
+    switch (m_xBorderWidth->get_active())
+    {
+        case 0:
+            UpdateWidth(HAIRLINE);
+            break;
+        case 1:
+            UpdateWidth(VERY_THIN);
+            break;
+        case 2:
+            UpdateWidth(THIN);
+            break;
+        case 4:
+            UpdateWidth(THICK);
+            break;
+        case 5:
+            UpdateWidth(EXTRA_THICK);
+            break;
+        default:
+            UpdateWidth(MEDIUM);
+            break;
+    }
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, BorderStyleHdl, SvtLineListBox&, void)
+{
+    SvxBoxItem aBox = GetValidBox();
+    auto aBorderStyle = m_xBorderStyle->GetSelectEntryStyle();
+
+    if (aBox.GetTop())
+        aBox.GetTop()->SetBorderLineStyle(aBorderStyle);
+    if (aBox.GetBottom())
+        aBox.GetBottom()->SetBorderLineStyle(aBorderStyle);
+    if (aBox.GetLeft())
+        aBox.GetLeft()->SetBorderLineStyle(aBorderStyle);
+    if (aBox.GetRight())
+        aBox.GetRight()->SetBorderLineStyle(aBorderStyle);
+
+    SvxAutoFormatDataField* pCurrField = mpData.GetField(mnField);
+    pCurrField->SetBox(aBox);
+    pCurrField->SetPropertyFlag(PROP_BOX);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK(SvxTableStylesDlg, PaddingHdl, weld::MetricSpinButton&, rField, void)
+{
+    SvxBoxItem aBox = GetValidBox();
+    
aBox.SetAllDistances(rField.denormalize(rField.get_value(FieldUnit::TWIP)));
+    mpCurrField->SetBox(aBox);
+    mpCurrField->SetPropertyFlag(PROP_PADDING);
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, TextFontSelHdl, weld::ComboBox&, void)
+{
+    SvxFontItem aFont = mpCurrField->GetFont();
+    aFont.SetFamilyName(m_xTextFont->get_active_text());
+    mpCurrField->SetFont(aFont);
+    mpCurrField->SetPropertyFlag(PROP_FONT);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, TextSizeSelHdl, weld::ComboBox&, void)
+{
+    SvxFontHeightItem aFontHeight = mpCurrField->GetHeight();
+
+    // Get the selected font size and convert to twips
+    OUString sSize = m_xTextSize->get_active_text();
+    if (sSize.endsWith(" pt"))
+        sSize = sSize.copy(0, sSize.getLength() - 3);
+
+    sal_uInt32 nSize = sSize.toInt32();
+    if (nSize > 0)
+    {
+        // Convert points to twips (1 pt = 20 twips)
+        sal_uInt32 nSizeTwips = nSize * 20;
+        aFontHeight.SetHeight(nSizeTwips);
+
+        mpCurrField->SetHeight(aFontHeight);
+        mpCurrField->SetPropertyFlag(PROP_HEIGHT);
+        maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+    }
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, OkayHdl, weld::Button&, void)
+{
+    OUString sName = m_xNameEntry->get_text();
+
+    // Check if style name has changed
+    if (sName != mpData.GetName()
+        && (sName.indexOf('.') != -1 || sName.indexOf("-") != -1 || 
mpFormat.FindAutoFormat(sName)))
+    {
+        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(
+            m_xDialog.get(), VclMessageType::Error, VclButtonsType::Ok,
+            SvxResId(RID_SVXSTR_INVALID_AUTOFORMAT_NAME)));
+        xBox->run();
+
+        m_xNameEntry->set_text(mpData.GetName());
+        m_xNameEntry->select_region(0, -1);
+    }
+    else
+    {
+        mpOriginalData.SetName(sName);
+        mpOriginalData.SetParent(mpData.GetParent());
+        mpOriginalData.ResetAutoFormat(mpData);
+        m_xDialog->response(RET_OK);
+    }
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, ResetHdl, weld::Button&, void)
+{
+    mpData.SetParent(msParentName);
+    m_xLinkedWith->set_active_text(msParentName);
+
+    if (mbNewStyle)
+        mpData.ResetAutoFormat(*mpFormat.GetData(0));
+    else
+        mpData.ResetAutoFormat(*mpFormat.FindAutoFormat(mpData.GetName()));
+
+    ElementSelHdl(*m_xElementBox);
+    maWndPreview.NotifyChange(mpFormat.GetResolvedStyle(&mpData));
+}
+
+IMPL_LINK_NOARG(SvxTableStylesDlg, CancelHdl, weld::Button&, void)
+{
+    if (!mbNewStyle)
+        mpData.ResetAutoFormat(*mpFormat.FindAutoFormat(mpData.GetName()));
+
+    m_xDialog->response(RET_CANCEL);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/table/tableautofmt.cxx 
b/svx/source/table/tableautofmt.cxx
new file mode 100644
index 000000000000..17934e9849fe
--- /dev/null
+++ b/svx/source/table/tableautofmt.cxx
@@ -0,0 +1,517 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/*
+There are two different Autoformat classes for Writer and Calc
+(SwTableAutoFormatTable & ScAutoFormat). This SvxAutoFormat unifies the
+common functionality of SwTableAutoFormatTable and ScAutoFormat
+*/
+
+#include <comphelper/processfactory.hxx>
+#include <sfx2/docfile.hxx>
+#include <unotools/streamwrap.hxx>
+#include <com/sun/star/awt/FontSlant.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <config_folders.h>
+#include <editeng/memberids.h>
+#include <rtl/bootstrap.hxx>
+#include <svl/intitem.hxx>
+#include <svx/rotmodit.hxx>
+#include <svx/svxtableitems.hxx>
+#include <com/sun/star/xml/sax/Writer.hpp>
+#include <editeng/adjustitem.hxx>
+#include <svx/TableAutoFmt.hxx>
+#include <editeng/justifyitem.hxx>
+#include <editeng/svxenum.hxx>
+#include <svl/typedwhich.hxx>
+#include <svx/TableStylesParser.hxx>
+
+using namespace com::sun::star::beans;
+using namespace com::sun::star;
+
+const SfxItemPropertySet& SvxAutoFormat::GetTablePropertySet()
+{
+    static const SfxItemPropertyMapEntry aSvxTablePropertyMap[] =
+
+        {
+            // SvxBrushItem
+            { u"BackColor"_ustr, SVX_TABLE_BACKGROUND, 
cppu::UnoType<sal_Int32>::get(),
+              PROPERTY_NONE, MID_BACK_COLOR },
+            // SvxBoxItem
+            { u"Border"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<css::table::BorderLine>::get(),
+              PROPERTY_NONE, LEFT_BORDER | CONVERT_TWIPS },
+            { u"LeftBorder"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<css::table::BorderLine>::get(),
+              PROPERTY_NONE, LEFT_BORDER | CONVERT_TWIPS },
+            { u"RightBorder"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<css::table::BorderLine>::get(),
+              PROPERTY_NONE, RIGHT_BORDER | CONVERT_TWIPS },
+            { u"TopBorder"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<css::table::BorderLine>::get(),
+              PROPERTY_NONE, TOP_BORDER | CONVERT_TWIPS },
+            { u"BottomBorder"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<css::table::BorderLine>::get(),
+              PROPERTY_NONE, BOTTOM_BORDER | CONVERT_TWIPS },
+            { u"BorderDistance"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<sal_Int32>::get(), PROPERTY_NONE,
+              BORDER_DISTANCE | CONVERT_TWIPS },
+            { u"LeftBorderDistance"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<sal_Int32>::get(),
+              PROPERTY_NONE, LEFT_BORDER_DISTANCE | CONVERT_TWIPS },
+            { u"RightBorderDistance"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<sal_Int32>::get(),
+              PROPERTY_NONE, RIGHT_BORDER_DISTANCE | CONVERT_TWIPS },
+            { u"TopBorderDistance"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<sal_Int32>::get(),
+              PROPERTY_NONE, TOP_BORDER_DISTANCE | CONVERT_TWIPS },
+            { u"BottomBorderDistance"_ustr, SVX_TABLE_BOX, 
cppu::UnoType<sal_Int32>::get(),
+              PROPERTY_NONE, BOTTOM_BORDER_DISTANCE | CONVERT_TWIPS },
+            // SvxFormatOrient
+            { u"VertOrient"_ustr, SVX_TABLE_VER_JUSTIFY, 
cppu::UnoType<sal_Int16>::get(),
+              PROPERTY_NONE, 0 },
+            // SvxColorItem
+            { u"CharColor"_ustr, SVX_TABLE_FONT_COLOR, 
cppu::UnoType<sal_Int32>::get(),
+              PROPERTY_NONE, 0 },
+            { u"CharUnderline"_ustr, SVX_TABLE_FONT_UNDERLINE, 
cppu::UnoType<sal_Int32>::get(),
+              PROPERTY_NONE, MID_TL_STYLE },
+            //Font
+            { u"CharHeight"_ustr, SVX_TABLE_FONT_HEIGHT, 
cppu::UnoType<float>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONTHEIGHT | CONVERT_TWIPS },
+            { u"CharWeight"_ustr, SVX_TABLE_FONT_WEIGHT, 
cppu::UnoType<float>::get(),
+              PropertyAttribute::MAYBEVOID, MID_WEIGHT },
+            { u"CharPosture"_ustr, SVX_TABLE_FONT_POSTURE,
+              cppu::UnoType<css::awt::FontSlant>::get(), 
PropertyAttribute::MAYBEVOID,
+              MID_POSTURE },
+            { u"CharFontName"_ustr, SVX_TABLE_FONT, 
cppu::UnoType<OUString>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY_NAME },
+            { u"CharFontStyleName"_ustr, SVX_TABLE_FONT, 
cppu::UnoType<OUString>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_STYLE_NAME },
+            { u"CharFontFamily"_ustr, SVX_TABLE_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY },
+            { u"CharFontCharSet"_ustr, SVX_TABLE_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_CHAR_SET },
+            { u"CharFontPitch"_ustr, SVX_TABLE_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_PITCH },
+            // CJK Font
+            { u"CharHeightAsian"_ustr, SVX_TABLE_CJK_FONT_HEIGHT, 
cppu::UnoType<float>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONTHEIGHT | CONVERT_TWIPS },
+            { u"CharWeightAsian"_ustr, SVX_TABLE_CJK_FONT_WEIGHT, 
cppu::UnoType<float>::get(),
+              PropertyAttribute::MAYBEVOID, MID_WEIGHT },
+            { u"CharPostureAsian"_ustr, SVX_TABLE_CJK_FONT_POSTURE,
+              cppu::UnoType<css::awt::FontSlant>::get(), 
PropertyAttribute::MAYBEVOID,
+              MID_POSTURE },
+            { u"CharFontNameAsian"_ustr, SVX_TABLE_CJK_FONT, 
cppu::UnoType<OUString>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY_NAME },
+            { u"CharFontStyleNameAsian"_ustr, SVX_TABLE_CJK_FONT, 
cppu::UnoType<OUString>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_STYLE_NAME },
+            { u"CharFontFamilyAsian"_ustr, SVX_TABLE_CJK_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY },
+            { u"CharFontCharSetAsian"_ustr, SVX_TABLE_CJK_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_CHAR_SET },
+            { u"CharFontPitchAsian"_ustr, SVX_TABLE_CJK_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_PITCH },
+            // CTL Font
+            { u"CharHeightComplex"_ustr, SVX_TABLE_CTL_FONT_HEIGHT, 
cppu::UnoType<float>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONTHEIGHT | CONVERT_TWIPS },
+            { u"CharWeightComplex"_ustr, SVX_TABLE_CTL_FONT_WEIGHT, 
cppu::UnoType<float>::get(),
+              PropertyAttribute::MAYBEVOID, MID_WEIGHT },
+            { u"CharPostureComplex"_ustr, SVX_TABLE_CTL_FONT_POSTURE,
+              cppu::UnoType<css::awt::FontSlant>::get(), 
PropertyAttribute::MAYBEVOID,
+              MID_POSTURE },
+            { u"CharFontNameComplex"_ustr, SVX_TABLE_CTL_FONT, 
cppu::UnoType<OUString>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY_NAME },
+            { u"CharFontStyleNameComplex"_ustr, SVX_TABLE_CTL_FONT, 
cppu::UnoType<OUString>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_STYLE_NAME },
+            { u"CharFontFamilyComplex"_ustr, SVX_TABLE_CTL_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY },
+            { u"CharFontCharSetComplex"_ustr, SVX_TABLE_CTL_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_CHAR_SET },
+            { u"CharFontPitchComplex"_ustr, SVX_TABLE_CTL_FONT, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_FONT_PITCH },
+            // Paragraph Properties
+            { u"ParaAdjust"_ustr, SVX_TABLE_PARA_ADJUST, 
cppu::UnoType<sal_Int16>::get(),
+              PropertyAttribute::MAYBEVOID, MID_PARA_ADJUST },
+        };
+    static SfxItemPropertySet aSvxTablePropertySet(aSvxTablePropertyMap);
+    return aSvxTablePropertySet;
+}
+
+SvxAutoFormatDataField::SvxAutoFormatDataField(const SvxAutoFormatDataField& 
rCopy)
+    : AutoFormatBase(rCopy)
+    , mSetProperties(rCopy.mSetProperties)
+{
+}
+
+void SvxAutoFormatDataField::GetValueFormat(OUString& rFormat, LanguageType& 
rLng,
+                                            LanguageType& rSys) const
+{
+    rFormat = maNumFormatString;
+    rLng = meNumFormatLanguage;
+    rSys = meSysLanguage;
+}
+
+void SvxAutoFormatDataField::SetValueFormat(const OUString& rFormat, 
LanguageType eLng,
+                                            LanguageType eSys)
+{
+    maNumFormatString = rFormat;
+    meNumFormatLanguage = eLng;
+    meSysLanguage = eSys;
+}
+
+SvxAutoFormatData::SvxAutoFormatData()
+    : mbInclFont(true)
+    , mbInclJustify(true)
+    , mbInclFrame(true)
+    , mbInclBackground(true)
+    , mbInclValueFormat(true)
+    , mbInclWidthHeight(true)
+    , mbUseFirstRowStyles(true)
+    , mbUseLastRowStyles(true)
+    , mbUseFirstColStyles(true)
+    , mbUseLastColStyles(true)
+    , mbUseBandedRowStyles(true)
+    , mbUseBandedColStyles(true)
+{
+}
+
+SvxAutoFormatData::SvxAutoFormatData(const SvxAutoFormatData& rData)
+    : maName(rData.maName)
+    , mbInclFont(rData.mbInclFont)
+    , mbInclJustify(rData.mbInclJustify)
+    , mbInclFrame(rData.mbInclFrame)
+    , mbInclBackground(rData.mbInclBackground)
+    , mbInclValueFormat(rData.mbInclValueFormat)
+    , mbInclWidthHeight(rData.mbInclWidthHeight)
+    , mbUseFirstRowStyles(rData.mbUseFirstRowStyles)
+    , mbUseLastRowStyles(rData.mbUseLastRowStyles)
+    , mbUseFirstColStyles(rData.mbUseFirstColStyles)
+    , mbUseLastColStyles(rData.mbUseLastColStyles)
+    , mbUseBandedRowStyles(rData.mbUseBandedRowStyles)
+    , mbUseBandedColStyles(rData.mbUseBandedColStyles)
+    , maParent(rData.maParent)
+{
+}
+
+SvxAutoFormatData& SvxAutoFormatData::operator=(const SvxAutoFormatData& rCopy)
+{
+    if (this == &rCopy)
+        return *this;
+
+    maName = rCopy.maName;
+    mbInclFont = rCopy.mbInclFont;
+    mbInclJustify = rCopy.mbInclJustify;
+    mbInclFrame = rCopy.mbInclFrame;
+    mbInclBackground = rCopy.mbInclBackground;
+    mbInclValueFormat = rCopy.mbInclValueFormat;
+    mbInclWidthHeight = rCopy.mbInclWidthHeight;
+    mbUseFirstRowStyles = rCopy.mbUseFirstRowStyles;
+    mbUseLastRowStyles = rCopy.mbUseLastRowStyles;
+    mbUseFirstColStyles = rCopy.mbUseFirstColStyles;
+    mbUseLastColStyles = rCopy.mbUseLastColStyles;
+    mbUseBandedRowStyles = rCopy.mbUseBandedRowStyles;
+    mbUseBandedColStyles = rCopy.mbUseBandedColStyles;
+
+    return *this;
+}
+
+void SvxAutoFormatData::FillToItemSet(size_t nIndex, SfxItemSet& rItemSet) 
const
+{
+    if (nIndex >= ELEMENT_COUNT)
+    {
+        SAL_WARN("svx", "SvxAutoFormatData::FillToItemSet - index out of 
bounds: " << nIndex);
+        return;
+    }
+
+    const SvxAutoFormatDataField& rField = *GetField(nIndex);
+    const SvxAutoFormatDataField& rDefault = *GetDefaultField();
+
+    if (IsFont())
+    {
+        // regular font
+        if (rField.GetFont() != rDefault.GetFont())
+            rItemSet.Put(rField.GetFont());
+
+        if (rField.GetHeight() != rDefault.GetHeight())
+            rItemSet.Put(rField.GetHeight());
+
+        if (rField.GetWeight() != rDefault.GetWeight())
+            rItemSet.Put(rField.GetWeight());
+
+        if (rField.GetPosture() != rDefault.GetPosture())
+            rItemSet.Put(rField.GetPosture());
+
+        // CJK Font
+        if (rField.GetCJKFont() != rDefault.GetCJKFont())
+            rItemSet.Put(rField.GetCJKFont());
+
+        if (rField.GetCJKHeight() != rDefault.GetCJKHeight())
+            rItemSet.Put(rField.GetCJKHeight());
+        if (rField.GetCJKWeight() != rDefault.GetCJKWeight())
+            rItemSet.Put(rField.GetCJKWeight());
+
+        if (rField.GetCJKPosture() != rDefault.GetCJKPosture())
+            rItemSet.Put(rField.GetCJKPosture());
+
+        // CTL font
+        if (rField.GetCTLFont() != rDefault.GetCTLFont())
+            rItemSet.Put(rField.GetCTLFont());
+
+        if (rField.GetCTLHeight() != rDefault.GetCTLHeight())
+            rItemSet.Put(rField.GetCTLHeight());
+
+        if (rField.GetCTLWeight() != rDefault.GetCTLWeight())
+            rItemSet.Put(rField.GetCTLWeight());
+
+        if (rField.GetCTLPosture() != rDefault.GetCTLPosture())
+            rItemSet.Put(rField.GetCTLPosture());
+
+        // Font properties
+        if (rField.GetUnderline() != rDefault.GetUnderline())
+            rItemSet.Put(rField.GetUnderline());
+
+        if (rField.GetColor() != rDefault.GetColor())
+            rItemSet.Put(rField.GetColor());
+    }
+
+    if (IsJustify())
+    {
+        if (rField.GetHorJustify() != rDefault.GetHorJustify())
+            rItemSet.Put(rField.GetHorJustify());
+
+        if (rField.GetVerJustify() != rDefault.GetVerJustify())
+            rItemSet.Put(rField.GetVerJustify());
+    }
+
+    if (IsBackground())
+    {
+        if (rField.GetBackground() != rDefault.GetBackground())
+            rItemSet.Put(rField.GetBackground());
+    }
+}
+
+void SvxAutoFormatData::MergeStyle(const SvxAutoFormatData& pParent)
+{
+    for (sal_uInt8 i = 0; i < ELEMENT_COUNT; i++)
+    {
+        if ((!UseFirstRowStyles()
+             && (i == FIRST_ROW || i == FIRST_ROW_START_COL || i == 
FIRST_ROW_END_COL
+                 || i == FIRST_ROW_EVEN_COL))
+            || (!UseLastRowStyles()
+                && (i == LAST_ROW || i == LAST_ROW_START_COL || i == 
LAST_ROW_END_COL
+                    || i == LAST_ROW_EVEN_COL))
+            || (!UseFirstColStyles() && i == FIRST_COL) || 
(!UseLastColStyles() && i == LAST_COL)
+            || (!UseBandedRowStyles() && (i == EVEN_ROW || i == ODD_ROW))
+            || (!UseBandedColStyles() && (i == EVEN_COL || i == ODD_COL)))
+        {
+            continue;
+        }
+
+        SvxAutoFormatDataField& pField = *GetField(i);
+        const SvxAutoFormatDataField& pNew = *pParent.GetField(i);
+
+        // regular font
+        if (!pField.IsPropertySet(PROP_FONT))
+            pField.SetFont(pNew.GetFont());
+        if (!pField.IsPropertySet(PROP_HEIGHT))
+            pField.SetHeight(pNew.GetHeight());
+        if (!pField.IsPropertySet(PROP_WEIGHT))
+            pField.SetWeight(pNew.GetWeight());
+        if (!pField.IsPropertySet(PROP_POSTURE))
+            pField.SetPosture(pNew.GetPosture());
+
+        // CJK font
+        if (!pField.IsPropertySet(PROP_CJK_FONT))
+            pField.SetCJKFont(pNew.GetCJKFont());
+        if (!pField.IsPropertySet(PROP_CJK_HEIGHT))
+            pField.SetCJKHeight(pNew.GetCJKHeight());
+        if (!pField.IsPropertySet(PROP_CJK_WEIGHT))
+            pField.SetCJKWeight(pNew.GetCJKWeight());
+        if (!pField.IsPropertySet(PROP_CJK_POSTURE))
+            pField.SetCJKPosture(pNew.GetCJKPosture());
+
+        // CTL font
+        if (!pField.IsPropertySet(PROP_CTL_FONT))
+            pField.SetCTLFont(pNew.GetCTLFont());
+        if (!pField.IsPropertySet(PROP_CTL_HEIGHT))
+            pField.SetCTLHeight(pNew.GetCTLHeight());
+        if (!pField.IsPropertySet(PROP_CTL_WEIGHT))
+            pField.SetCTLWeight(pNew.GetCTLWeight());
+        if (!pField.IsPropertySet(PROP_CTL_POSTURE))
+            pField.SetCTLPosture(pNew.GetCTLPosture());
+
+        // Font properties
+        if (!pField.IsPropertySet(PROP_UNDERLINE))
+            pField.SetUnderline(pNew.GetUnderline());
+
+        if (!pField.IsPropertySet(PROP_COLOR))
+            pField.SetColor(pNew.GetColor());
+        if (!pField.IsPropertySet(PROP_HOR_JUSTIFY))
+        {
+            pField.SetAdjust(pNew.GetAdjust());
+            pField.SetHorJustify(pNew.GetHorJustify());
+        }
+        if (!pField.IsPropertySet(PROP_VER_JUSTIFY))
+            pField.SetVerJustify(pNew.GetVerJustify());
+
+        SvxBoxItem aBox = pField.IsPropertySet(PROP_BOX) ? pField.GetBox() : 
pNew.GetBox();
+        sal_Int16 nPadding = pField.IsPropertySet(PROP_BOX)
+                                 ? 
pField.GetBox().GetDistance(SvxBoxItemLine::RIGHT)
+                                 : 
pNew.GetBox().GetDistance(SvxBoxItemLine::RIGHT);
+
+        aBox.SetDistance(nPadding, SvxBoxItemLine::RIGHT);
+        pField.SetBox(aBox);
+
+        if (!pField.IsPropertySet(PROP_BACKGROUND))
+            pField.SetBackground(pNew.GetBackground());
+    }
+}
+
+void SvxAutoFormatData::ResetAutoFormat(SvxAutoFormatData& pOld)
+{
+    for (int i = 0; i < ELEMENT_COUNT; i++)
+    {
+        SvxAutoFormatDataField& pField = *GetField(i);
+        const SvxAutoFormatDataField& pNew = *pOld.GetField(i);
+        pField.SetPropertySet(pNew.GetPropertySet());
+        // regular font
+        pField.SetFont(pNew.GetFont());
+        pField.SetHeight(pNew.GetHeight());
+        pField.SetWeight(pNew.GetWeight());
+        pField.SetPosture(pNew.GetPosture());
+
+        // CJK font
+        pField.SetCJKFont(pNew.GetCJKFont());
+        pField.SetCJKHeight(pNew.GetCJKHeight());
+        pField.SetCJKWeight(pNew.GetCJKWeight());
+        pField.SetCJKPosture(pNew.GetCJKPosture());
+
+        // CTL font
+        pField.SetCTLFont(pNew.GetCTLFont());
+        pField.SetCTLHeight(pNew.GetCTLHeight());
+        pField.SetCTLWeight(pNew.GetCTLWeight());
+        pField.SetCTLPosture(pNew.GetCTLPosture());
+
+        // Font properties
+        pField.SetUnderline(pNew.GetUnderline());
+        pField.SetColor(pNew.GetColor());
+
+        pField.SetAdjust(pNew.GetAdjust());
+        pField.SetHorJustify(pNew.GetHorJustify());
+        pField.SetVerJustify(pNew.GetVerJustify());
+
+        pField.SetBox(pNew.GetBox());
+        pField.SetBackground(pNew.GetBackground());
+    }
+}
+
+SvxAutoFormat::~SvxAutoFormat() = default;
+
+void SvxAutoFormat::ResetParent(const OUString& rName)
+{
+    OUString sParent;
+    if (size())
+        sParent = GetData(0)->GetName();
+
+    for (size_t i = 0; i < size(); i++)
+    {
+        if (GetData(i)->GetParent() == rName)
+        {
+            GetData(i)->SetParent(sParent);
+        }
+    }
+}
+
+bool SvxAutoFormat::Load(bool bWriter)
+{
+    OUString sStyles = "/svx/tablestyles.xml";
+    if (!bWriter)
+        sStyles = "/calc/tablestyles.xml";
+
+    try
+    {
+        OUString sPath(u"$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER + sStyles);
-e 
... etc. - the rest is truncated

Reply via email to