diff options
author | Gülşah Köse <gulsah.kose@collabora.com> | 2019-03-25 21:08:22 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2019-05-04 10:21:44 +0200 |
commit | 8c637b47d9de4b3a64c33a9c2ffe7ed220be2467 (patch) | |
tree | 1657f72af2c99ebd0cdc027730fbb31e81eeefe7 /sc/source/filter/oox | |
parent | c2ebd00b653c77985af36accde4b647b5279cb28 (diff) |
tdf#122590 Import and export xlsx x14:cfRule element for type = cellis.
Change-Id: I3d940269ec25657b64c714400a2828781dd9dd3e
Reviewed-on: https://gerrit.libreoffice.org/69713
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sc/source/filter/oox')
-rw-r--r-- | sc/source/filter/oox/condformatbuffer.cxx | 5 | ||||
-rw-r--r-- | sc/source/filter/oox/extlstcontext.cxx | 64 | ||||
-rw-r--r-- | sc/source/filter/oox/stylesbuffer.cxx | 35 | ||||
-rw-r--r-- | sc/source/filter/oox/stylesfragment.cxx | 13 |
4 files changed, 110 insertions, 7 deletions
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx index b6392bed7a8d..5750cce50592 100644 --- a/sc/source/filter/oox/condformatbuffer.cxx +++ b/sc/source/filter/oox/condformatbuffer.cxx @@ -39,6 +39,7 @@ #include <document.hxx> #include <tokenarray.hxx> #include <tokenuno.hxx> +#include <extlstcontext.hxx> namespace oox { namespace xls { @@ -1096,7 +1097,7 @@ void CondFormatBuffer::finalizeImport() { for( const auto& rxCondFormat : maCondFormats ) { - if ( rxCondFormat.get() ) + if ( rxCondFormat.get()) rxCondFormat.get()->finalizeImport(); } for ( const auto& rxCfRule : maCfRules ) @@ -1128,6 +1129,8 @@ void CondFormatBuffer::finalizeImport() pFormat->AddEntry(rxEntry->Clone(pDoc)); } } + + rStyleIdx = 0; // Resets <extlst> <cfRule> style index. } CondFormatRef CondFormatBuffer::importCondFormatting( SequenceInputStream& rStrm ) diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx index d0840dddf6a4..1d1bc8341fd5 100644 --- a/sc/source/filter/oox/extlstcontext.cxx +++ b/sc/source/filter/oox/extlstcontext.cxx @@ -20,11 +20,16 @@ #include <document.hxx> #include <worksheetfragment.hxx> #include <workbookfragment.hxx> +#include <stylesbuffer.hxx> +#include <stylesfragment.hxx> #include <rangeutl.hxx> #include <sal/log.hxx> using ::oox::core::ContextHandlerRef; +using ::oox::xls::CondFormatBuffer; + +sal_Int32 rStyleIdx = 0; namespace oox { namespace xls { @@ -79,6 +84,7 @@ void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs ) ExtConditionalFormattingContext::ExtConditionalFormattingContext(WorksheetContextBase& rFragment): WorksheetContextBase(rFragment) { + isPreviousElementF = false; } ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nElement, const AttributeList& rAttribs) @@ -98,6 +104,7 @@ ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nEl { OUString aType = rAttribs.getString(XML_type, OUString()); OUString aId = rAttribs.getString(XML_id, OUString()); + if (aType == "dataBar") { // an ext entry does not need to have an existing corresponding entry @@ -119,12 +126,22 @@ ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nEl maEntries.push_back(std::make_unique<ScIconSetFormat>(pDoc)); return new IconSetContext(*this, mpCurrentRule.get()); } + else if (aType == "cellIs") + { + sal_Int32 aToken = rAttribs.getToken( XML_operator, XML_TOKEN_INVALID ); + eOperator = CondFormatBuffer::convertToInternalOperator(aToken); + return this; + } else { SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType); } } - else if (nElement == XM_TOKEN(sqref)) + else if (nElement == XLS14_TOKEN( dxf )) + { + return new DxfContext( *this, getStyles().createExtDxf() ); + } + else if (nElement == XM_TOKEN( sqref ) || nElement == XM_TOKEN( f )) { return this; } @@ -132,26 +149,43 @@ ContextHandlerRef ExtConditionalFormattingContext::onCreateContext(sal_Int32 nEl return nullptr; } -void ExtConditionalFormattingContext::onStartElement(const AttributeList& /*rAttribs*/) +void ExtConditionalFormattingContext::onStartElement(const AttributeList& /*Attribs*/) +{ +} + +void ExtConditionalFormattingContext::onCharacters(const OUString& rCharacters) { switch (getCurrentElement()) { + case XM_TOKEN(f): + { + aChars = rCharacters; + isPreviousElementF = true; + } + break; case XM_TOKEN(sqref): { + aChars = rCharacters; } break; } -} -void ExtConditionalFormattingContext::onCharacters(const OUString& rCharacters) -{ - aChars = rCharacters; } void ExtConditionalFormattingContext::onEndElement() { switch (getCurrentElement()) { + case XM_TOKEN(f): + { + rFormulas.push_back(aChars); + } + break; + case XLS14_TOKEN( cfRule ): + { + getStyles().getExtDxfs().forEachMem( &Dxf::finalizeImport ); + } + break; case XM_TOKEN(sqref): { ScRangeList aRange; @@ -167,8 +201,26 @@ void ExtConditionalFormattingContext::onEndElement() aRange[i].aEnd.SetTab(nTab); } + if(isPreviousElementF) // sqref can be alone in some cases. + { + for(const OUString& rFormula : rFormulas) + { + ScAddress rPos = aRange.GetTopLeftCorner(); + rStyle = getStyles().createExtDxfStyle(rStyleIdx); + ScCondFormatEntry* pEntry = new ScCondFormatEntry(eOperator, rFormula, "", pDoc, + rPos, rStyle, "", "", + formula::FormulaGrammar::GRAM_OOXML , + formula::FormulaGrammar::GRAM_OOXML, + ScFormatEntry::Type::ExtCondition ); + maEntries.push_back(std::unique_ptr<ScFormatEntry>(pEntry)); + rStyleIdx++; + } + rFormulas.clear(); + } + std::vector< std::unique_ptr<ExtCfCondFormat> >& rExtFormats = getCondFormats().importExtCondFormat(); rExtFormats.push_back(std::make_unique<ExtCfCondFormat>(aRange, maEntries)); + isPreviousElementF = false; } break; default: diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index bb5e6f934f19..5e808c8c9a8e 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -2753,6 +2753,13 @@ DxfRef StylesBuffer::createDxf() return xDxf; } +DxfRef StylesBuffer::createExtDxf() +{ + DxfRef xDxf( new Dxf( *this ) ); + maExtDxfs.push_back( xDxf ); + return xDxf; +} + void StylesBuffer::importPaletteColor( const AttributeList& rAttribs ) { maPalette.importPaletteColor( rAttribs ); @@ -2903,6 +2910,34 @@ OUString StylesBuffer::createDxfStyle( sal_Int32 nDxfId ) const rStyleSheet.GetItemSet(); pDxf->fillToItemSet(rStyleItemSet); + + } + + // on error: fallback to default style + if (rStyleName.isEmpty()) + rStyleName = maCellStyles.getDefaultStyleName(); + + return rStyleName; +} + +OUString StylesBuffer::createExtDxfStyle( sal_Int32 nDxfId ) const +{ + OUString rStyleName; + + if (Dxf* pDxf = maExtDxfs.get(nDxfId).get()) + { + rStyleName = "ExtConditionalStyle_" + OUString::number(nDxfId + 1); + + // Create a cell style. This may overwrite an existing style if + // one with the same name exists. + ScStyleSheet& rStyleSheet = ScfTools::MakeCellStyleSheet( + *getScDocument().GetStyleSheetPool(), rStyleName, true); + + rStyleSheet.ResetParent(); + SfxItemSet& rStyleItemSet = + rStyleSheet.GetItemSet(); + + pDxf->fillToItemSet(rStyleItemSet); } // on error: fallback to default style diff --git a/sc/source/filter/oox/stylesfragment.cxx b/sc/source/filter/oox/stylesfragment.cxx index 9efcbc45e703..2c2c9968703d 100644 --- a/sc/source/filter/oox/stylesfragment.cxx +++ b/sc/source/filter/oox/stylesfragment.cxx @@ -157,6 +157,19 @@ ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const Attribu } break; } + + if( mxExtDxf.get() ) switch( getCurrentElement() ) + { + case XLS14_TOKEN( dxf ): + switch( nElement ) + { + case XLS_TOKEN( font ): return new FontContext( *this, mxExtDxf->createFont() ); + case XLS_TOKEN( border ): return new BorderContext( *this, mxExtDxf->createBorder() ); + case XLS_TOKEN( fill ): return new FillContext( *this, mxExtDxf->createFill() ); + case XLS_TOKEN( numFmt ): mxExtDxf->importNumFmt( rAttribs ); break; + } + break; + } return nullptr; } |