sc/inc/patattr.hxx                                                |    6 
 sc/qa/unit/subsequent_export_test.cxx                             |    2 
 sc/qa/unit/subsequent_export_test4.cxx                            |    5 
 sc/qa/unit/subsequent_filters_test2.cxx                           |    4 
 sc/qa/unit/ucalc.cxx                                              |   45 ++---
 sc/qa/unit/ucalc_DocumentThemes.cxx                               |    4 
 sc/qa/unit/ucalc_copypaste.cxx                                    |   10 -
 sc/qa/unit/ucalc_formula.cxx                                      |    2 
 sc/qa/unit/ucalc_sort.cxx                                         |    6 
 sc/source/core/data/attarray.cxx                                  |   37 ++--
 sc/source/core/data/column.cxx                                    |    2 
 sc/source/core/data/column3.cxx                                   |    3 
 sc/source/core/data/column4.cxx                                   |    4 
 sc/source/core/data/patattr.cxx                                   |   80 
+++++++---
 sc/source/core/data/poolcach.cxx                                  |    4 
 sc/source/core/data/table2.cxx                                    |    9 -
 sc/source/core/data/table3.cxx                                    |    5 
 sc/source/core/data/table4.cxx                                    |    9 -
 sc/source/filter/dif/difimp.cxx                                   |    2 
 sc/source/filter/excel/xestyle.cxx                                |    2 
 sc/source/filter/excel/xicontent.cxx                              |    2 
 sc/source/filter/excel/xistyle.cxx                                |    6 
 sc/source/filter/lotus/lotattr.cxx                                |    2 
 sc/source/filter/lotus/op.cxx                                     |    2 
 sc/source/filter/oox/PivotTableFormat.cxx                         |    4 
 sc/source/filter/oox/stylesbuffer.cxx                             |    6 
 sc/source/filter/orcus/interface.cxx                              |   10 -
 sc/source/filter/qpro/qprostyle.cxx                               |    2 
 sc/source/filter/rtf/eeimpars.cxx                                 |    2 
 sc/source/filter/xml/xmlcelli.cxx                                 |    2 
 sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx |   12 -
 sc/source/ui/docshell/arealink.cxx                                |    4 
 sc/source/ui/docshell/dbdocimp.cxx                                |    2 
 sc/source/ui/docshell/docfunc.cxx                                 |    6 
 sc/source/ui/docshell/docsh5.cxx                                  |    6 
 sc/source/ui/docshell/docsh8.cxx                                  |    3 
 sc/source/ui/docshell/impex.cxx                                   |    3 
 sc/source/ui/theme/ThemeColorChanger.cxx                          |    2 
 sc/source/ui/undo/undoblk.cxx                                     |    4 
 sc/source/ui/undo/undocell.cxx                                    |    2 
 sc/source/ui/unoobj/cellsuno.cxx                                  |   26 +--
 sc/source/ui/unoobj/funcuno.cxx                                   |    4 
 sc/source/ui/view/dbfunc3.cxx                                     |    2 
 sc/source/ui/view/formatsh.cxx                                    |   14 -
 sc/source/ui/view/output2.cxx                                     |    8 -
 sc/source/ui/view/spelleng.cxx                                    |    2 
 sc/source/ui/view/viewfun2.cxx                                    |    6 
 sc/source/ui/view/viewfunc.cxx                                    |   31 +--
 48 files changed, 219 insertions(+), 197 deletions(-)

New commits:
commit 76f3531532b7618d43e4f783748e30689f58900a
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Aug 6 20:11:02 2025 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Aug 8 00:29:33 2025 +0200

    copy the PatternAttr cached values
    
    which are derived from the SfxItemSet which is also copied
    so they are valid at the time of creation.
    
    And rework things to control more granularly when the ItemSet
    is changed to see when the cached values become invalid.
    
    Change-Id: Ibe3a07a37f2730495148d65911c465cbd7f2f027
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189023
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins

diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx
index e818df60a197..f08c29710267 100644
--- a/sc/inc/patattr.hxx
+++ b/sc/inc/patattr.hxx
@@ -157,7 +157,10 @@ public:
     CellAttributeHelper& getCellAttributeHelper() const { return 
*pCellAttributeHelper; }
 
     const SfxItemSet& GetItemSet() const { return maLocalSfxItemSet; }
-    SfxItemSet& GetItemSet() { return maLocalSfxItemSet; }
+    SC_DLLPUBLIC SfxItemSet& GetItemSetWritable();
+    SC_DLLPUBLIC void ItemSetPut(const SfxPoolItem& rItem);
+    void ItemSetPut(std::unique_ptr<SfxPoolItem> xItem);
+    void ItemSetClearItem(sal_uInt16 nWhich);
 
     const SfxPoolItem& GetItem(sal_uInt16 nWhichP) const
     {
@@ -281,6 +284,7 @@ private:
     sal_uInt32              GetNumberFormatKey() const;
     LanguageType            GetLanguageType() const;
     void                    InvalidateCaches();
+    void                    InvalidateCacheFor(sal_uInt16 nWhich);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/subsequent_export_test.cxx 
b/sc/qa/unit/subsequent_export_test.cxx
index 0e4e495a0e19..a8a8bd99c7a0 100644
--- a/sc/qa/unit/subsequent_export_test.cxx
+++ b/sc/qa/unit/subsequent_export_test.cxx
@@ -1610,7 +1610,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest, testRichTextExportODS)
         CPPUNIT_ASSERT_MESSAGE("Incorrect B9 value.", 
aCheckFunc.checkB9(pEditText));
 
         ScPatternAttr aCellFontColor(pDoc->getCellAttributeHelper());
-        aCellFontColor.GetItemSet().Put(SvxColorItem(COL_BLUE, 
ATTR_FONT_COLOR));
+        aCellFontColor.ItemSetPut(SvxColorItem(COL_BLUE, ATTR_FONT_COLOR));
         // Set font color of B10 to blue.
         pDoc->ApplyPattern(1, 9, 0, aCellFontColor);
         pEE->Clear();
diff --git a/sc/qa/unit/subsequent_export_test4.cxx 
b/sc/qa/unit/subsequent_export_test4.cxx
index 6342d4dde16c..d9551b045794 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -230,8 +230,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf143979)
         SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
         pFormatter->PutEntry(aCode, nCheckPos, nType, nFormat);
         ScPatternAttr aNewAttrs(pDoc->getCellAttributeHelper());
-        SfxItemSet& rSet = aNewAttrs.GetItemSet();
-        rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
         pDoc->ApplyPattern(0, 0, 0, aNewAttrs);
         pDoc->SetString(ScAddress(0, 0, 0), u"08/30/2021"_ustr);
         CPPUNIT_ASSERT_EQUAL(u"2021-08Aug-30Mon"_ustr, 
pDoc->GetString(ScAddress(0, 0, 0)));
@@ -1455,7 +1454,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testWholeRowBold)
 
         // Make entire second row bold.
         ScPatternAttr boldAttr(pDoc->getCellAttributeHelper());
-        boldAttr.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, 
ATTR_FONT_WEIGHT));
+        boldAttr.ItemSetPut(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
         pDoc->ApplyPatternAreaTab(0, 1, pDoc->MaxCol(), 1, 0, boldAttr);
     }
 
diff --git a/sc/qa/unit/subsequent_filters_test2.cxx 
b/sc/qa/unit/subsequent_filters_test2.cxx
index 0f72c945b828..91101037f918 100644
--- a/sc/qa/unit/subsequent_filters_test2.cxx
+++ b/sc/qa/unit/subsequent_filters_test2.cxx
@@ -1719,10 +1719,10 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest2, 
testBackColorFilter)
     ScDocument* pDoc = getScDoc();
 
     ScPatternAttr aPattern1(pDoc->getCellAttributeHelper());
-    aPattern1.GetItemSet().Put(SvxBrushItem(aBackColor1, ATTR_BACKGROUND));
+    aPattern1.ItemSetPut(SvxBrushItem(aBackColor1, ATTR_BACKGROUND));
 
     ScPatternAttr aPattern2(pDoc->getCellAttributeHelper());
-    aPattern2.GetItemSet().Put(SvxBrushItem(aBackColor2, ATTR_BACKGROUND));
+    aPattern2.ItemSetPut(SvxBrushItem(aBackColor2, ATTR_BACKGROUND));
 
     // Apply the pattern to cell A1:A2
     pDoc->ApplyPatternAreaTab(0, 0, 0, 1, 0, aPattern1);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 76ec832b8c5e..fd895fb64322 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -124,7 +124,7 @@ CPPUNIT_TEST_FIXTURE(Test, testUndoBackgroundColorInsertRow)
 
     // Add patterns
     ScPatternAttr aCellBlueColor(m_pDoc->getCellAttributeHelper());
-    aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    aCellBlueColor.ItemSetPut(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(0, 3, m_pDoc->MaxCol(), 3, 0, aCellBlueColor);
 
     // Insert a new row at row 3
@@ -165,7 +165,7 @@ CPPUNIT_TEST_FIXTURE(Test, 
testUndoBackgroundColorInsertColumn)
 
     // Add patterns
     ScPatternAttr aCellBlueColor(m_pDoc->getCellAttributeHelper());
-    aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    aCellBlueColor.ItemSetPut(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(3, 0, 3, m_pDoc->MaxRow(), 0, aCellBlueColor);
 
     // Insert a new column at column 3
@@ -332,7 +332,7 @@ CPPUNIT_TEST_FIXTURE(Test, testBackgroundColorDeleteColumn)
 
     // Add patterns
     ScPatternAttr aCellBlueColor(m_pDoc->getCellAttributeHelper());
-    aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    aCellBlueColor.ItemSetPut(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(3, 0, 3, m_pDoc->MaxRow(), 0, aCellBlueColor);
 
     // Delete column 10
@@ -369,7 +369,7 @@ CPPUNIT_TEST_FIXTURE(Test, testBackgroundColorDeleteRow)
 
     // Add patterns
     ScPatternAttr aCellBlueColor(m_pDoc->getCellAttributeHelper());
-    aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    aCellBlueColor.ItemSetPut(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(0, 3, m_pDoc->MaxCol(), 3, 0, aCellBlueColor);
 
     // Delete row 10
@@ -1379,7 +1379,7 @@ CPPUNIT_TEST_FIXTURE(Test, testHorizontalAttrIterator)
 
     // Set the background color of B2:C3,D2,E3,C4:D4,B5:D5 to blue
     ScPatternAttr aCellBackColor(m_pDoc->getCellAttributeHelper());
-    aCellBackColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    aCellBackColor.ItemSetPut(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(1, 1, 2, 2, 0, aCellBackColor);
     m_pDoc->ApplyPatternAreaTab(3, 1, 3, 1, 0, aCellBackColor);
     m_pDoc->ApplyPatternAreaTab(4, 2, 4, 2, 0, aCellBackColor);
@@ -1427,7 +1427,7 @@ CPPUNIT_TEST_FIXTURE(Test, 
testIteratorsUnallocatedColumnsAttributes)
 
     // Make entire second row and third row bold.
     ScPatternAttr boldAttr(m_pDoc->getCellAttributeHelper());
-    boldAttr.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
+    boldAttr.ItemSetPut(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
     m_pDoc->ApplyPatternAreaTab(0, 1, m_pDoc->MaxCol(), 2, 0, boldAttr);
 
     // That shouldn't need allocating more columns, just changing the default 
attribute.
@@ -1485,7 +1485,7 @@ CPPUNIT_TEST_FIXTURE(Test, testIteratorsDefPattern)
     SCCOL firstCol = 100;
     SCCOL lastCol = 103;
     ScPatternAttr boldAttr(m_pDoc->getCellAttributeHelper());
-    boldAttr.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
+    boldAttr.ItemSetPut(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
     m_pDoc->ApplyPattern(100, 0, 0, boldAttr);
     m_pDoc->ApplyPattern(102, 0, 0, boldAttr);
 
@@ -3697,8 +3697,7 @@ CPPUNIT_TEST_FIXTURE(Test, testAutoFilterTimeValue)
     SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
     sal_uInt32 nFormat = pFormatter->GetFormatIndex(NF_TIME_HH_MMSS, 
LANGUAGE_ENGLISH_US);
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
 
     m_pDoc->ApplyPatternAreaTab(0, 1, 0, 2, 0, aNewAttrs); // apply it to 
A2:A3.
 
@@ -3850,8 +3849,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf76441)
     pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat );
 
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
     {
         // First insert the string, then the format
         m_pDoc->SetString(ScAddress(0,0,0), u"01:20"_ustr);
@@ -3888,8 +3886,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf76836)
     pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat );
 
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
 
     m_pDoc->ApplyPattern(0, 0, 0, aNewAttrs);
     m_pDoc->SetValue(0,0,0, 10.0);
@@ -3935,8 +3932,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf142186)
     pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat );
 
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
     {
         // First insert the string, then the format
         m_pDoc->SetString(ScAddress(0,0,0), u"123.45"_ustr);
@@ -3989,8 +3985,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf164124)
     pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat );
 
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
     m_pDoc->ApplyPattern(0, 0, 0, aNewAttrs);
 
     m_pDoc->SetString(ScAddress(0,0,0), u"2021-6/1"_ustr);
@@ -4015,8 +4010,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf126342)
     pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat );
 
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
     m_pDoc->ApplyPattern(0, 0, 0, aNewAttrs);
 
     m_pDoc->SetString(ScAddress(0,0,0), u"11/7/19"_ustr);
