diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-11-29 22:35:15 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-11-29 22:35:47 -0500 |
commit | 7f2fcde9e12164b72f775fa4e2b30bebe7c37311 (patch) | |
tree | a525ce6c0f56502f796a34ae49d8b905c04fff5d /sc | |
parent | sal_Bool to bool. (diff) | |
download | core-7f2fcde9e12164b72f775fa4e2b30bebe7c37311.tar.gz core-7f2fcde9e12164b72f775fa4e2b30bebe7c37311.zip |
Export multi-value filters to xlsx.
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/excel/excrecds.cxx | 81 | ||||
-rw-r--r-- | sc/source/filter/inc/excrecds.hxx | 6 |
2 files changed, 67 insertions, 20 deletions
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx index 80368210921a..ebd2b4ee3f5e 100644 --- a/sc/source/filter/excel/excrecds.cxx +++ b/sc/source/filter/excel/excrecds.cxx @@ -652,6 +652,7 @@ void ExcFilterCondition::SaveText( XclExpStream& rStrm ) XclExpAutofilter::XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC ) : XclExpRecord( EXC_ID_AUTOFILTER, 24 ), XclExpRoot( rRoot ), + meType(FilterCondition), nCol( nC ), nFlags( 0 ) { @@ -674,14 +675,26 @@ bool XclExpAutofilter::AddCondition( ScQueryConnect eConn, sal_uInt8 nType, sal_ AddRecSize( aCond[ nInd ].GetTextBytes() ); - return sal_True; + return true; +} + +bool XclExpAutofilter::HasCondition() const +{ + return !aCond[0].IsEmpty(); } bool XclExpAutofilter::AddEntry( const ScQueryEntry& rEntry ) { + const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems(); + if (rItems.empty()) + return true; + + if (GetOutput() != EXC_OUTPUT_BINARY && rItems.size() > 1) + return AddMultiValueEntry(rEntry); + bool bConflict = false; String sText; - const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); + const ScQueryEntry::Item& rItem = rItems[0]; const rtl::OUString& rQueryStr = rItem.maString; if (!rQueryStr.isEmpty()) { @@ -785,6 +798,17 @@ bool XclExpAutofilter::AddEntry( const ScQueryEntry& rEntry ) return bConflict; } +bool XclExpAutofilter::AddMultiValueEntry( const ScQueryEntry& rEntry ) +{ + meType = MultiValue; + const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems(); + ScQueryEntry::QueryItemsType::const_iterator itr = rItems.begin(), itrEnd = rItems.end(); + for (; itr != itrEnd; ++itr) + maMultiValues.push_back(itr->maString); + + return false; +} + void XclExpAutofilter::WriteBody( XclExpStream& rStrm ) { rStrm << nCol << nFlags; @@ -796,7 +820,7 @@ void XclExpAutofilter::WriteBody( XclExpStream& rStrm ) void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm ) { - if( !HasCondition() ) + if (meType == FilterCondition && !HasCondition()) return; sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); @@ -807,24 +831,43 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm ) // OOXTODO: XML_showButton, FSEND ); - if( HasTop10() ) + switch (meType) { - rWorksheet->singleElement( XML_top10, - XML_top, XclXmlUtils::ToPsz( get_flag( nFlags, EXC_AFFLAG_TOP10TOP ) ), - XML_percent, XclXmlUtils::ToPsz( get_flag( nFlags, EXC_AFFLAG_TOP10PERC ) ), - XML_val, OString::valueOf( (sal_Int32) (nFlags >> 7 ) ).getStr(), - // OOXTODO: XML_filterVal, - FSEND ); - } + case FilterCondition: + { + if( HasTop10() ) + { + rWorksheet->singleElement( XML_top10, + XML_top, XclXmlUtils::ToPsz( get_flag( nFlags, EXC_AFFLAG_TOP10TOP ) ), + XML_percent, XclXmlUtils::ToPsz( get_flag( nFlags, EXC_AFFLAG_TOP10PERC ) ), + XML_val, OString::valueOf( (sal_Int32) (nFlags >> 7 ) ).getStr(), + // OOXTODO: XML_filterVal, + FSEND ); + } - rWorksheet->startElement( XML_customFilters, - XML_and, XclXmlUtils::ToPsz( (nFlags & EXC_AFFLAG_ANDORMASK) == EXC_AFFLAG_AND ), - FSEND ); - aCond[ 0 ].SaveXml( rStrm ); - aCond[ 1 ].SaveXml( rStrm ); - rWorksheet->endElement( XML_customFilters ); - // OOXTODO: XLM_colorFilter, XML_dynamicFilter, - // XML_extLst, XML_filters, XML_iconFilter, XML_top10 + rWorksheet->startElement( XML_customFilters, + XML_and, XclXmlUtils::ToPsz( (nFlags & EXC_AFFLAG_ANDORMASK) == EXC_AFFLAG_AND ), + FSEND ); + aCond[ 0 ].SaveXml( rStrm ); + aCond[ 1 ].SaveXml( rStrm ); + rWorksheet->endElement( XML_customFilters ); + // OOXTODO: XLM_colorFilter, XML_dynamicFilter, + // XML_extLst, XML_filters, XML_iconFilter, XML_top10 + } + break; + case MultiValue: + { + rWorksheet->startElement(XML_filters, FSEND); + std::vector<rtl::OUString>::const_iterator itr = maMultiValues.begin(), itrEnd = maMultiValues.end(); + for (; itr != itrEnd; ++itr) + { + const char* pz = rtl::OUStringToOString(*itr, RTL_TEXTENCODING_UTF8).getStr(); + rWorksheet->singleElement(XML_filter, XML_val, pz, FSEND); + } + rWorksheet->endElement(XML_filters); + } + break; + } rWorksheet->endElement( XML_filterColumn ); } diff --git a/sc/source/filter/inc/excrecds.hxx b/sc/source/filter/inc/excrecds.hxx index 2c6b1fb69e89..6274bd8019f0 100644 --- a/sc/source/filter/inc/excrecds.hxx +++ b/sc/source/filter/inc/excrecds.hxx @@ -402,9 +402,12 @@ public: class XclExpAutofilter : public XclExpRecord, protected XclExpRoot { private: + enum FilterType { FilterCondition, MultiValue }; + FilterType meType; sal_uInt16 nCol; sal_uInt16 nFlags; ExcFilterCondition aCond[ 2 ]; + std::vector<rtl::OUString> maMultiValues; bool AddCondition( ScQueryConnect eConn, sal_uInt8 nType, sal_uInt8 nOp, double fVal, String* pText, @@ -416,10 +419,11 @@ public: XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC ); inline sal_uInt16 GetCol() const { return nCol; } - inline bool HasCondition() const { return !aCond[ 0 ].IsEmpty(); } inline bool HasTop10() const { return ::get_flag( nFlags, EXC_AFFLAG_TOP10 ); } + bool HasCondition() const; bool AddEntry( const ScQueryEntry& rEntry ); + bool AddMultiValueEntry( const ScQueryEntry& rEntry ); virtual void SaveXml( XclExpXmlStream& rStrm ); }; |