diff options
author | Serge Krot <Serge.Krot@cib.de> | 2020-06-29 13:23:34 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-09-19 21:11:04 +0200 |
commit | d8e0001fd8b4702f78ade095b8b2ce09ac2451e2 (patch) | |
tree | 8aa4317a180dd6249ace466326ff5a06703eb9fc /sc/source/filter/excel | |
parent | 0cb32df8141eb49eb8b44f0523dfd81079abb2ac (diff) |
tdf#95640 XLSX: import/export of custom sort lists
Conflicts:
sc/source/filter/excel/excrecds.cxx
sc/source/filter/oox/autofilterbuffer.cxx
sc/source/filter/oox/tablebuffer.cxx
Change-Id: If5ffef39770bf7abd6e75e8de998d4a2b4749a0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97399
Tested-by: Jenkins
Tested-by: Serge Krot <Serge.Krot@cib.de>
Reviewed-by: Serge Krot <Serge.Krot@cib.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102254
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sc/source/filter/excel')
-rw-r--r-- | sc/source/filter/excel/excrecds.cxx | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx index 4fbe955d8b52..d7ab5d7d95af 100644 --- a/sc/source/filter/excel/excrecds.cxx +++ b/sc/source/filter/excel/excrecds.cxx @@ -34,6 +34,8 @@ #include <oox/token/tokens.hxx> #include <queryentry.hxx> #include <queryparam.hxx> +#include <sortparam.hxx> +#include <userlist.hxx> #include <root.hxx> #include <xeescher.hxx> @@ -927,6 +929,45 @@ ExcAutoFilterRecs::ExcAutoFilterRecs( const XclExpRoot& rRoot, SCTAB nTab, const if (maFilterList.IsEmpty () && !bConflict) mbAutoFilter = true; + + // get sort criteria + { + ScSortParam aSortParam; + pData->GetSortParam( aSortParam ); + + if (aSortParam.bUserDef) + { + // get sorted area without headers + maSortRef = ScRange( + aParam.nCol1, aParam.nRow1 + (aSortParam.bHasHeader? 1 : 0), aParam.nTab, + aParam.nCol2, aParam.nRow2, aParam.nTab ); + + // get sorted columns with custom lists + ScUserList* pList = ScGlobal::GetUserList(); + const ScUserListData& rData = (*pList)[aSortParam.nUserIndex]; + + // get column index and sorting direction + SCCOLROW nField = 0; + bool bSortAscending=true; + for (const auto & rKey : aSortParam.maKeyState) + { + if (rKey.bDoSort) + { + nField = rKey.nField; + bSortAscending = rKey.bAscending; + break; + } + } + + // remember sort criteria + const ScRange aSortedColumn( + nField, aParam.nRow1 + (aSortParam.bHasHeader? 1 : 0), aParam.nTab, + nField, aParam.nRow2, aParam.nTab ); + const OUString aItemList = rData.GetString(); + + maSortCustomList.emplace_back(aSortedColumn, aItemList, !bSortAscending); + } + } } } } @@ -990,6 +1031,29 @@ void ExcAutoFilterRecs::SaveXml( XclExpXmlStream& rStrm ) // OOXTODO: XML_extLst, XML_sortState if( !maFilterList.IsEmpty() ) maFilterList.SaveXml( rStrm ); + + if (!maSortCustomList.empty()) + { + rWorksheet->startElement(XML_sortState, XML_ref, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), maSortRef)); + + for (const auto & rSortCriteria : maSortCustomList) + { + if (std::get<2>(rSortCriteria)) + rWorksheet->singleElement(XML_sortCondition, + XML_ref, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), + std::get<0>(rSortCriteria)), + XML_descending, "1", + XML_customList, std::get<1>(rSortCriteria).toUtf8().getStr()); + else + rWorksheet->singleElement(XML_sortCondition, + XML_ref, XclXmlUtils::ToOString(&rStrm.GetRoot().GetDoc(), + std::get<0>(rSortCriteria)), + XML_customList, std::get<1>(rSortCriteria).toUtf8().getStr()); + } + + rWorksheet->endElement(XML_sortState); + } + rWorksheet->endElement( XML_autoFilter ); } |