@@ -4148,8 +4142,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateFilterContains)
     SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
     sal_uInt32 nFormat = pFormatter->GetFormatIndex(NF_DATE_DIN_YYMMDD, 
LANGUAGE_ENGLISH_US);
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
     m_pDoc->ApplyPatternAreaTab(0, 1, 0, 5, 0, aNewAttrs); // apply it to A1:A6
 
     ScDBData* pDBData = new ScDBData(u"NONAME"_ustr, 0, 0, 0, nCols, nRows);
@@ -6917,7 +6910,7 @@ CPPUNIT_TEST_FIXTURE(Test, testProtectedSheetEditByRow)
     {
         // Remove protected flags from rows 2-5.
         ScPatternAttr aAttr(m_pDoc->getCellAttributeHelper());
-        aAttr.GetItemSet().Put(ScProtectionAttr(false));
+        aAttr.ItemSetPut(ScProtectionAttr(false));
         m_pDoc->ApplyPatternAreaTab(0, 1, m_pDoc->MaxCol(), 4, 0, aAttr);
 
         // Protect the sheet without any options.
@@ -6993,7 +6986,7 @@ CPPUNIT_TEST_FIXTURE(Test, testProtectedSheetEditByColumn)
     {
         // Remove protected flags from columns B to E.
         ScPatternAttr aAttr(m_pDoc->getCellAttributeHelper());
-        aAttr.GetItemSet().Put(ScProtectionAttr(false));
+        aAttr.ItemSetPut(ScProtectionAttr(false));
         m_pDoc->ApplyPatternAreaTab(1, 0, 4, m_pDoc->MaxRow(), 0, aAttr);
 
         // Protect the sheet without any options.
@@ -7127,8 +7120,7 @@ CPPUNIT_TEST_FIXTURE(Test, 
testDocumentModelAccessor_getDocumentCurrencies)
         CPPUNIT_ASSERT_EQUAL(SvNumFormatType::CURRENCY, eType);
 
         ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-        SfxItemSet& rSet = aNewAttrs.GetItemSet();
-        rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
         m_pDoc->ApplyPattern(0, 0, 0, aNewAttrs); // A1.
 
         CPPUNIT_ASSERT_EQUAL(u"2,00€"_ustr, m_pDoc->GetString(ScAddress(0, 0, 
0)));
@@ -7157,8 +7149,7 @@ CPPUNIT_TEST_FIXTURE(Test, 
testDocumentModelAccessor_getDocumentCurrencies)
         CPPUNIT_ASSERT_EQUAL(SvNumFormatType::CURRENCY, eType);
 
         ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-        SfxItemSet& rSet = aNewAttrs.GetItemSet();
-        rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
         m_pDoc->ApplyPattern(1, 1, 0, aNewAttrs); // B2.
         m_pDoc->ApplyPattern(2, 2, 0, aNewAttrs); // C3.
 
diff --git a/sc/qa/unit/ucalc_DocumentThemes.cxx 
b/sc/qa/unit/ucalc_DocumentThemes.cxx
index 83878d02186d..73f8bab6efca 100644
--- a/sc/qa/unit/ucalc_DocumentThemes.cxx
+++ b/sc/qa/unit/ucalc_DocumentThemes.cxx
@@ -58,13 +58,13 @@ CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testChangeTheme)
         model::ComplexColor aComplexColor;
         aComplexColor.setThemeColor(eBackgroundThemeType);
         Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor);
-        aNewPattern.GetItemSet().Put(SvxBrushItem(aColor, aComplexColor, 
ATTR_BACKGROUND));
+        aNewPattern.ItemSetPut(SvxBrushItem(aColor, aComplexColor, 
ATTR_BACKGROUND));
     }
     {
         model::ComplexColor aComplexColor;
         aComplexColor.setThemeColor(eCellTextThemeType);
         Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor);
-        aNewPattern.GetItemSet().Put(SvxColorItem(aColor, aComplexColor, 
ATTR_FONT_COLOR));
+        aNewPattern.ItemSetPut(SvxColorItem(aColor, aComplexColor, 
ATTR_FONT_COLOR));
     }
 
     // Apply the pattern to cells C3:E5 (2,2 - 4,4) on the first sheet
diff --git a/sc/qa/unit/ucalc_copypaste.cxx b/sc/qa/unit/ucalc_copypaste.cxx
index 810d9a45a2af..e00135f69034 100644
--- a/sc/qa/unit/ucalc_copypaste.cxx
+++ b/sc/qa/unit/ucalc_copypaste.cxx
@@ -1615,7 +1615,7 @@ void TestCopyPaste::executeCopyPasteSpecial(const SCTAB 
srcSheet, const SCTAB de
 
     // add patterns
     ScPatternAttr aCellBlueColor(m_pDoc->getCellAttributeHelper());
-    aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    aCellBlueColor.ItemSetPut(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(1, 2, 1, 4, srcSheet, aCellBlueColor);
 
     // Check pattern precondition
@@ -1630,12 +1630,12 @@ void TestCopyPaste::executeCopyPasteSpecial(const SCTAB 
srcSheet, const SCTAB de
 
     // row 2 on empty cell
     ScPatternAttr aCellGreenColor(m_pDoc->getCellAttributeHelper());
-    aCellGreenColor.GetItemSet().Put(SvxBrushItem(COL_GREEN, ATTR_BACKGROUND));
+    aCellGreenColor.ItemSetPut(SvxBrushItem(COL_GREEN, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(5, 4, 5, 4, srcSheet, aCellGreenColor);
 
     // row 4 for multi range row selection
     ScPatternAttr aCellRedColor(m_pDoc->getCellAttributeHelper());
-    aCellRedColor.GetItemSet().Put(SvxBrushItem(COL_RED, ATTR_BACKGROUND));
+    aCellRedColor.ItemSetPut(SvxBrushItem(COL_RED, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(3, 6, 4, 6, srcSheet, aCellRedColor);
 
     // add borders
@@ -9288,7 +9288,7 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, 
testCopyPasteSkipEmpty)
 
     // Set the background color of B1:B5 to blue.
     ScPatternAttr aCellBackColor(m_pDoc->getCellAttributeHelper());
-    aCellBackColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
+    aCellBackColor.ItemSetPut(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND));
     m_pDoc->ApplyPatternAreaTab(1, 0, 1, 4, 0, aCellBackColor);
 
     // Insert notes to B1:B5.
@@ -9308,7 +9308,7 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, 
testCopyPasteSkipEmpty)
     aClipDoc.SetString(ScAddress(0, 4, 0), u"Clip3"_ustr);
 
     // Set the background color of A1:A5 to yellow.
-    aCellBackColor.GetItemSet().Put(SvxBrushItem(COL_YELLOW, ATTR_BACKGROUND));
+    aCellBackColor.ItemSetPut(SvxBrushItem(COL_YELLOW, ATTR_BACKGROUND));
     aClipDoc.ApplyPatternAreaTab(0, 0, 0, 4, 0, aCellBackColor);
 
     CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, aClipDoc.GetCellType(ScAddress(0, 0, 
0)));
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 4dd944fb1774..20e74f856d3e 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -4258,7 +4258,7 @@ CPPUNIT_TEST_FIXTURE(TestFormula, 
testFormulaRefUpdateValidity)
     SfxUInt32Item aItem(ATTR_VALIDDATA, nIndex);
 
     ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper());
-    aNewAttrs.GetItemSet().Put(aItem);
+    aNewAttrs.ItemSetPut(aItem);
 
     m_pDoc->ApplyPattern(0, 1, 0, aNewAttrs);
 
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index 6853794b0ec6..8fa964138501 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -641,8 +641,7 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
     CPPUNIT_ASSERT(pPat);
     {
         ScPatternAttr aNewPat(*pPat);
-        SfxItemSet& rSet = aNewPat.GetItemSet();
-        rSet.Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
+        aNewPat.ItemSetPut(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT));
         m_pDoc->ApplyPattern(0, 2, 0, aNewPat);
 
         // Make sure it's really in.
@@ -654,8 +653,7 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
     CPPUNIT_ASSERT(pPat);
     {
         ScPatternAttr aNewPat(*pPat);
-        SfxItemSet& rSet = aNewPat.GetItemSet();
-        rSet.Put(SvxPostureItem(ITALIC_NORMAL, ATTR_FONT_POSTURE));
+        aNewPat.ItemSetPut(SvxPostureItem(ITALIC_NORMAL, ATTR_FONT_POSTURE));
         m_pDoc->ApplyPattern(0, 3, 0, aNewPat);
 
         bool bGood = aCheck.isItalic(m_pDoc->GetPattern(ScAddress(0,3,0)));
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 852db370cf54..bde6a65e0929 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -309,21 +309,21 @@ void ScAttrArray::AddCondFormat( SCROW nStartRow, SCROW 
nEndRow, sal_uInt32 nInd
                     aNewCondFormatData.insert(nIndex);
                     ScCondFormatItem aItem( std::move(aNewCondFormatData) );
                     pNewPattern.reset( new ScPatternAttr(*pPattern) );
-                    pNewPattern->GetItemSet().Put( aItem );
+                    pNewPattern->ItemSetPut(aItem);
                 }
             }
             else
             {
                 ScCondFormatItem aItem(nIndex);
                 pNewPattern.reset( new ScPatternAttr(*pPattern) );
-                pNewPattern->GetItemSet().Put( aItem );
+                pNewPattern->ItemSetPut(aItem);
             }
         }
         else
         {
             pNewPattern.reset( new ScPatternAttr( 
rDocument.getCellAttributeHelper() ) );
             ScCondFormatItem aItem(nIndex);
-            pNewPattern->GetItemSet().Put( aItem );
+            pNewPattern->ItemSetPut(aItem);
             nTempEndRow = nEndRow;
         }
 
@@ -366,7 +366,7 @@ void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW 
nEndRow, sal_uInt32 n
                 {
                     ScCondFormatItem aItem;
                     ScPatternAttr* pTemp(new ScPatternAttr(*pPattern));
-                    pTemp->GetItemSet().Put( aItem );
+                    pTemp->ItemSetPut(aItem);
                     SetPatternArea( nTempStartRow, nTempEndRow, 
CellAttributeHolder(pTemp, true) );
                 }
                 else
@@ -379,7 +379,7 @@ void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW 
nEndRow, sal_uInt32 n
                         
aNewCondFormatData.erase_at(std::distance(rCondFormatData.begin(), itr));
                         ScCondFormatItem aItem( std::move(aNewCondFormatData) 
);
                         ScPatternAttr* pTemp(new ScPatternAttr(*pPattern));
-                        pTemp->GetItemSet().Put( aItem );
+                        pTemp->ItemSetPut(aItem);
                         SetPatternArea( nTempStartRow, nTempEndRow, 
CellAttributeHolder(pTemp, true) );
                     }
                 }
