Kaydet (Commit) 7f2fcde9 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Export multi-value filters to xlsx.

üst 5b033d42
...@@ -652,6 +652,7 @@ void ExcFilterCondition::SaveText( XclExpStream& rStrm ) ...@@ -652,6 +652,7 @@ void ExcFilterCondition::SaveText( XclExpStream& rStrm )
XclExpAutofilter::XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC ) : XclExpAutofilter::XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC ) :
XclExpRecord( EXC_ID_AUTOFILTER, 24 ), XclExpRecord( EXC_ID_AUTOFILTER, 24 ),
XclExpRoot( rRoot ), XclExpRoot( rRoot ),
meType(FilterCondition),
nCol( nC ), nCol( nC ),
nFlags( 0 ) nFlags( 0 )
{ {
...@@ -674,14 +675,26 @@ bool XclExpAutofilter::AddCondition( ScQueryConnect eConn, sal_uInt8 nType, sal_ ...@@ -674,14 +675,26 @@ bool XclExpAutofilter::AddCondition( ScQueryConnect eConn, sal_uInt8 nType, sal_
AddRecSize( aCond[ nInd ].GetTextBytes() ); AddRecSize( aCond[ nInd ].GetTextBytes() );
return sal_True; return true;
}
bool XclExpAutofilter::HasCondition() const
{
return !aCond[0].IsEmpty();
} }
bool XclExpAutofilter::AddEntry( const ScQueryEntry& rEntry ) 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; bool bConflict = false;
String sText; String sText;
const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); const ScQueryEntry::Item& rItem = rItems[0];
const rtl::OUString& rQueryStr = rItem.maString; const rtl::OUString& rQueryStr = rItem.maString;
if (!rQueryStr.isEmpty()) if (!rQueryStr.isEmpty())
{ {
...@@ -785,6 +798,17 @@ bool XclExpAutofilter::AddEntry( const ScQueryEntry& rEntry ) ...@@ -785,6 +798,17 @@ bool XclExpAutofilter::AddEntry( const ScQueryEntry& rEntry )
return bConflict; 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 ) void XclExpAutofilter::WriteBody( XclExpStream& rStrm )
{ {
rStrm << nCol << nFlags; rStrm << nCol << nFlags;
...@@ -796,7 +820,7 @@ void XclExpAutofilter::WriteBody( XclExpStream& rStrm ) ...@@ -796,7 +820,7 @@ void XclExpAutofilter::WriteBody( XclExpStream& rStrm )
void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm ) void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm )
{ {
if( !HasCondition() ) if (meType == FilterCondition && !HasCondition())
return; return;
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
...@@ -807,24 +831,43 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm ) ...@@ -807,24 +831,43 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm )
// OOXTODO: XML_showButton, // OOXTODO: XML_showButton,
FSEND ); FSEND );
if( HasTop10() ) switch (meType)
{ {
rWorksheet->singleElement( XML_top10, case FilterCondition:
XML_top, XclXmlUtils::ToPsz( get_flag( nFlags, EXC_AFFLAG_TOP10TOP ) ), {
XML_percent, XclXmlUtils::ToPsz( get_flag( nFlags, EXC_AFFLAG_TOP10PERC ) ), if( HasTop10() )
XML_val, OString::valueOf( (sal_Int32) (nFlags >> 7 ) ).getStr(), {
// OOXTODO: XML_filterVal, rWorksheet->singleElement( XML_top10,
FSEND ); 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, rWorksheet->startElement( XML_customFilters,
XML_and, XclXmlUtils::ToPsz( (nFlags & EXC_AFFLAG_ANDORMASK) == EXC_AFFLAG_AND ), XML_and, XclXmlUtils::ToPsz( (nFlags & EXC_AFFLAG_ANDORMASK) == EXC_AFFLAG_AND ),
FSEND ); FSEND );
aCond[ 0 ].SaveXml( rStrm ); aCond[ 0 ].SaveXml( rStrm );
aCond[ 1 ].SaveXml( rStrm ); aCond[ 1 ].SaveXml( rStrm );
rWorksheet->endElement( XML_customFilters ); rWorksheet->endElement( XML_customFilters );
// OOXTODO: XLM_colorFilter, XML_dynamicFilter, // OOXTODO: XLM_colorFilter, XML_dynamicFilter,
// XML_extLst, XML_filters, XML_iconFilter, XML_top10 // 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 ); rWorksheet->endElement( XML_filterColumn );
} }
......
...@@ -402,9 +402,12 @@ public: ...@@ -402,9 +402,12 @@ public:
class XclExpAutofilter : public XclExpRecord, protected XclExpRoot class XclExpAutofilter : public XclExpRecord, protected XclExpRoot
{ {
private: private:
enum FilterType { FilterCondition, MultiValue };
FilterType meType;
sal_uInt16 nCol; sal_uInt16 nCol;
sal_uInt16 nFlags; sal_uInt16 nFlags;
ExcFilterCondition aCond[ 2 ]; ExcFilterCondition aCond[ 2 ];
std::vector<rtl::OUString> maMultiValues;
bool AddCondition( ScQueryConnect eConn, sal_uInt8 nType, bool AddCondition( ScQueryConnect eConn, sal_uInt8 nType,
sal_uInt8 nOp, double fVal, String* pText, sal_uInt8 nOp, double fVal, String* pText,
...@@ -416,10 +419,11 @@ public: ...@@ -416,10 +419,11 @@ public:
XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC ); XclExpAutofilter( const XclExpRoot& rRoot, sal_uInt16 nC );
inline sal_uInt16 GetCol() const { return nCol; } 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 ); } inline bool HasTop10() const { return ::get_flag( nFlags, EXC_AFFLAG_TOP10 ); }
bool HasCondition() const;
bool AddEntry( const ScQueryEntry& rEntry ); bool AddEntry( const ScQueryEntry& rEntry );
bool AddMultiValueEntry( const ScQueryEntry& rEntry );
virtual void SaveXml( XclExpXmlStream& rStrm ); virtual void SaveXml( XclExpXmlStream& rStrm );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment