diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index 667212d8..98dc1739 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -750,8 +750,7 @@ void cell::format(const class format new_format) format().d_->references -= format().d_->references > 0 ? 1 : 0; } - ++new_format.d_->references; - d_->format_ = new_format.d_; + d_->format_ = detail::reference(new_format.d_); } calendar cell::base_date() const diff --git a/source/detail/implementations/stylesheet.hpp b/source/detail/implementations/stylesheet.hpp index 0ec45161..9863909d 100644 --- a/source/detail/implementations/stylesheet.hpp +++ b/source/detail/implementations/stylesheet.hpp @@ -419,6 +419,7 @@ struct stylesheet if (pattern->references == 0) { *pattern = new_format; + return pattern; } return find_or_create(new_format); } @@ -431,6 +432,7 @@ struct stylesheet if (pattern->references == 0) { *pattern = new_format; + return pattern; } return find_or_create(new_format); } @@ -443,6 +445,7 @@ struct stylesheet if (pattern->references == 0) { *pattern = new_format; + return pattern; } return find_or_create(new_format); } @@ -455,6 +458,7 @@ struct stylesheet if (pattern->references == 0) { *pattern = new_format; + return pattern; } return find_or_create(new_format); } @@ -467,6 +471,7 @@ struct stylesheet if (pattern->references == 0) { *pattern = new_format; + return pattern; } return find_or_create(new_format); } @@ -483,6 +488,7 @@ struct stylesheet if (pattern->references == 0) { *pattern = new_format; + return pattern; } return find_or_create(new_format); } @@ -495,6 +501,7 @@ struct stylesheet if (pattern->references == 0) { *pattern = new_format; + return pattern; } return find_or_create(new_format); } @@ -577,5 +584,15 @@ struct stylesheet std::vector colors; }; +inline format_impl* reference(format_impl *impl) +{ + ++impl->references; + if (impl->references == 1) + { + impl = impl->parent->find_or_create(*impl); + } + return impl; +} + } // namespace detail } // namespace xlnt