@@ -736,7 +736,6 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, 
SCROW nEndRow,
         if ( pBoxItem || pTLBRItem || pBLTRItem )
         {
             std::unique_ptr<ScPatternAttr> pNewPattern(new 
ScPatternAttr(*pOldPattern));
-            SfxItemSet&     rNewSet = pNewPattern->GetItemSet();
             SCROW           nY1 = nStart;
             SCROW           nY2 = mvData[nPos].nEndRow;
 
@@ -792,9 +791,9 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, 
SCROW nEndRow,
                         SetLine( pNewBLTRItem->GetLine(), pLine );
                 }
             }
-            if( pNewBoxItem )   rNewSet.Put( std::move(pNewBoxItem) );
-            if( pNewTLBRItem )  rNewSet.Put( std::move(pNewTLBRItem) );
-            if( pNewBLTRItem )  rNewSet.Put( std::move(pNewBLTRItem) );
+            if (pNewBoxItem) pNewPattern->ItemSetPut(std::move(pNewBoxItem));
+            if (pNewTLBRItem) pNewPattern->ItemSetPut(std::move(pNewTLBRItem));
+            if (pNewBLTRItem) pNewPattern->ItemSetPut(std::move(pNewBLTRItem));
 
             nStart = mvData[nPos].nEndRow + 1;
 
@@ -1536,8 +1535,7 @@ void ScAttrArray::RemoveAreaMerge(SCROW nStartRow, SCROW 
nEndRow)
                 rDocument.ApplyAttr( nThisCol, nThisRow, nTab, *pAttr );
 
             ScPatternAttr aNewPattern( rDocument.getCellAttributeHelper() );
-            SfxItemSet*     pSet = &aNewPattern.GetItemSet();
-            pSet->Put( *pFlagAttr );
+            aNewPattern.ItemSetPut(*pFlagAttr);
             rDocument.ApplyPatternAreaTab( nThisCol, nThisStart, nMergeEndCol, 
nMergeEndRow,
                                                 nTab, aNewPattern );
 
@@ -1580,7 +1578,7 @@ void ScAttrArray::SetPatternAreaSafe(SCROW nStartRow, 
SCROW nEndRow, const CellA
                 //  Instead, the document's 
getCellAttributeHelper().getDefaultCellAttribute() is copied. Since it is 
passed as
                 //  pWantedPattern, no special treatment of default is needed 
here anymore.
                 ScPatternAttr* pNewPattern(new 
ScPatternAttr(*rWantedPattern.getScPatternAttr()));
-                pNewPattern->GetItemSet().Put( *pItem );
+                pNewPattern->ItemSetPut(*pItem);
                 SetPatternArea( nThisRow, nAttrRow, 
CellAttributeHolder(pNewPattern, true) );
             }
             else
@@ -1620,7 +1618,7 @@ bool ScAttrArray::ApplyFlags( SCROW nStartRow, SCROW 
nEndRow, ScMF nFlags )
             nRow = mvData[nIndex].nEndRow;
             SCROW nAttrRow = std::min( nRow, nEndRow );
             ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern));
-            pNewPattern->GetItemSet().Put( ScMergeFlagAttr( nOldValue | nFlags 
) );
+            pNewPattern->ItemSetPut(ScMergeFlagAttr(nOldValue | nFlags));
             SetPatternArea( nThisRow, nAttrRow, 
CellAttributeHolder(pNewPattern, true) );
             Search( nThisRow, nIndex );  // data changed
             bChanged = true;
@@ -1657,7 +1655,7 @@ bool ScAttrArray::RemoveFlags( SCROW nStartRow, SCROW 
nEndRow, ScMF nFlags )
             nRow = mvData[nIndex].nEndRow;
             SCROW nAttrRow = std::min( nRow, nEndRow );
             ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern));
-            pNewPattern->GetItemSet().Put( ScMergeFlagAttr( nOldValue & 
~nFlags ) );
+            pNewPattern->ItemSetPut(ScMergeFlagAttr(nOldValue & ~nFlags));
             SetPatternArea( nThisRow, nAttrRow, 
CellAttributeHolder(pNewPattern, true) );
             Search( nThisRow, nIndex );  // data changed
             bChanged = true;
@@ -1747,9 +1745,9 @@ void ScAttrArray::ChangeIndent( SCROW nStartRow, SCROW 
nEndRow, bool bIncrement
             SCROW nThisEnd = mvData[nIndex].nEndRow;
             SCROW nAttrRow = std::min( nThisEnd, nEndRow );
             ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern));
-            pNewPattern->GetItemSet().Put( ScIndentItem( nNewValue ) );
+            pNewPattern->ItemSetPut(ScIndentItem(nNewValue));
             if ( bNeedJust )
-                pNewPattern->GetItemSet().Put(
+                pNewPattern->ItemSetPut(
                                 SvxHorJustifyItem( SvxCellHorJustify::Left, 
ATTR_HOR_JUSTIFY ) );
             SetPatternArea( nThisStart, nAttrRow, 
CellAttributeHolder(pNewPattern, true) );
 
@@ -2349,10 +2347,9 @@ void ScAttrArray::DeleteHardAttr(SCROW nStartRow, SCROW 
nEndRow)
             SCROW nAttrRow = std::min( nRow, nEndRow );
 
             ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern));
-            SfxItemSet& rSet = pNewPattern->GetItemSet();
             for (sal_uInt16 nId = ATTR_PATTERN_START; nId <= ATTR_PATTERN_END; 
nId++)
                 if (nId != ATTR_MERGE && nId != ATTR_MERGE_FLAG)
-                    rSet.ClearItem(nId);
+                    pNewPattern->ItemSetClearItem(nId);
 
             if ( *pNewPattern == *aDefHolder.getScPatternAttr() )
             {
@@ -2432,9 +2429,9 @@ void ScAttrArray::CopyArea(
                     nNewFlags = 
pTmpPattern->GetItem(ATTR_MERGE_FLAG).GetValue() & ~nStripFlags;
 
                 if ( nNewFlags != ScMF::NONE )
-                    pTmpPattern->GetItemSet().Put( ScMergeFlagAttr( nNewFlags 
) );
+                    pTmpPattern->ItemSetPut(ScMergeFlagAttr(nNewFlags));
                 else
-                    pTmpPattern->GetItemSet().ClearItem( ATTR_MERGE_FLAG );
+                    pTmpPattern->ItemSetClearItem(ATTR_MERGE_FLAG);
 
                 if (bSameCellAttributeHelper)
                     aNewPattern.setScPatternAttr(pTmpPattern, true);
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 41c603f5b777..0996250e4d49 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -559,7 +559,7 @@ void ScColumn::ApplyAttr( SCROW nRow, const SfxPoolItem& 
rAttr )
 
     const ScPatternAttr* pOldPattern(pAttrArray->GetPattern(nRow));
     ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern));
