diff --git a/sc/qa/unit/data/xlsx/tdf122945_TabColorProtectedSheet.xlsx b/sc/qa/unit/data/xlsx/tdf122945_TabColorProtectedSheet.xlsx new file mode 100644 index 000000000000..09558ae59710 Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf122945_TabColorProtectedSheet.xlsx differ diff --git a/sc/qa/unit/subsequent_filters_test2.cxx b/sc/qa/unit/subsequent_filters_test2.cxx index bfee79ae8332..139708add9ef 100644 --- a/sc/qa/unit/subsequent_filters_test2.cxx +++ b/sc/qa/unit/subsequent_filters_test2.cxx @@ -1814,6 +1814,32 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf66377) CPPUNIT_ASSERT_EQUAL(Color(COL_TRANSPARENT), rColor);*/ } +CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf122945TabColorProtectedSheet) +{ + createScDoc("xlsx/tdf122945_TabColorProtectedSheet.xlsx"); + + ScDocument* pDoc = getScDoc(); + CPPUNIT_ASSERT(pDoc->IsTabProtected(0)); + + // Without the fix in place, this test would have failed with + // - Expected: rgba[ff0000ff] (RED) + // - Actual : rgba[ffffff00] (COL_AUTO) + // i.e. the sheet protection prevented the import of the tab color + CPPUNIT_ASSERT_EQUAL(Color(0xFF0000), pDoc->GetTabBgColor(0)); + + saveAndReload(TestFilter::XLSX); + + // check that the tab color was exported correctly + xmlDocUniquePtr pSheet = parseExport(u"xl/worksheets/sheet1.xml"_ustr); + CPPUNIT_ASSERT(pSheet); + assertXPath(pSheet, "/x:worksheet/x:sheetPr/x:tabColor", "rgb", u"FFFF0000"); + + // check that sheet protection and tab color are still present after save and reload + pDoc = getScDoc(); + CPPUNIT_ASSERT(pDoc->IsTabProtected(0)); + CPPUNIT_ASSERT_EQUAL(Color(0xFF0000), pDoc->GetTabBgColor(0)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/oox/worksheetsettings.cxx b/sc/source/filter/oox/worksheetsettings.cxx index ab079b2bface..d23c81f19ca3 100644 --- a/sc/source/filter/oox/worksheetsettings.cxx +++ b/sc/source/filter/oox/worksheetsettings.cxx @@ -286,7 +286,8 @@ void WorksheetSettings::finalizeImport() if( !maSheetSettings.maTabColor.isAuto() ) { ::Color nColor = maSheetSettings.maTabColor.getColor( getBaseFilter().getGraphicHelper() ); - xSheet->setPropertyValue( u"TabColor"_ustr, Any(nColor) ); + // tdf#122945 - set the color directly to avoid sheet protection preventing the import + getScDocument().SetTabBgColor(getSheetIndex(), nColor); } // Summary data below or above the contents