-    pNewPattern->GetItemSet().Put(rAttr);
+    pNewPattern->ItemSetPut(rAttr);
 
     if (!ScPatternAttr::areSame( pNewPattern, pOldPattern ))
         pAttrArray->SetPattern( nRow, CellAttributeHolder(pNewPattern, true) );
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 0d0670011ea5..168dda3e9704 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2099,8 +2099,7 @@ void applyTextNumFormat( ScColumn& rCol, SCROW nRow, 
SvNumberFormatter* pFormatt
 {
     sal_uInt32 nFormat = pFormatter->GetStandardFormat(SvNumFormatType::TEXT);
     ScPatternAttr aNewAttrs(rCol.GetDoc().getCellAttributeHelper());
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
     rCol.ApplyPattern(nRow, aNewAttrs);
 }
 
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index 452786cfbf87..999cd804c13f 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -134,7 +134,7 @@ void ScColumn::DeleteBeforeCopyFromClip(
             if (rCxt.isTableProtected())
             {
                 ScPatternAttr aPattern(rDocument.getCellAttributeHelper());
-                aPattern.GetItemSet().Put(ScProtectionAttr(false));
+                aPattern.ItemSetPut(ScProtectionAttr(false));
                 ApplyPatternArea(aRange.mnRow1, aRange.mnRow2, aPattern);
             }
 
@@ -229,7 +229,7 @@ void ScColumn::DeleteBeforeCopyFromClip(
             if (rCxt.isTableProtected())
             {
                 ScPatternAttr aPattern(rDocument.getCellAttributeHelper());
-                aPattern.GetItemSet().Put(ScProtectionAttr(false));
+                aPattern.ItemSetPut(ScProtectionAttr(false));
                 ApplyPatternArea(nRow1, nRow2, aPattern);
             }
 
diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index ceff826a43ca..08b28d8dbd7c 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -418,7 +418,9 @@ ScPatternAttr::ScPatternAttr(CellAttributeHelper& rHelper, 
const SfxItemSet* pIt
 ScPatternAttr::ScPatternAttr(const ScPatternAttr& rPatternAttr)
 : maLocalSfxItemSet(rPatternAttr.maLocalSfxItemSet)
 , moName(rPatternAttr.moName)
-, mxVisible()
+, mxVisible(rPatternAttr.mxVisible)
+, mxNumberFormatKey(rPatternAttr.mxNumberFormatKey)
+, mxLanguageType(rPatternAttr.mxLanguageType)
 , pStyle(rPatternAttr.pStyle)
 , pCellAttributeHelper(rPatternAttr.pCellAttributeHelper)
 , mnPAKey(rPatternAttr.mnPAKey)
@@ -1286,7 +1288,7 @@ void ScPatternAttr::GetFromEditItemSet( const SfxItemSet* 
pEditSet )
 {
     if( !pEditSet )
         return;
-    GetFromEditItemSet( GetItemSet(), *pEditSet );
+    GetFromEditItemSet(maLocalSfxItemSet, *pEditSet);
     InvalidateCaches();
 }
 
@@ -1312,7 +1314,6 @@ void ScPatternAttr::FillEditParaItems( SfxItemSet* 
pEditSet ) const
 
 void ScPatternAttr::DeleteUnchanged( const ScPatternAttr* pOldAttrs )
 {
-    SfxItemSet& rThisSet = GetItemSet();
     const SfxItemSet& rOldSet = pOldAttrs->GetItemSet();
 
     const SfxPoolItem* pThisItem;
@@ -1321,7 +1322,7 @@ void ScPatternAttr::DeleteUnchanged( const ScPatternAttr* 
pOldAttrs )
     for ( sal_uInt16 nSubWhich=ATTR_PATTERN_START; 
nSubWhich<=ATTR_PATTERN_END; nSubWhich++ )
     {
         //  only items that are set are interesting
-        if ( rThisSet.GetItemState( nSubWhich, false, &pThisItem ) == 
SfxItemState::SET )
+        if ( maLocalSfxItemSet.GetItemState( nSubWhich, false, &pThisItem ) == 
SfxItemState::SET )
         {
             SfxItemState eOldState = rOldSet.GetItemState( nSubWhich, true, 
&pOldItem );
             if ( eOldState == SfxItemState::SET )
@@ -1329,16 +1330,16 @@ void ScPatternAttr::DeleteUnchanged( const 
ScPatternAttr* pOldAttrs )
                 //  item is set in OldAttrs (or its parent) -> compare pointers
                 if (SfxPoolItem::areSame( pThisItem, pOldItem ))
                 {
-                    rThisSet.ClearItem( nSubWhich );
+                    maLocalSfxItemSet.ClearItem( nSubWhich );
                     InvalidateCaches();
                 }
             }
             else if ( eOldState != SfxItemState::INVALID )
             {
                 //  not set in OldAttrs -> compare item value to default item
-                if ( *pThisItem == 
rThisSet.GetPool()->GetUserOrPoolDefaultItem( nSubWhich ) )
+                if ( *pThisItem == 
maLocalSfxItemSet.GetPool()->GetUserOrPoolDefaultItem( nSubWhich ) )
                 {
-                    rThisSet.ClearItem( nSubWhich );
+                    maLocalSfxItemSet.ClearItem( nSubWhich );
                     InvalidateCaches();
                 }
             }
@@ -1348,18 +1349,16 @@ void ScPatternAttr::DeleteUnchanged( const 
ScPatternAttr* pOldAttrs )
 
 bool ScPatternAttr::HasItemsSet( const sal_uInt16* pWhich ) const
 {
-    const SfxItemSet& rSet = GetItemSet();
     for (sal_uInt16 i=0; pWhich[i]; i++)
-        if ( rSet.GetItemState( pWhich[i], false ) == SfxItemState::SET )
+        if ( maLocalSfxItemSet.GetItemState( pWhich[i], false ) == 
SfxItemState::SET )
             return true;
     return false;
 }
 
 void ScPatternAttr::ClearItems( const sal_uInt16* pWhich )
 {
-    SfxItemSet& rSet = GetItemSet();
     for (sal_uInt16 i=0; pWhich[i]; i++)
-        rSet.ClearItem(pWhich[i]);
+        maLocalSfxItemSet.ClearItem(pWhich[i]);
     InvalidateCaches();
 }
 
@@ -1426,7 +1425,7 @@ CellAttributeHolder ScPatternAttr::MigrateToDocument( 
ScDocument* pDestDoc, ScDo
 {
     const SfxItemSet* pSrcSet = &GetItemSet();
     ScPatternAttr* pDestPattern(new 
ScPatternAttr(pDestDoc->getCellAttributeHelper()));
-    SfxItemSet* pDestSet(&pDestPattern->GetItemSet());
+    SfxItemSet* pDestSet(&pDestPattern->GetItemSetWritable());
 
     // Copy cell pattern style to other document:
     if ( pDestDoc != pSrcDoc )
@@ -1559,7 +1558,6 @@ void ScPatternAttr::SetStyleSheet( ScStyleSheet* 
pNewStyle, bool bClearDirectFor
 {
     if (pNewStyle)
     {
-        SfxItemSet&       rPatternSet = GetItemSet();
         const SfxItemSet& rStyleSet = pNewStyle->GetItemSet();
 
         if (bClearDirectFormat)
@@ -1567,17 +1565,17 @@ void ScPatternAttr::SetStyleSheet( ScStyleSheet* 
pNewStyle, bool bClearDirectFor
             for (sal_uInt16 i=ATTR_PATTERN_START; i<=ATTR_PATTERN_END; i++)
             {
                 if (rStyleSet.GetItemState(i) == SfxItemState::SET)
-                    rPatternSet.ClearItem(i);
+                    maLocalSfxItemSet.ClearItem(i);
             }
         }
-        rPatternSet.SetParent(&pNewStyle->GetItemSet());
+        maLocalSfxItemSet.SetParent(&pNewStyle->GetItemSet());
         pStyle = pNewStyle;
         moName.reset();
     }
     else
     {
         OSL_FAIL( "ScPatternAttr::SetStyleSheet( NULL ) :-|" );
-        GetItemSet().SetParent(nullptr);
+        maLocalSfxItemSet.SetParent(nullptr);
         pStyle = nullptr;
     }
     InvalidateCaches();
@@ -1601,7 +1599,7 @@ bool ScPatternAttr::UpdateStyleSheet(const ScDocument& 
rDoc)
 
         if (pStyle)
         {
-            GetItemSet().SetParent(&pStyle->GetItemSet());
+            maLocalSfxItemSet.SetParent(&pStyle->GetItemSet());
             moName.reset();
         }
     }
@@ -1622,7 +1620,7 @@ void ScPatternAttr::StyleToName()
     {
         moName = pStyle->GetName();
         pStyle = nullptr;
-        GetItemSet().SetParent( nullptr );
+        maLocalSfxItemSet.SetParent( nullptr );
         InvalidateCaches();
     }
 }
@@ -1801,4 +1799,50 @@ void ScPatternAttr::InvalidateCaches()
     mxLanguageType.reset();
 }
 
+SfxItemSet& ScPatternAttr::GetItemSetWritable()
+{
+    // Generally have to assume that caches are invalid
+    // after this is used.
+    InvalidateCaches();
+    return maLocalSfxItemSet;
+}
+
+void ScPatternAttr::InvalidateCacheFor(sal_uInt16 nWhich)
+{
+    switch (nWhich)
+    {
+        case ATTR_LANGUAGE_FORMAT:
+            mxLanguageType.reset();
+            break;
+        case ATTR_VALUE_FORMAT:
+            mxNumberFormatKey.reset();
+            break;
+        case ATTR_BACKGROUND:
+        case ATTR_BORDER:
+        case ATTR_BORDER_TLBR:
+        case ATTR_BORDER_BLTR:
+        case ATTR_SHADOW:
+            mxVisible.reset();
+            break;
+    }
+}
+
+void ScPatternAttr::ItemSetPut(const SfxPoolItem& rItem)
+{
+    InvalidateCacheFor(rItem.Which());
+    maLocalSfxItemSet.Put(rItem);
+}
+
+void ScPatternAttr::ItemSetPut(std::unique_ptr<SfxPoolItem> xItem)
+{
+    InvalidateCacheFor(xItem->Which());
+    maLocalSfxItemSet.Put(std::move(xItem));
+}
+
+void ScPatternAttr::ItemSetClearItem(sal_uInt16 nWhich)
+{
+    InvalidateCacheFor(nWhich);
+    maLocalSfxItemSet.ClearItem(nWhich);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/poolcach.cxx b/sc/source/core/data/poolcach.cxx
index 6db714bb7c12..4107dd89f180 100644
--- a/sc/source/core/data/poolcach.cxx
+++ b/sc/source/core/data/poolcach.cxx
@@ -64,11 +64,11 @@ const CellAttributeHolder& ScItemPoolCache::ApplyTo(const 
CellAttributeHolder& r
 
     if (nullptr != aItemToPut.getItem())
     {
-        pNewItem->GetItemSet().Put(*aItemToPut.getItem());
+        pNewItem->ItemSetPut(*aItemToPut.getItem());
     }
     else
     {
-        pNewItem->GetItemSet().Put(*pSetToPut);
+        pNewItem->GetItemSetWritable().Put(*pSetToPut);
     }
 
     m_aCache.emplace_back(rOrigItem, CellAttributeHolder(pNewItem, true));
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 25c5d94c87c7..1d2455c57deb 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1099,7 +1099,6 @@ void ScTable::TransposeColPatterns(ScTable* pTransClip, 
SCCOL nCol1, SCCOL nCol,
                 {
                     // transpose borders and merge values, remove merge flags 
(refreshed after pasting)
                     ScPatternAttr aNewPattern( *pPattern );
-                    SfxItemSet& rNewSet = aNewPattern.GetItemSet();
 
                     const SvxBoxItem& rOldBox = rSet.Get(ATTR_BORDER);
                     if ( rOldBox.GetTop() || rOldBox.GetBottom() || 
rOldBox.GetLeft() || rOldBox.GetRight() )
@@ -1113,12 +1112,12 @@ void ScTable::TransposeColPatterns(ScTable* pTransClip, 
SCCOL nCol1, SCCOL nCol,
                         aNew.SetDistance( rOldBox.GetDistance( 
SvxBoxItemLine::LEFT ), SvxBoxItemLine::TOP );
                         aNew.SetDistance( rOldBox.GetDistance( 
SvxBoxItemLine::BOTTOM ), SvxBoxItemLine::RIGHT );
                         aNew.SetDistance( rOldBox.GetDistance( 
SvxBoxItemLine::RIGHT ), SvxBoxItemLine::BOTTOM );
-                        rNewSet.Put( aNew );
+                        aNewPattern.ItemSetPut(aNew);
                     }
 
                     const ScMergeAttr& rOldMerge = rSet.Get(ATTR_MERGE);
                     if (rOldMerge.IsMerged())
-                        rNewSet.Put( ScMergeAttr( std::min(
+                        aNewPattern.ItemSetPut( ScMergeAttr( std::min(
                                         
static_cast<SCCOL>(rOldMerge.GetRowMerge()),
                                         
static_cast<SCCOL>(rDocument.MaxCol()+1 - (nAttrRow2-nRow1))),
                                     std::min(
@@ -1129,9 +1128,9 @@ void ScTable::TransposeColPatterns(ScTable* pTransClip, 
SCCOL nCol1, SCCOL nCol,
                     {
                         ScMF nNewFlags = rOldFlag.GetValue() & ~ScMF( 
ScMF::Hor | ScMF::Ver );
                         if ( nNewFlags != ScMF::NONE )
-                            rNewSet.Put( ScMergeFlagAttr( nNewFlags ) );
+                            aNewPattern.ItemSetPut(ScMergeFlagAttr(nNewFlags));
                         else
-                            rNewSet.ClearItem( ATTR_MERGE_FLAG );
+                            aNewPattern.ItemSetClearItem(ATTR_MERGE_FLAG);
                     }
 
                     // Set pattern in cells from nAttrRow1 to nAttrRow2
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 39decdf6e027..055617dfec14 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1927,9 +1927,8 @@ static void lcl_RemoveNumberFormat( ScTable* pTab, SCCOL 
nCol, SCROW nRow )
             == SfxItemState::SET )
     {
         ScPatternAttr* pNewPattern(new ScPatternAttr( *pPattern ));
-        SfxItemSet& rSet = pNewPattern->GetItemSet();
-        rSet.ClearItem( ATTR_VALUE_FORMAT );
-        rSet.ClearItem( ATTR_LANGUAGE_FORMAT );
+        pNewPattern->ItemSetClearItem(ATTR_VALUE_FORMAT);
+        pNewPattern->ItemSetClearItem(ATTR_LANGUAGE_FORMAT);
         pTab->SetPattern( nCol, nRow, CellAttributeHolder(pNewPattern, true) );
     }
 }
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 718aae92f8d4..ae641dea45cc 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -987,11 +987,10 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL 
nCol2, SCROW nRow2,
                         if ( nOldValue != nOldValueMerge )
                         {
                             pNewPattern.reset(new ScPatternAttr(*pSrcPattern));
-                            SfxItemSet& rNewSet = pNewPattern->GetItemSet();
-                            if ( nOldValueMerge == ScMF::NONE )
-                                rNewSet.ClearItem(ATTR_MERGE_FLAG);
+                            if (nOldValueMerge == ScMF::NONE)
+                                pNewPattern->ItemSetClearItem(ATTR_MERGE_FLAG);
                             else
-                                rNewSet.Put(ScMergeFlagAttr(nOldValueMerge));
+                                
pNewPattern->ItemSetPut(ScMergeFlagAttr(nOldValueMerge));
                         }
                         else
                             pNewPattern.reset();
@@ -2698,7 +2697,7 @@ void ScTable::AutoFormat( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SCROW
     for (sal_uInt8 i = 0; i < 16; ++i)
     {
         pPatternAttrs[i].reset(new 
ScPatternAttr(rDocument.getCellAttributeHelper()));
-        pData->FillToItemSet(i, pPatternAttrs[i]->GetItemSet(), rDocument);
+        pData->FillToItemSet(i, pPatternAttrs[i]->GetItemSetWritable(), 
rDocument);
     }
 
     // Important special case: when the whole rows are selected. Then applying 
autoformat to right
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx
index d26b7276a3de..626b76005988 100644
--- a/sc/source/filter/dif/difimp.cxx
+++ b/sc/source/filter/dif/difimp.cxx
@@ -625,7 +625,7 @@ void DifColumn::NewEntry( const SCROW nPos, const 
sal_uInt32 nNumFormat )
 void DifColumn::Apply( ScDocument& rDoc, const SCCOL nCol, const SCTAB nTab )
 {
     ScPatternAttr aAttr(rDoc.getCellAttributeHelper());
-    SfxItemSet &rItemSet = aAttr.GetItemSet();
+    SfxItemSet &rItemSet = aAttr.GetItemSetWritable();
 
     for (const auto& rEntry : maEntries)
     {
diff --git a/sc/source/filter/excel/xestyle.cxx 
b/sc/source/filter/excel/xestyle.cxx
index 53797143e578..4fce1d001825 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -3171,7 +3171,7 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot )
                 if (!rFormat.pPattern)
                     continue;
 
-                SfxItemSet& rItemSet = rFormat.pPattern->GetItemSet();
+                SfxItemSet& rItemSet = rFormat.pPattern->GetItemSetWritable();
                 fillDxfFrom(rItemSet, xFormatter);
                 maPatternToDxfId.emplace(rFormat.pPattern.get(), nDxfId);
                 nDxfId++;
diff --git a/sc/source/filter/excel/xicontent.cxx 
b/sc/source/filter/excel/xicontent.cxx
index f8e64b4ef28f..4fa70f160c68 100644
--- a/sc/source/filter/excel/xicontent.cxx
+++ b/sc/source/filter/excel/xicontent.cxx
@@ -943,7 +943,7 @@ void XclImpValidationManager::Apply()
         // set the handle ID
         sal_uInt32 nHandle = rDoc.AddValidationEntry( rItem.maValidData );
         ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-        aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nHandle ) );
+        aPattern.ItemSetPut(SfxUInt32Item(ATTR_VALIDDATA, nHandle));
 
         // apply all ranges
         for ( size_t i = 0, nRanges = rItem.maRanges.size(); i < nRanges; ++i, 
++nPatterns )
diff --git a/sc/source/filter/excel/xistyle.cxx 
b/sc/source/filter/excel/xistyle.cxx
index 7cf0f136681c..8c488b3b0b8d 100644
--- a/sc/source/filter/excel/xistyle.cxx
+++ b/sc/source/filter/excel/xistyle.cxx
@@ -1250,7 +1250,7 @@ const ScPatternAttr& XclImpXF::CreatePattern( bool 
bSkipPoolDefs )
 
     // create new pattern attribute set
     mpPattern.reset( new ScPatternAttr(GetDoc().getCellAttributeHelper()) );
-    SfxItemSet& rItemSet = mpPattern->GetItemSet();
+    SfxItemSet& rItemSet = mpPattern->GetItemSetWritable();
     XclImpXF* pParentXF = IsCellXF() ? GetXFBuffer().GetXF( mnParent ) : 
nullptr;
 
     // parent cell style
@@ -1377,8 +1377,8 @@ void XclImpXF::ApplyPatternToAttrVector(
     if (nForceScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND)
     {
         ScPatternAttr aNumPat(rDoc.getCellAttributeHelper());
-        GetNumFmtBuffer().FillScFmtToItemSet(aNumPat.GetItemSet(), 
nForceScNumFmt);
-        rPat.GetItemSet().Put(aNumPat.GetItemSet());
+        GetNumFmtBuffer().FillScFmtToItemSet(aNumPat.GetItemSetWritable(), 
nForceScNumFmt);
+        rPat.GetItemSetWritable().Put(aNumPat.GetItemSet());
     }
 
     // Make sure we skip unnamed styles.
diff --git a/sc/source/filter/lotus/lotattr.cxx 
b/sc/source/filter/lotus/lotattr.cxx
index 933380ad7b96..410cac7ba242 100644
--- a/sc/source/filter/lotus/lotattr.cxx
+++ b/sc/source/filter/lotus/lotattr.cxx
@@ -88,7 +88,7 @@ const ScPatternAttr& LotAttrCache::GetPattAttr( const 
LotAttrWK3& rAttr )
     // generate new Pattern Attribute
     ScPatternAttr*  pNewPatt = new 
ScPatternAttr(mrContext.rDoc.getCellAttributeHelper());
 
-    SfxItemSet&     rItemSet = pNewPatt->GetItemSet();
+    SfxItemSet&     rItemSet = pNewPatt->GetItemSetWritable();
     ENTRY *pCurrent = new ENTRY( std::unique_ptr<ScPatternAttr>(pNewPatt) );
 
     pCurrent->nHash0 = nRefHash;
diff --git a/sc/source/filter/lotus/op.cxx b/sc/source/filter/lotus/op.cxx
index e1c46643bd55..8cd3717dffc5 100644
--- a/sc/source/filter/lotus/op.cxx
+++ b/sc/source/filter/lotus/op.cxx
@@ -536,7 +536,7 @@ void OP_CreatePattern123(LotusContext& rContext, SvStream& 
r, sal_uInt16 n)
     sal_uInt16 nCode;
 
     ScPatternAttr aPattern(rContext.rDoc.getCellAttributeHelper());
-    SfxItemSet& rItemSet = aPattern.GetItemSet();
+    SfxItemSet& rItemSet = aPattern.GetItemSetWritable();
 
     r.ReadUInt16( nCode );
     n -= std::min<sal_uInt16>(n, 2);
diff --git a/sc/source/filter/oox/PivotTableFormat.cxx 
b/sc/source/filter/oox/PivotTableFormat.cxx
index 8072d680ddda..48410d01ceda 100644
--- a/sc/source/filter/oox/PivotTableFormat.cxx
+++ b/sc/source/filter/oox/PivotTableFormat.cxx
@@ -79,7 +79,9 @@ void PivotTableFormat::finalizeImport()
     auto pPattern = 
std::make_shared<ScPatternAttr>(getScDocument().getCellAttributeHelper());
 
     if (DxfRef pDxf = getStyles().getDxf(mnDxfId))
-        pDxf->fillToItemSet(pPattern->GetItemSet());
+    {
+        pDxf->fillToItemSet(pPattern->GetItemSetWritable());
+    }
 
     ScDPObject* pDPObj = mrPivotTable.getDPObject();
     ScDPSaveData* pSaveData = pDPObj->GetSaveData();
diff --git a/sc/source/filter/oox/stylesbuffer.cxx 
b/sc/source/filter/oox/stylesbuffer.cxx
index 72ed6cd59882..15547d4b4e22 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2232,8 +2232,8 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW 
nRow1, SCROW nRow2, sal
     if ( !pCachedPattern && nNumFmtId >= 0 )
     {
         ScPatternAttr aNumPat(rDoc.getCellAttributeHelper());
-        mnScNumFmt = getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), 
nNumFmtId, false );
-        rPat.GetItemSet().Put(aNumPat.GetItemSet());
+        mnScNumFmt = getStyles().writeNumFmtToItemSet( 
aNumPat.GetItemSetWritable(), nNumFmtId, false );
+        rPat.GetItemSetWritable().Put(aNumPat.GetItemSet());
     }
 
     if (!pCachedPattern && !rDocImport.isLatinScript(mnScNumFmt))
@@ -2310,7 +2310,7 @@ Xf::createPattern( bool bSkipPoolDefs )
     if( mpPattern )
         return *mpPattern;
     mpPattern.reset( new 
::ScPatternAttr(getScDocument().getCellAttributeHelper()) );
-    SfxItemSet& rItemSet = mpPattern->GetItemSet();
+    SfxItemSet& rItemSet = mpPattern->GetItemSetWritable();
     /*  Enables the used flags, if the formatting attributes differ from the
         style XF. In cell XFs Excel uses the cell attributes, if they differ
         from the parent style XF (even if the used flag is switched off).
diff --git a/sc/source/filter/orcus/interface.cxx 
b/sc/source/filter/orcus/interface.cxx
index ce03a417bba1..ffd9068300b3 100644
--- a/sc/source/filter/orcus/interface.cxx
+++ b/sc/source/filter/orcus/interface.cxx
@@ -1146,7 +1146,7 @@ void ScOrcusSheet::set_format(os::row_t row, os::col_t 
col, size_t xf_index)
     SAL_INFO("sc.orcus.style", "set format: " << xf_index);
 
     ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper());
-    mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index);
+    mrStyles.applyXfToItemSet(aPattern.GetItemSetWritable(), xf_index);
     mrDoc.getDoc().ApplyPattern(col, row, mnTab, aPattern);
 }
 
@@ -1155,15 +1155,14 @@ void ScOrcusSheet::set_format(os::row_t row_start, 
os::col_t col_start, os::row_
 {
     SAL_INFO("sc.orcus.style", "set format range: " << xf_index);
     ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper());
-    mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index);
+    mrStyles.applyXfToItemSet(aPattern.GetItemSetWritable(), xf_index);
     mrDoc.getDoc().ApplyPatternAreaTab(col_start, row_start, col_end, row_end, 
mnTab, aPattern);
 }
 
 void ScOrcusSheet::set_column_format(os::col_t col, os::col_t col_span, 
std::size_t xf_index)
 {
     ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper());
-    mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index);
-
+    mrStyles.applyXfToItemSet(aPattern.GetItemSetWritable(), xf_index);
     mrDoc.getDoc().ApplyPatternAreaTab(col, 0, col + col_span - 1, 
mrDoc.getDoc().MaxRow(), mnTab,
                                        aPattern);
 }
@@ -1171,8 +1170,7 @@ void ScOrcusSheet::set_column_format(os::col_t col, 
os::col_t col_span, std::siz
 void ScOrcusSheet::set_row_format(os::row_t row, std::size_t xf_index)
 {
     ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper());
-    mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index);
-
+    mrStyles.applyXfToItemSet(aPattern.GetItemSetWritable(), xf_index);
     mrDoc.getDoc().ApplyPatternAreaTab(0, row, mrDoc.getDoc().MaxCol(), row, 
mnTab, aPattern);
 }
 
diff --git a/sc/source/filter/qpro/qprostyle.cxx 
b/sc/source/filter/qpro/qprostyle.cxx
index 5cd64c817447..e6d2ca927353 100644
--- a/sc/source/filter/qpro/qprostyle.cxx
+++ b/sc/source/filter/qpro/qprostyle.cxx
@@ -41,7 +41,7 @@ void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 
nCol, sal_uInt16 nRow,
         return;
 
     ScPatternAttr aPattern(pDoc->getCellAttributeHelper());
-    SfxItemSet& rItemSet = aPattern.GetItemSet();
+    SfxItemSet& rItemSet = aPattern.GetItemSetWritable();
 
     sal_uInt8 nTmp = maAlign[ nStyle ];
     sal_uInt8 nHor = ( nTmp & 0x07 );
diff --git a/sc/source/filter/rtf/eeimpars.cxx 
b/sc/source/filter/rtf/eeimpars.cxx
index 107f316c0496..38122bfc6669 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -219,7 +219,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, 
double nOutputFactor, SvNu
             // Set attributes
             ScPatternAttr* pAttr(new 
ScPatternAttr(mrDoc.getCellAttributeHelper()));
             pAttr->GetFromEditItemSet( &aSet );
-            SfxItemSet* pAttrItemSet = &pAttr->GetItemSet();
+            SfxItemSet* pAttrItemSet = &pAttr->GetItemSetWritable();
             if (!aNumStr.isEmpty())
             {
                 pAttrItemSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumForm 
) );
diff --git a/sc/source/filter/xml/xmlcelli.cxx 
b/sc/source/filter/xml/xmlcelli.cxx
index 5d1003d3f470..de7a16928f62 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -808,7 +808,7 @@ void ScXMLTableRowCellContext::SetContentValidation( const 
ScRange& rScRange )
     sal_uInt32 nIndex = pDoc->AddValidationEntry( aScValidationData );
 
     ScPatternAttr aPattern(pDoc->getCellAttributeHelper());
-    aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
+    aPattern.ItemSetPut(SfxUInt32Item(ATTR_VALIDDATA, nIndex));
     if( rScRange.aStart == rScRange.aEnd )  //for a single cell
     {
         pDoc->ApplyPattern( rScRange.aStart.Col(), rScRange.aStart.Row(),
diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx 
b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
index 502d467cc5b8..32a06e183d4c 100644
--- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
+++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
@@ -246,11 +246,11 @@ void AddressWalkerWriter::formatAsColumnHeader(SCCOL 
nCols)
     aBorderOuter.SetLine(&aLine, SvxBoxItemLine::TOP);
     aBorderOuter.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
 
-    aPattern.GetItemSet().Put(aHJustify);
-    aPattern.GetItemSet().Put(aVJustify);
-    aPattern.GetItemSet().Put(aWeight);
-    aPattern.GetItemSet().Put(aWrap);
-    aPattern.GetItemSet().Put(aBorderOuter);
+    aPattern.ItemSetPut(aHJustify);
+    aPattern.ItemSetPut(aVJustify);
+    aPattern.ItemSetPut(aWeight);
+    aPattern.ItemSetPut(aWrap);
+    aPattern.ItemSetPut(aBorderOuter);
 
     mrDocument.ApplyPatternAreaTab(mCurrentAddress.Col(), 
mCurrentAddress.Row(),
                                    mCurrentAddress.Col() + nCols - 1, 
mCurrentAddress.Row(),
@@ -266,7 +266,7 @@ void AddressWalkerWriter::formatTableBottom(SCCOL nCols)
     SvxBorderLine aLine;
     aLine.GuessLinesWidths(aLine.GetBorderLineStyle(), 
SvxBorderLineWidth::Thin);
     aBorderOuter.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
-    aPattern.GetItemSet().Put(aBorderOuter);
+    aPattern.ItemSetPut(aBorderOuter);
     mrDocument.ApplyPatternAreaTab(mCurrentAddress.Col(), 
mCurrentAddress.Row(),
                                    mCurrentAddress.Col() + nCols - 1, 
mCurrentAddress.Row(),
                                    mCurrentAddress.Tab(), aPattern);
diff --git a/sc/source/ui/docshell/arealink.cxx 
b/sc/source/ui/docshell/arealink.cxx
index 29360ad4956d..95f7f04d3f02 100644
--- a/sc/source/ui/docshell/arealink.cxx
+++ b/sc/source/ui/docshell/arealink.cxx
@@ -389,8 +389,8 @@ bool ScAreaLink::Refresh( const OUString& rNewFile, const 
OUString& rNewFilter,
                     //! ResetAttrib at document !!!
 
                     ScPatternAttr aPattern( rSrcDoc.getCellAttributeHelper() );
-                    aPattern.GetItemSet().Put( ScMergeAttr() );             // 
Defaults
-                    aPattern.GetItemSet().Put( ScMergeFlagAttr() );
+                    aPattern.ItemSetPut(ScMergeAttr());             // Defaults
+                    aPattern.ItemSetPut(ScMergeFlagAttr());
                     aClipDoc.ApplyPatternAreaTab( 0,0, 
rDoc.MaxCol(),rDoc.MaxRow(), nSrcTab, aPattern );
                 }
 
diff --git a/sc/source/ui/docshell/dbdocimp.cxx 
b/sc/source/ui/docshell/dbdocimp.cxx
index 75a207b615c5..64ea51194d58 100644
--- a/sc/source/ui/docshell/dbdocimp.cxx
+++ b/sc/source/ui/docshell/dbdocimp.cxx
@@ -453,7 +453,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const 
ScImportParam& rParam,
         if (rDoc.IsTabProtected(nTab))
         {
             ScPatternAttr aPattern(pImportDoc->getCellAttributeHelper());
-            aPattern.GetItemSet().Put( ScProtectionAttr( 
false,false,false,false ) );
+            aPattern.ItemSetPut(ScProtectionAttr(false,false,false,false));
             pImportDoc->ApplyPatternAreaTab( 0,0,rDoc.MaxCol(),rDoc.MaxRow(), 
nTab, aPattern );
         }
 
diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 1aed6cc9ae4a..06650e6b507e 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -1249,7 +1249,7 @@ void ScDocFunc::PutData( const ScAddress& rPos, 
ScEditEngineDefaulter& rEngine,
     ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
     aPattern.GetFromEditItemSet( &rEditAttr );
     aPattern.DeleteUnchanged( rDoc.GetPattern( rPos.Col(), rPos.Row(), 
rPos.Tab() ) );
-    aPattern.GetItemSet().ClearItem( ATTR_HOR_JUSTIFY );    // wasn't removed 
above if no edit object
+    aPattern.ItemSetClearItem(ATTR_HOR_JUSTIFY);    // wasn't removed above if 
no edit object
     if ( aPattern.GetItemSet().Count() > 0 )
     {
         ScMarkData aMark(rDoc.GetSheetLimits());
@@ -2794,7 +2794,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const 
ScMarkData* pTabMark,
         // not only for whole columns/rows
 
         ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-        aPattern.GetItemSet().Put( ScMergeFlagAttr() );
+        aPattern.ItemSetPut(ScMergeFlagAttr());
 
         rDoc.ApplyPatternArea( nExtendStartCol, nExtendStartRow, 
nMergeTestEndCol, nMergeTestEndRow, aMark, aPattern );
 
@@ -5132,7 +5132,7 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& 
rOption, bool bRecord, Sc
 
         const SfxPoolItem& rDefAttr = 
rDoc.GetPool()->GetUserOrPoolDefaultItem( ATTR_MERGE );
         ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-        aPattern.GetItemSet().Put( rDefAttr );
+        aPattern.ItemSetPut(rDefAttr);
         rDoc.ApplyPatternAreaTab( aRange.aStart.Col(), aRange.aStart.Row(),
                                    aRange.aEnd.Col(), aRange.aEnd.Row(), nTab,
                                    aPattern );
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index ab4cdd7b62cc..3615b735a873 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -837,12 +837,12 @@ SCTAB ScDocShell::MakeScenario( SCTAB nTab, const 
OUString& rName, const OUStrin
             //!     test for filter / buttons / merging
 
             ScPatternAttr aProtPattern(m_pDocument->getCellAttributeHelper());
-            aProtPattern.GetItemSet().Put( ScProtectionAttr( true ) );
+            aProtPattern.ItemSetPut(ScProtectionAttr(true));
             m_pDocument->ApplyPatternAreaTab( 0,0, 
m_pDocument->MaxCol(),m_pDocument->MaxRow(), nNewTab, aProtPattern );
 
             ScPatternAttr aPattern(m_pDocument->getCellAttributeHelper());
-            aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) );
-            aPattern.GetItemSet().Put( ScProtectionAttr( true ) );
+            aPattern.ItemSetPut(ScMergeFlagAttr(ScMF::Scenario));
+            aPattern.ItemSetPut(ScProtectionAttr(true));
             m_pDocument->ApplySelectionPattern( aPattern, aDestMark );
 
             if (!bCopyAll)
diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx
index 63d2026195b2..1227ad74a341 100644
--- a/sc/source/ui/docshell/docsh8.cxx
+++ b/sc/source/ui/docshell/docsh8.cxx
@@ -263,8 +263,7 @@ static void lcl_setScalesToColumns(ScDocument& rDoc, const 
vector<tools::Long>&
         }
 
         ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper());
-        SfxItemSet& rSet = aNewAttrs.GetItemSet();
-        rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat) );
+        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat));
         rDoc.ApplyPatternAreaTab(i, 0, i, rDoc.MaxRow(), 0, aNewAttrs);
     }
 }
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index d35e192a4bf7..97a25e0d91ae 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1026,8 +1026,7 @@ static bool lcl_PutString(
                 // ScDocument::SetTextCell() forces it by ScSetStringParam.
                 sal_uInt32 nFormat = 
rDoc.GetFormatTable()->GetStandardFormat(SvNumFormatType::TEXT);
                 ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper());
-                SfxItemSet& rSet = aNewAttrs.GetItemSet();
-                rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) );
+                aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, 
nFormat));
                 rDoc.ApplyPattern(nCol, nRow, nTab, aNewAttrs);
             }
             if (ScStringUtil::isMultiline(rStr))
diff --git a/sc/source/ui/theme/ThemeColorChanger.cxx 
b/sc/source/ui/theme/ThemeColorChanger.cxx
index bbe2f328f69c..aa4dd38e1f47 100644
--- a/sc/source/ui/theme/ThemeColorChanger.cxx
+++ b/sc/source/ui/theme/ThemeColorChanger.cxx
@@ -172,7 +172,7 @@ bool changeSheets(ScDocShell& rDocShell, ScTabViewShell* 
pViewShell, ScDrawLayer
                     continue;
 
                 ScPatternAttr aNewPattern(*pPattern);
-                auto& rItemSet = aNewPattern.GetItemSet();
+                auto& rItemSet = aNewPattern.GetItemSetWritable();
                 bool bItemChanged = changeCellItems(rItemSet, rColorSet);
                 bChanged = bChanged || bItemChanged;
 
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 4fa1085f2748..cfa044be993c 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -475,7 +475,7 @@ void ScUndoDeleteCells::DoChange( const bool bUndo )
                 ScMarkData aMarkData(rDoc.GetSheetLimits());
                 aMarkData.SelectOneTable( aWorkRange.aStart.Tab() );
                 ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-                aPattern.GetItemSet().Put( ScMergeFlagAttr() );
+                aPattern.ItemSetPut(ScMergeFlagAttr());
                 rDoc.ApplyPatternArea( aWorkRange.aStart.Col(), 
aWorkRange.aStart.Row(),
                     aWorkRange.aEnd.Col(),   aWorkRange.aEnd.Row(),
                     aMarkData, aPattern );
@@ -2389,7 +2389,7 @@ void ScUndoRemoveMerge::Redo()
 
             const SfxPoolItem& rDefAttr = 
rDoc.GetPool()->GetUserOrPoolDefaultItem( ATTR_MERGE );
             ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-            aPattern.GetItemSet().Put( rDefAttr );
+            aPattern.ItemSetPut(rDefAttr);
             rDoc.ApplyPatternAreaTab( rOption.mnStartCol, rOption.mnStartRow,
                     rOption.mnEndCol, rOption.mnEndRow, nTab,
                     aPattern );
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index ac2619b9ff13..724da8cd5676 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -247,7 +247,7 @@ void ScUndoEnterData::Undo()
         else
         {
             ScPatternAttr* pPattern(new 
ScPatternAttr(*rDoc.GetPattern(maPos.Col(), maPos.Row(), rVal.mnTab)));
-            pPattern->GetItemSet().ClearItem( ATTR_VALUE_FORMAT );
+            pPattern->ItemSetClearItem(ATTR_VALUE_FORMAT);
             rDoc.SetPattern(maPos.Col(), maPos.Row(), rVal.mnTab, 
CellAttributeHolder(pPattern, true));
         }
         rDocShell.PostPaintCell(maPos.Col(), maPos.Row(), rVal.mnTab);
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index e0ce8a80f45f..b6ecd0cce147 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -1975,7 +1975,7 @@ static void lcl_SetCellProperty( const 
SfxItemPropertyMapEntry& rEntry, const un
     rFirstItemId = rEntry.nWID;
     rSecondItemId = 0;
 
-    SfxItemSet& rSet = rPattern.GetItemSet();
+    SfxItemSet& rSet = rPattern.GetItemSetWritable();
     switch ( rEntry.nWID )
     {
         case ATTR_VALUE_FORMAT:
@@ -2112,7 +2112,7 @@ void ScCellRangesBase::SetOnePropertyValue( const 
SfxItemPropertyMapEntry* pEntr
             //  ClearInvalidItems, so that in any case we have an item with 
the correct type
 
             ScPatternAttr aPattern( *GetCurrentAttrsDeep() );
-            SfxItemSet& rSet = aPattern.GetItemSet();
+            SfxItemSet& rSet = aPattern.GetItemSetWritable();
             rSet.ClearInvalidItems();
 
             sal_uInt16 nFirstItem, nSecondItem;
@@ -2279,7 +2279,7 @@ void ScCellRangesBase::SetOnePropertyValue( const 
SfxItemPropertyMapEntry* pEntr
                             pNewData.reset();
 
                             ScPatternAttr 
aPattern(rDoc.getCellAttributeHelper());
-                            aPattern.GetItemSet().Put( SfxUInt32Item( 
ATTR_VALIDDATA, nIndex ) );
+                            aPattern.ItemSetPut(SfxUInt32Item(ATTR_VALIDDATA, 
nIndex));
                             pDocShell->GetDocFunc().ApplyAttributes( 
*GetMarkData(), aPattern, true );
                         }
                     }
@@ -2501,7 +2501,7 @@ void ScCellRangesBase::setValidation(const 
rtl::Reference<ScTableValidationObj>&
     pNewData.reset();
 
     ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-    aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
+    aPattern.ItemSetPut(SfxUInt32Item(ATTR_VALIDDATA, nIndex));
     pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), aPattern, true );
 }
 
@@ -2598,7 +2598,7 @@ void SAL_CALL ScCellRangesBase::setPropertyValues( const 
uno::Sequence< OUString
                 if ( !pOldPattern )
                 {
                     pOldPattern.reset(new ScPatternAttr( 
*GetCurrentAttrsDeep() ));
-                    pOldPattern->GetItemSet().ClearInvalidItems();
+                    pOldPattern->GetItemSetWritable().ClearInvalidItems();
                     pNewPattern.reset(new 
ScPatternAttr(rDoc.getCellAttributeHelper()));
                 }
 
@@ -2609,9 +2609,9 @@ void SAL_CALL ScCellRangesBase::setPropertyValues( const 
uno::Sequence< OUString
 
                 //  put only affected items into new set
                 if ( nFirstItem )
-                    pNewPattern->GetItemSet().Put( 
pOldPattern->GetItemSet().Get( nFirstItem ) );
+                    
pNewPattern->ItemSetPut(pOldPattern->GetItemSet().Get(nFirstItem));
                 if ( nSecondItem )
-                    pNewPattern->GetItemSet().Put( 
pOldPattern->GetItemSet().Get( nSecondItem ) );
+                    
pNewPattern->ItemSetPut(pOldPattern->GetItemSet().Get(nSecondItem));
             }
             else if ( pEntry->nWID != SC_WID_UNO_CELLSTYL )   // CellStyle is 
handled above
             {
@@ -2734,7 +2734,7 @@ uno::Sequence< beans::SetPropertyTolerantFailed > 
SAL_CALL ScCellRangesBase::set
                     if ( !pOldPattern )
                     {
                         pOldPattern.reset(new ScPatternAttr( 
*GetCurrentAttrsDeep() ));
-                        pOldPattern->GetItemSet().ClearInvalidItems();
+                        pOldPattern->GetItemSetWritable().ClearInvalidItems();
                         pNewPattern.reset(new 
ScPatternAttr(rDoc.getCellAttributeHelper()));
                     }
 
@@ -2746,9 +2746,9 @@ uno::Sequence< beans::SetPropertyTolerantFailed > 
SAL_CALL ScCellRangesBase::set
 
                         //  put only affected items into new set
                         if ( nFirstItem )
-                            pNewPattern->GetItemSet().Put( 
pOldPattern->GetItemSet().Get( nFirstItem ) );
+                            
pNewPattern->ItemSetPut(pOldPattern->GetItemSet().Get(nFirstItem));
                         if ( nSecondItem )
-                            pNewPattern->GetItemSet().Put( 
pOldPattern->GetItemSet().Get( nSecondItem ) );
+                            
pNewPattern->ItemSetPut(pOldPattern->GetItemSet().Get(nSecondItem));
                     }
                     catch ( lang::IllegalArgumentException& )
                     {
@@ -5828,7 +5828,7 @@ void ScCellObj::InputEnglishString( const OUString& rText 
)
             if (nNewFormat != nOldFormat)
             {
                 ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-                aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, 
nNewFormat ) );
+                aPattern.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, 
nNewFormat));
                 // ATTR_LANGUAGE_FORMAT remains unchanged
                 rFunc.ApplyAttributes( *GetMarkData(), aPattern, true );
             }
@@ -7519,8 +7519,8 @@ void SAL_CALL ScTableSheetObj::addRanges( const 
uno::Sequence<table::CellRangeAd
 
     //  Scenario ranges are tagged with attribute
     ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-    aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) );
-    aPattern.GetItemSet().Put( ScProtectionAttr( true ) );
+    aPattern.ItemSetPut(ScMergeFlagAttr(ScMF::Scenario));
+    aPattern.ItemSetPut(ScProtectionAttr(true));
     pDocSh->GetDocFunc().ApplyAttributes( aMarkData, aPattern, true );
 }
 
diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index 7e301b4b3984..40628e0ea1fe 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -154,8 +154,8 @@ static bool lcl_CopyData( ScDocument* pSrcDoc, const 
ScRange& rSrcRange,
                                 HasAttrFlags::Merged | 
HasAttrFlags::Overlapped ) )
     {
         ScPatternAttr aPattern(pSrcDoc->getCellAttributeHelper());
-        aPattern.GetItemSet().Put( ScMergeAttr() );             // Defaults
-        aPattern.GetItemSet().Put( ScMergeFlagAttr() );
+        aPattern.ItemSetPut(ScMergeAttr());             // Defaults
+        aPattern.ItemSetPut(ScMergeFlagAttr());
         pClipDoc->ApplyPatternAreaTab( 0,0, pClipDoc->MaxCol(), 
pClipDoc->MaxRow(), nSrcTab, aPattern );
     }
 
diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index 192bb2d996fd..ca9d6f38695a 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -2080,7 +2080,7 @@ void ScDBFunc::ShowDataPilotSourceData( ScDPObject& 
rDPObj, const Sequence<sheet
             continue;
 
         ScPatternAttr aPattern(pInsDoc->getCellAttributeHelper());
-        aPattern.GetItemSet().Put( SfxUInt32Item(ATTR_VALUE_FORMAT, 
static_cast<sal_uInt32>(nNumFmt)) );
+        aPattern.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, 
static_cast<sal_uInt32>(nNumFmt)));
         pInsDoc->ApplyPatternAreaTab(nCol, 1, nCol, nRowSize-1, nNewTab, 
aPattern);
     }
 
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 66df2025835a..25118bf6f54f 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -180,7 +180,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
             SfxItemSet aItemSet( GetPool() );
 
             ScPatternAttr 
aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper());
-            SfxItemSet& rNewSet = aNewAttrs.GetItemSet();
+            SfxItemSet& rNewSet = aNewAttrs.GetItemSetWritable();
             rNewSet.Put( aItemSet, false );
 
             rDoc.ApplySelectionPattern( aNewAttrs, rDoc.GetPreviewSelection() 
);
@@ -203,7 +203,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq )
             SfxItemSet aItemSet( GetPool() );
 
             ScPatternAttr 
aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper());
-            SfxItemSet& rNewSet = aNewAttrs.GetItemSet();
+            SfxItemSet& rNewSet = aNewAttrs.GetItemSetWritable();
             rNewSet.Put( aItemSet, false );
             rDoc.ApplySelectionPattern( aNewAttrs, aPreviewMark );
             pTabViewShell->UpdateSelectionArea(aPreviewMark, &aAttr, 
/*adjustHeight*/ false);
@@ -333,11 +333,10 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
                     {
                         const SvNumberformat* pNewEntry = 
pFormatter->GetEntry( nNewFormat );
                         ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper());
-                        SfxItemSet& rSet = aNewAttrs.GetItemSet();
                         LanguageType eNewLang = pNewEntry ? 
pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW;
                         if ( eNewLang != eOldLang && eNewLang != 
LANGUAGE_DONTKNOW )
-                            rSet.Put( SvxLanguageItem( eNewLang, 
ATTR_LANGUAGE_FORMAT ) );
-                        rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat 
) );
+                            aNewAttrs.ItemSetPut(SvxLanguageItem(eNewLang, 
ATTR_LANGUAGE_FORMAT));
+                        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, 
nNewFormat));
                         pTabViewShell->ApplySelectionPattern( aNewAttrs );
                     }
                     else
@@ -1913,9 +1912,8 @@ void ScFormatShell::ExecuteTextDirection( const 
SfxRequest& rReq )
         {
             bool bVert = (nSlot == SID_TEXTDIRECTION_TOP_TO_BOTTOM);
             ScPatternAttr 
aAttr(GetViewData().GetDocument().getCellAttributeHelper());
-            SfxItemSet& rItemSet = aAttr.GetItemSet();
-            rItemSet.Put( ScVerticalStackCell( bVert ) );
-            rItemSet.Put( SfxBoolItem( ATTR_VERTICAL_ASIAN, bVert ) );
+            aAttr.ItemSetPut(ScVerticalStackCell(bVert));
+            aAttr.ItemSetPut(SfxBoolItem(ATTR_VERTICAL_ASIAN, bVert));
             pTabViewShell->ApplySelectionPattern( aAttr );
             pTabViewShell->AdjustBlockHeight();
         }
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 64c9e9b5c1d4..c0ea776687c9 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -1742,11 +1742,11 @@ void ScOutputData::LayoutStringsImpl(bool const 
bPixelToLogic, RowInfo* const pT
             else if ( SfxItemSet* pFontSet = mpDoc->GetPreviewFont( nCellX, 
nCellY, mnTab ) )
             {
                 if ( const SvxFontItem* pItem = pFontSet->GetItemIfSet( 
ATTR_FONT ) )
-                    pAltPattern->GetItemSet().Put( *pItem );
+                    pAltPattern->ItemSetPut( *pItem );
                 if ( const SvxFontItem* pItem = pFontSet->GetItemIfSet( 
ATTR_CJK_FONT ) )
-                    pAltPattern->GetItemSet().Put( *pItem );
+                    pAltPattern->ItemSetPut( *pItem );
                 if ( const SvxFontItem* pItem = pFontSet->GetItemIfSet( 
ATTR_CTL_FONT ) )
-                    pAltPattern->GetItemSet().Put( *pItem );
+                    pAltPattern->ItemSetPut( *pItem );
             }
             pPattern = pAltPattern;
         }
@@ -1758,7 +1758,7 @@ void ScOutputData::LayoutStringsImpl(bool const 
bPixelToLogic, RowInfo* const pT
             aAltPatterns.push_back(std::make_unique<ScPatternAttr>(*pPattern));
             ScPatternAttr* pAltPattern = aAltPatterns.back().get();
             ScLineBreakCell aLineBreak(false);
-            pAltPattern->GetItemSet().Put(aLineBreak);
+            pAltPattern->ItemSetPut(aLineBreak);
             pPattern = pAltPattern;
         }
 
diff --git a/sc/source/ui/view/spelleng.cxx b/sc/source/ui/view/spelleng.cxx
index edb894a29432..670091f46401 100644
--- a/sc/source/ui/view/spelleng.cxx
+++ b/sc/source/ui/view/spelleng.cxx
@@ -141,7 +141,7 @@ bool ScConversionEngineBase::FindNextConversionCell()
                     else
                         pNewAttr = new 
ScPatternAttr(mrDoc.getCellAttributeHelper());
 
-                    pNewAttr->GetItemSet().Put(SvxLanguageItem(aLang.nLang, 
ATTR_FONT_LANGUAGE));
+                    pNewAttr->ItemSetPut(SvxLanguageItem(aLang.nLang, 
ATTR_FONT_LANGUAGE));
                     mrDoc.SetPattern(aPos, CellAttributeHolder(pNewAttr, 
true));
                 }
 
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 3e2f1b2d3489..6e4792a4159e 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -958,7 +958,7 @@ void ScViewFunc::EnterBlock( const OUString& rString, const 
EditTextObject* pDat
         // MarkData was already MarkToSimple'ed in PasteFromClip
         const ScRange& aRange = rMark.GetMarkArea();
         ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-        aPattern.GetItemSet().Put( *pItem );
+        aPattern.ItemSetPut(*pItem);
         SvNumFormatType nNewType = rDoc.GetFormatTable()->GetType( 
pItem->GetValue() );
         rDoc.ApplyPatternIfNumberformatIncompatible( aRange, rMark,
             aPattern, nNewType );
@@ -2390,8 +2390,8 @@ void ScViewFunc::ExtendScenario()
 
     ScDocument& rDoc = GetViewData().GetDocument();
     ScPatternAttr aPattern(rDoc.getCellAttributeHelper());
-    aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) );
-    aPattern.GetItemSet().Put( ScProtectionAttr( true ) );
+    aPattern.ItemSetPut(ScMergeFlagAttr(ScMF::Scenario));
+    aPattern.ItemSetPut(ScProtectionAttr(true));
     ApplySelectionPattern(aPattern);
 }
 
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 63513f83604c..afc6009a03e5 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -586,7 +586,7 @@ void finalizeFormulaProcessing(const 
std::shared_ptr<FormulaProcessingContext>&
                 const LanguageType nLang = (pEntry ? pEntry->GetLanguage() : 
ScGlobal::eLnge);
                 const sal_uInt32 nFormat = pFormatter->GetStandardFormat( 
SvNumFormatType::NUMBER, nLang);
                 ScPatternAttr 
aPattern(context->GetDoc().getCellAttributeHelper());
-                aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, 
nFormat));
+                aPattern.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat));
                 ScMarkData aMark(context->GetDoc().GetSheetLimits());
                 aMark.SelectTable( i, true);
                 aMark.SetMarkArea( ScRange( *(context->aPos)));
@@ -1115,14 +1115,15 @@ void ScViewFunc::ApplyAttributes( const SfxItemSet& 
rDialogSet,
                 pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW;
             if ( eNewLang != eOldLang )
             {
-                aNewAttrs.GetItemSet().Put(
-                    SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) );
+                aNewAttrs.ItemSetPut(SvxLanguageItem(eNewLang, 
ATTR_LANGUAGE_FORMAT));
 
                 //  only the language has changed -> do not touch 
numberformat-attribute
                 sal_uInt32 nNewMod = nNewFormat % SV_COUNTRY_LANGUAGE_OFFSET;
                 if ( nNewMod == ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) &&
                      nNewMod <= SV_MAX_COUNT_STANDARD_FORMATS )
-                    aNewAttrs.GetItemSet().ClearItem( ATTR_VALUE_FORMAT );
+                {
+                    aNewAttrs.ItemSetClearItem(ATTR_VALUE_FORMAT);
+                }
             }
         }
     }
@@ -1135,7 +1136,6 @@ void ScViewFunc::ApplyAttributes( const SfxItemSet& 
rDialogSet,
     const SvxBoxItem&     rNewOuter = rDialogSet.Get(ATTR_BORDER);
     const SvxBoxInfoItem& rOldInner = rOldSet.Get(ATTR_BORDER_INNER);
     const SvxBoxInfoItem& rNewInner = rDialogSet.Get(ATTR_BORDER_INNER);
-    SfxItemSet&           rNewSet   = aNewAttrs.GetItemSet();
 
     // protect referenced Items from disappearing (was: don't delete yet)
     const SfxPoolItemHolder aHoldOuter(*rDialogSet.GetPool() , &rNewOuter);
@@ -1143,8 +1143,8 @@ void ScViewFunc::ApplyAttributes( const SfxItemSet& 
rDialogSet,
     (void)aHoldOuter;
     (void)aHoldInner;
 
-    rNewSet.ClearItem( ATTR_BORDER );
-    rNewSet.ClearItem( ATTR_BORDER_INNER );
+    aNewAttrs.ItemSetClearItem(ATTR_BORDER);
+    aNewAttrs.ItemSetClearItem(ATTR_BORDER_INNER);
 
     /*
      * establish whether border attribute is to be set:
@@ -1206,10 +1206,10 @@ void ScViewFunc::ApplyAttr( const SfxPoolItem& 
rAttrItem, bool bAdjustBlockHeigh
     ScDocument& rDoc = GetViewData().GetDocument();
     ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper());
 
-    aNewAttrs.GetItemSet().Put( rAttrItem );
+    aNewAttrs.ItemSetPut(rAttrItem);
     //  if justify is set (with Buttons), always indentation 0
     if ( rAttrItem.Which() == ATTR_HOR_JUSTIFY )
-        aNewAttrs.GetItemSet().Put( ScIndentItem( 0 ) );
+        aNewAttrs.ItemSetPut(ScIndentItem(0));
     ApplySelectionPattern( aNewAttrs );
 
     // Prevent useless compute
@@ -1514,7 +1514,7 @@ void ScViewFunc::ApplyUserItemSet( const SfxItemSet& 
rItemSet )
     }
 
     ScPatternAttr 
aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper());
-    SfxItemSet& rNewSet = aNewAttrs.GetItemSet();
+    SfxItemSet& rNewSet = aNewAttrs.GetItemSetWritable();
     rNewSet.Put( rItemSet, false );
     ApplySelectionPattern( aNewAttrs );
 
@@ -2893,8 +2893,7 @@ void ScViewFunc::SetNumberFormat( SvNumFormatType 
nFormatType, sal_uLong nAdd )
 
     nNumberFormat = pNumberFormatter->GetStandardFormat( nFormatType, 
eLanguage ) + nAdd;
 
-    SfxItemSet& rSet = aNewAttrs.GetItemSet();
-    rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumberFormat ) );
+    aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nNumberFormat));
     //  ATTR_LANGUAGE_FORMAT not
     ApplySelectionPattern( aNewAttrs );
 }
@@ -2937,9 +2936,8 @@ void ScViewFunc::SetNumFmtByStr( const OUString& rCode )
     if ( bOk )          // valid format?
     {
         ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper());
-        SfxItemSet& rSet = aNewAttrs.GetItemSet();
-        rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumberFormat ) );
-        rSet.Put( SvxLanguageItem( eLanguage, ATTR_LANGUAGE_FORMAT ) );
+        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nNumberFormat));
+        aNewAttrs.ItemSetPut(SvxLanguageItem(eLanguage, ATTR_LANGUAGE_FORMAT));
         ApplySelectionPattern( aNewAttrs );
     }
 
@@ -3070,8 +3068,7 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement )
     if (!bError)
     {
         ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper());
-        SfxItemSet& rSet = aNewAttrs.GetItemSet();
-        rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
+        aNewAttrs.ItemSetPut(SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat));
         //  ATTR_LANGUAGE_FORMAT not
         ApplySelectionPattern( aNewAttrs );
     }

Reply via email to