1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "xmldrani.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlfilti.hxx"
23 #include "xmlsorti.hxx"
24 #include <document.hxx>
25 #include <globalnames.hxx>
27 #include <datauno.hxx>
29 #include <unonames.hxx>
30 #include "XMLConverter.hxx"
31 #include <rangeutl.hxx>
33 #include <sortparam.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmlnamespace.hxx>
38 #include <sax/tools/converter.hxx>
40 #include <com/sun/star/sheet/DataImportMode.hpp>
41 #include <com/sun/star/table/TableOrientation.hpp>
42 #include <osl/diagnose.h>
43 #include <o3tl/string_view.hxx>
47 using namespace com::sun::star
;
48 using namespace xmloff::token
;
50 ScXMLDatabaseRangesContext::ScXMLDatabaseRangesContext( ScXMLImport
& rImport
) :
51 ScXMLImportContext( rImport
)
54 rImport
.LockSolarMutex();
57 ScXMLDatabaseRangesContext::~ScXMLDatabaseRangesContext()
59 GetScImport().UnlockSolarMutex();
62 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDatabaseRangesContext::createFastChildContext(
64 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
66 SvXMLImportContext
*pContext
= nullptr;
67 sax_fastparser::FastAttributeList
*pAttribList
=
68 &sax_fastparser::castToFastAttributeList( xAttrList
);
72 case XML_ELEMENT( TABLE
, XML_DATABASE_RANGE
):
74 pContext
= new ScXMLDatabaseRangeContext( GetScImport(), pAttribList
);
82 ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( ScXMLImport
& rImport
,
83 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
84 ScXMLImportContext( rImport
),
85 mpQueryParam(new ScQueryParam
),
86 sDatabaseRangeName(STR_DB_LOCAL_NONAME
),
87 nSourceType(sheet::DataImportMode_NONE
),
89 nSubTotalsUserListIndex(0),
92 bContainsSubTotal(false),
99 bSubTotalsBindFormatsToContent(false),
100 bSubTotalsIsCaseSensitive(false),
101 bSubTotalsInsertPageBreaks(false),
102 bSubTotalsSummaryBelow(true),
103 bSubTotalsSortGroups(false),
104 bSubTotalsEnabledUserList(false),
105 bSubTotalsAscending(true),
106 bFilterConditionSourceRange(false),
110 meRangeType(ScDBCollection::GlobalNamed
)
114 for( auto &aIter
: *rAttrList
)
116 switch( aIter
.getToken() )
118 case XML_ELEMENT( TABLE
, XML_NAME
):
120 sDatabaseRangeName
= aIter
.toString();
123 case XML_ELEMENT( TABLE
, XML_IS_SELECTION
):
125 bIsSelection
= IsXMLToken( aIter
, XML_TRUE
);
128 case XML_ELEMENT( TABLE
, XML_ON_UPDATE_KEEP_STYLES
):
130 bKeepFormats
= IsXMLToken( aIter
, XML_TRUE
);
133 case XML_ELEMENT( TABLE
, XML_ON_UPDATE_KEEP_SIZE
):
135 bMoveCells
= !IsXMLToken( aIter
, XML_TRUE
);
138 case XML_ELEMENT( TABLE
, XML_HAS_PERSISTENT_DATA
):
140 bStripData
= !IsXMLToken( aIter
, XML_TRUE
);
143 case XML_ELEMENT( TABLE
, XML_ORIENTATION
):
145 bByRow
= !IsXMLToken( aIter
, XML_COLUMN
);
146 mpQueryParam
->bByRow
= bByRow
;
149 case XML_ELEMENT( TABLE
, XML_CONTAINS_HEADER
):
151 bHasHeader
= IsXMLToken( aIter
, XML_TRUE
);
152 mpQueryParam
->bHasHeader
= bHasHeader
;
155 case XML_ELEMENT( TABLE
, XML_CONTAINS_FOOTER
):
156 case XML_ELEMENT( CALC_EXT
, XML_CONTAINS_FOOTER
):
158 bHasFooter
= IsXMLToken( aIter
, XML_TRUE
);
159 mpQueryParam
->bHasTotals
= bHasFooter
;
162 case XML_ELEMENT( TABLE
, XML_DISPLAY_FILTER_BUTTONS
):
164 bAutoFilter
= IsXMLToken( aIter
, XML_TRUE
);
167 case XML_ELEMENT( TABLE
, XML_TARGET_RANGE_ADDRESS
):
169 ScDocument
* pDoc
= GetScImport().GetDocument();
171 sal_Int32 nOffset
= 0;
172 if (!ScRangeStringConverter::GetRangeFromString(
173 maRange
, aIter
.toString(), *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
))
174 mbValidRange
= false;
177 case XML_ELEMENT( TABLE
, XML_REFRESH_DELAY
):
180 if (::sax::Converter::convertDuration( fTime
, aIter
.toView() ))
181 nRefresh
= std::max( static_cast<sal_Int32
>(fTime
* 86400.0), sal_Int32(0) );
188 mpQueryParam
->nTab
= maRange
.aStart
.Tab();
189 mpQueryParam
->nCol1
= maRange
.aStart
.Col();
190 mpQueryParam
->nRow1
= maRange
.aStart
.Row();
191 mpQueryParam
->nCol2
= maRange
.aEnd
.Col();
192 mpQueryParam
->nRow2
= maRange
.aEnd
.Row();
194 if (sDatabaseRangeName
.startsWith(STR_DB_LOCAL_NONAME
))
195 meRangeType
= ScDBCollection::SheetAnonymous
;
196 else if (sDatabaseRangeName
.startsWith(STR_DB_GLOBAL_NONAME
))
197 meRangeType
= ScDBCollection::GlobalAnonymous
;
200 ScXMLDatabaseRangeContext::~ScXMLDatabaseRangeContext()
204 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDatabaseRangeContext::createFastChildContext(
205 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
207 SvXMLImportContext
*pContext
= nullptr;
208 sax_fastparser::FastAttributeList
*pAttribList
=
209 &sax_fastparser::castToFastAttributeList( xAttrList
);
213 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_SQL
):
215 pContext
= new ScXMLSourceSQLContext( GetScImport(), pAttribList
, this);
218 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_TABLE
):
220 pContext
= new ScXMLSourceTableContext( GetScImport(), pAttribList
, this);
223 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_QUERY
):
225 pContext
= new ScXMLSourceQueryContext( GetScImport(), pAttribList
, this);
228 case XML_ELEMENT( TABLE
, XML_FILTER
):
230 pContext
= new ScXMLFilterContext(
231 GetScImport(), pAttribList
, *mpQueryParam
, this);
234 case XML_ELEMENT( TABLE
, XML_SORT
):
236 bContainsSort
= true;
237 pContext
= new ScXMLSortContext( GetScImport(), pAttribList
, this);
240 case XML_ELEMENT( TABLE
, XML_SUBTOTAL_RULES
):
242 bContainsSubTotal
= true;
243 pContext
= new ScXMLSubTotalRulesContext( GetScImport(), pAttribList
, this);
251 std::unique_ptr
<ScDBData
> ScXMLDatabaseRangeContext::ConvertToDBData(const OUString
& rName
)
256 ScDocument
* pDoc
= GetScImport().GetDocument();
258 ::std::unique_ptr
<ScDBData
> pData(
259 new ScDBData(rName
, maRange
.aStart
.Tab(), maRange
.aStart
.Col(), maRange
.aStart
.Row(), maRange
.aEnd
.Col(), maRange
.aEnd
.Row(), bByRow
, bHasHeader
, bHasFooter
));
261 pData
->SetAutoFilter(bAutoFilter
);
262 pData
->SetKeepFmt(bKeepFormats
);
263 pData
->SetDoSize(bMoveCells
);
264 pData
->SetStripData(bStripData
);
266 pDoc
->PrepareQuery(mpQueryParam
->nTab
, *mpQueryParam
);
268 pData
->SetQueryParam(*mpQueryParam
);
270 if (bFilterConditionSourceRange
)
272 pData
->SetAdvancedQuerySource( &aFilterConditionSourceRangeAddress
);
276 ScImportParam aParam
;
277 aParam
.bNative
= bNative
;
278 aParam
.aDBName
= sDatabaseName
.isEmpty() ? sConnectionResource
: sDatabaseName
;
279 aParam
.aStatement
= sSourceObject
;
282 case sheet::DataImportMode_NONE
:
283 aParam
.bImport
= false;
285 case sheet::DataImportMode_SQL
:
286 aParam
.bImport
= true;
289 case sheet::DataImportMode_TABLE
:
290 aParam
.bImport
= true;
292 aParam
.nType
= ScDbTable
;
294 case sheet::DataImportMode_QUERY
:
295 aParam
.bImport
= true;
297 aParam
.nType
= ScDbQuery
;
300 OSL_FAIL("Unknown data import mode");
301 aParam
.bImport
= false;
303 pData
->SetImportParam(aParam
);
308 size_t nOldSize
= aSortSequence
.getLength();
309 aSortSequence
.realloc(nOldSize
+ 1);
310 beans::PropertyValue aProperty
;
311 aProperty
.Name
= SC_UNONAME_ORIENT
;
312 table::TableOrientation eOrient
= mpQueryParam
->bByRow
?
313 table::TableOrientation_ROWS
: table::TableOrientation_COLUMNS
;
314 aProperty
.Value
<<= eOrient
;
315 aSortSequence
.getArray()[nOldSize
] = std::move(aProperty
);
317 ScSortDescriptor::FillSortParam(aParam
, aSortSequence
);
319 SCCOLROW nStartPos
= aParam
.bByRow
? maRange
.aStart
.Col() : maRange
.aStart
.Row();
320 for (size_t i
= 0; i
< aParam
.GetSortKeyCount(); ++i
)
322 if (!aParam
.maKeyState
[i
].bDoSort
)
324 aParam
.maKeyState
[i
].nField
+= nStartPos
;
327 pData
->SetSortParam(aParam
);
330 if (bContainsSubTotal
)
332 ScSubTotalParam aParam
;
333 aParam
.bIncludePattern
= bSubTotalsBindFormatsToContent
;
334 aParam
.bUserDef
= bSubTotalsEnabledUserList
;
335 aParam
.nUserIndex
= nSubTotalsUserListIndex
;
336 aParam
.bPagebreak
= bSubTotalsInsertPageBreaks
;
337 aParam
.bSummaryBelow
= bSubTotalsSummaryBelow
;
338 aParam
.bCaseSens
= bSubTotalsIsCaseSensitive
;
339 aParam
.bDoSort
= bSubTotalsSortGroups
;
340 aParam
.bAscending
= bSubTotalsAscending
;
342 for (const auto& rSubTotalRule
: aSubTotalRules
)
344 if (nPos
>= MAXSUBTOTAL
)
346 auto& group
= aParam
.aGroups
[nPos
];
348 const uno::Sequence
<sheet::SubTotalColumn
>& rColumns
= rSubTotalRule
.aSubTotalColumns
;
349 sal_Int16 nGroupColumn
= rSubTotalRule
.nSubTotalRuleGroupFieldNumber
;
350 group
.bActive
= true;
351 group
.nField
= static_cast<SCCOL
>(nGroupColumn
);
353 group
.SetSubtotals(rColumns
);
357 pData
->SetSubTotalParam(aParam
);
360 if (pData
->HasImportParam() && !pData
->HasImportSelection())
362 pData
->SetRefreshDelay(nRefresh
);
363 pData
->SetRefreshHandler(pDoc
->GetDBCollection()->GetRefreshHandler());
364 pData
->SetRefreshControl(&pDoc
->GetRefreshTimerControlAddress());
372 bool setAutoFilterFlags(ScDocument
& rDoc
, const ScDBData
& rData
)
374 if (!rData
.HasAutoFilter())
377 // Set autofilter flags so that the buttons get displayed.
379 rData
.GetArea(aRange
);
381 aRange
.aStart
.Col(), aRange
.aStart
.Row(), aRange
.aEnd
.Col(), aRange
.aStart
.Row(),
382 aRange
.aStart
.Tab(), ScMF::Auto
);
388 void SAL_CALL
ScXMLDatabaseRangeContext::endFastElement( sal_Int32
/*nElement*/ )
390 ScDocument
* pDoc
= GetScImport().GetDocument();
394 if (meRangeType
== ScDBCollection::SheetAnonymous
)
396 ::std::unique_ptr
<ScDBData
> pData(ConvertToDBData(STR_DB_LOCAL_NONAME
));
401 pData
->GetArea(aRange
);
403 setAutoFilterFlags(*pDoc
, *pData
);
404 pDoc
->SetAnonymousDBData(aRange
.aStart
.Tab(), std::move(pData
));
408 else if (meRangeType
== ScDBCollection::GlobalAnonymous
)
410 ::std::unique_ptr
<ScDBData
> pData(ConvertToDBData(STR_DB_GLOBAL_NONAME
));
415 pData
->GetArea(aRange
);
417 if (setAutoFilterFlags(*pDoc
, *pData
))
418 pDoc
->SetAnonymousDBData(aRange
.aStart
.Tab(), std::move(pData
));
420 pDoc
->GetDBCollection()->getAnonDBs().insert(pData
.release());
424 else if (meRangeType
== ScDBCollection::GlobalNamed
)
426 ::std::unique_ptr
<ScDBData
> pData(ConvertToDBData(sDatabaseRangeName
));
430 setAutoFilterFlags(*pDoc
, *pData
);
431 (void)pDoc
->GetDBCollection()->getNamedDBs().insert(std::move(pData
));
436 ScXMLSourceSQLContext::ScXMLSourceSQLContext( ScXMLImport
& rImport
,
437 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
438 ScXMLDatabaseRangeContext
* pTempDatabaseRangeContext
) :
439 ScXMLImportContext( rImport
),
440 pDatabaseRangeContext(pTempDatabaseRangeContext
)
442 if ( rAttrList
.is() )
444 for (auto &aIter
: *rAttrList
)
446 switch (aIter
.getToken())
448 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
449 sDBName
= aIter
.toString();
451 case XML_ELEMENT( TABLE
, XML_SQL_STATEMENT
):
452 pDatabaseRangeContext
->SetSourceObject(aIter
.toString());
454 case XML_ELEMENT( TABLE
, XML_PARSE_SQL_STATEMENT
):
455 pDatabaseRangeContext
->SetNative(IsXMLToken(aIter
, XML_TRUE
));
460 pDatabaseRangeContext
->SetSourceType(sheet::DataImportMode_SQL
);
463 ScXMLSourceSQLContext::~ScXMLSourceSQLContext()
467 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLSourceSQLContext::createFastChildContext(
468 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
470 SvXMLImportContext
*pContext
= nullptr;
471 sax_fastparser::FastAttributeList
*pAttribList
=
472 &sax_fastparser::castToFastAttributeList( xAttrList
);
474 if ( nElement
== XML_ELEMENT( FORM
, XML_CONNECTION_RESOURCE
) && sDBName
.isEmpty() )
476 pContext
= new ScXMLConResContext( GetScImport(), pAttribList
, pDatabaseRangeContext
);
482 void SAL_CALL
ScXMLSourceSQLContext::endFastElement( sal_Int32
/*nElement*/ )
484 if (!sDBName
.isEmpty())
485 pDatabaseRangeContext
->SetDatabaseName(sDBName
);
488 ScXMLSourceTableContext::ScXMLSourceTableContext( ScXMLImport
& rImport
,
489 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
490 ScXMLDatabaseRangeContext
* pTempDatabaseRangeContext
) :
491 ScXMLImportContext( rImport
),
492 pDatabaseRangeContext(pTempDatabaseRangeContext
)
494 if ( rAttrList
.is() )
496 for (auto &aIter
: *rAttrList
)
498 switch (aIter
.getToken())
500 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
501 sDBName
= aIter
.toString();
503 case XML_ELEMENT( TABLE
, XML_TABLE_NAME
):
504 case XML_ELEMENT( TABLE
, XML_DATABASE_TABLE_NAME
):
505 pDatabaseRangeContext
->SetSourceObject(aIter
.toString());
510 pDatabaseRangeContext
->SetSourceType(sheet::DataImportMode_TABLE
);
513 ScXMLSourceTableContext::~ScXMLSourceTableContext()
517 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLSourceTableContext::createFastChildContext(
518 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
520 SvXMLImportContext
*pContext
= nullptr;
521 sax_fastparser::FastAttributeList
*pAttribList
=
522 &sax_fastparser::castToFastAttributeList( xAttrList
);
524 if ( nElement
== XML_ELEMENT( FORM
, XML_CONNECTION_RESOURCE
) && sDBName
.isEmpty() )
526 pContext
= new ScXMLConResContext( GetScImport(), pAttribList
, pDatabaseRangeContext
);
532 void SAL_CALL
ScXMLSourceTableContext::endFastElement( sal_Int32
/*nElement*/ )
534 if (!sDBName
.isEmpty())
535 pDatabaseRangeContext
->SetDatabaseName(sDBName
);
538 ScXMLSourceQueryContext::ScXMLSourceQueryContext( ScXMLImport
& rImport
,
539 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
540 ScXMLDatabaseRangeContext
* pTempDatabaseRangeContext
) :
541 ScXMLImportContext( rImport
),
542 pDatabaseRangeContext(pTempDatabaseRangeContext
)
544 if ( rAttrList
.is() )
546 for (auto &aIter
: *rAttrList
)
548 switch (aIter
.getToken())
550 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
551 sDBName
= aIter
.toString();
553 case XML_ELEMENT( TABLE
, XML_QUERY_NAME
):
554 pDatabaseRangeContext
->SetSourceObject(aIter
.toString());
559 pDatabaseRangeContext
->SetSourceType(sheet::DataImportMode_QUERY
);
562 ScXMLSourceQueryContext::~ScXMLSourceQueryContext()
566 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLSourceQueryContext::createFastChildContext(
567 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
569 SvXMLImportContext
*pContext
= nullptr;
570 sax_fastparser::FastAttributeList
*pAttribList
=
571 &sax_fastparser::castToFastAttributeList( xAttrList
);
573 if ( nElement
== XML_ELEMENT( FORM
, XML_CONNECTION_RESOURCE
) && sDBName
.isEmpty() )
575 pContext
= new ScXMLConResContext( GetScImport(), pAttribList
, pDatabaseRangeContext
);
581 void SAL_CALL
ScXMLSourceQueryContext::endFastElement( sal_Int32
/*nElement*/ )
583 if (!sDBName
.isEmpty())
584 pDatabaseRangeContext
->SetDatabaseName(sDBName
);
587 ScXMLConResContext::ScXMLConResContext( ScXMLImport
& rImport
,
588 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
589 ScXMLDatabaseRangeContext
* pDatabaseRangeContext
) :
590 ScXMLImportContext( rImport
)
593 if ( rAttrList
.is() )
595 auto aIter( rAttrList
->find( XML_ELEMENT( XLINK
, XML_HREF
) ) );
596 if (aIter
!= rAttrList
->end())
597 sConRes
= aIter
.toString();
599 if (!sConRes
.isEmpty())
600 pDatabaseRangeContext
->SetConnectionResource(sConRes
);
603 ScXMLConResContext::~ScXMLConResContext()
607 ScXMLSubTotalRulesContext::ScXMLSubTotalRulesContext( ScXMLImport
& rImport
,
608 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
609 ScXMLDatabaseRangeContext
* pTempDatabaseRangeContext
) :
610 ScXMLImportContext( rImport
),
611 pDatabaseRangeContext(pTempDatabaseRangeContext
)
613 if ( !rAttrList
.is() )
616 for (auto &aIter
: *rAttrList
)
618 switch (aIter
.getToken())
620 case XML_ELEMENT( TABLE
, XML_BIND_STYLES_TO_CONTENT
):
621 pDatabaseRangeContext
->SetSubTotalsBindFormatsToContent(IsXMLToken(aIter
, XML_TRUE
));
623 case XML_ELEMENT( TABLE
, XML_CASE_SENSITIVE
):
624 pDatabaseRangeContext
->SetSubTotalsIsCaseSensitive(IsXMLToken(aIter
, XML_TRUE
));
626 case XML_ELEMENT( TABLE
, XML_PAGE_BREAKS_ON_GROUP_CHANGE
):
627 pDatabaseRangeContext
->SetSubTotalsInsertPageBreaks(IsXMLToken(aIter
, XML_TRUE
));
629 case XML_ELEMENT( LO_EXT
, XML_SUMMARY_BELOW
):
630 pDatabaseRangeContext
->SetSubTotalsSummaryBelow(IsXMLToken(aIter
, XML_TRUE
));
636 ScXMLSubTotalRulesContext::~ScXMLSubTotalRulesContext()
640 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLSubTotalRulesContext::createFastChildContext(
641 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
643 SvXMLImportContext
*pContext
= nullptr;
644 sax_fastparser::FastAttributeList
*pAttribList
=
645 &sax_fastparser::castToFastAttributeList( xAttrList
);
649 case XML_ELEMENT( TABLE
, XML_SORT_GROUPS
):
651 pContext
= new ScXMLSortGroupsContext( GetScImport(), pAttribList
, pDatabaseRangeContext
);
654 case XML_ELEMENT( TABLE
, XML_SUBTOTAL_RULE
):
656 pContext
= new ScXMLSubTotalRuleContext( GetScImport(), pAttribList
, pDatabaseRangeContext
);
664 ScXMLSortGroupsContext::ScXMLSortGroupsContext( ScXMLImport
& rImport
,
665 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
666 ScXMLDatabaseRangeContext
* pDatabaseRangeContext
) :
667 ScXMLImportContext( rImport
)
669 pDatabaseRangeContext
->SetSubTotalsSortGroups(true);
670 if ( !rAttrList
.is() )
673 for (auto &aIter
: *rAttrList
)
675 switch (aIter
.getToken())
677 case XML_ELEMENT( TABLE
, XML_DATA_TYPE
):
679 const OUString sValue
= aIter
.toString();
680 if (sValue
.getLength() > 8)
682 std::u16string_view sTemp
= sValue
.subView(0, 8);
683 if (sTemp
== u
"UserList")
685 pDatabaseRangeContext
->SetSubTotalsEnabledUserList(true);
686 sTemp
= sValue
.subView(8);
687 pDatabaseRangeContext
->SetSubTotalsUserListIndex(static_cast<sal_Int16
>(o3tl::toInt32(sTemp
)));
691 //if (IsXMLToken(aIter, XML_AUTOMATIC))
692 //aSortField.FieldType = util::SortFieldType_AUTOMATIC;
693 // is not supported by StarOffice
698 //if (IsXMLToken(aIter, XML_TEXT))
699 //aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
700 // is not supported by StarOffice
701 //else if (IsXMLToken(aIter, XML_NUMBER))
702 //aSortField.FieldType = util::SortFieldType_NUMERIC;
703 // is not supported by StarOffice
707 case XML_ELEMENT( TABLE
, XML_ORDER
):
709 if (IsXMLToken(aIter
, XML_ASCENDING
))
710 pDatabaseRangeContext
->SetSubTotalsAscending(true);
712 pDatabaseRangeContext
->SetSubTotalsAscending(false);
719 ScXMLSortGroupsContext::~ScXMLSortGroupsContext()
723 ScXMLSubTotalRuleContext::ScXMLSubTotalRuleContext( ScXMLImport
& rImport
,
724 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
725 ScXMLDatabaseRangeContext
* pTempDatabaseRangeContext
) :
726 ScXMLImportContext( rImport
),
727 pDatabaseRangeContext(pTempDatabaseRangeContext
)
729 if ( rAttrList
.is() )
731 for (auto &aIter
: *rAttrList
)
733 switch (aIter
.getToken())
735 case XML_ELEMENT( TABLE
, XML_GROUP_BY_FIELD_NUMBER
):
736 aSubTotalRule
.nSubTotalRuleGroupFieldNumber
= static_cast<sal_Int16
>(aIter
.toInt32());
743 ScXMLSubTotalRuleContext::~ScXMLSubTotalRuleContext()
747 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLSubTotalRuleContext::createFastChildContext(
748 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
750 SvXMLImportContext
*pContext
= nullptr;
751 sax_fastparser::FastAttributeList
*pAttribList
=
752 &sax_fastparser::castToFastAttributeList( xAttrList
);
756 case XML_ELEMENT( TABLE
, XML_SUBTOTAL_FIELD
):
758 pContext
= new ScXMLSubTotalFieldContext( GetScImport(), pAttribList
, this);
766 void SAL_CALL
ScXMLSubTotalRuleContext::endFastElement( sal_Int32
/*nElement*/ )
768 if (pDatabaseRangeContext
)
769 pDatabaseRangeContext
->AddSubTotalRule(aSubTotalRule
);
772 ScXMLSubTotalFieldContext::ScXMLSubTotalFieldContext( ScXMLImport
& rImport
,
773 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
774 ScXMLSubTotalRuleContext
* pTempSubTotalRuleContext
) :
775 ScXMLImportContext( rImport
),
776 pSubTotalRuleContext(pTempSubTotalRuleContext
)
778 if ( !rAttrList
.is() )
781 for (auto &aIter
: *rAttrList
)
783 switch (aIter
.getToken())
785 case XML_ELEMENT( TABLE
, XML_FIELD_NUMBER
):
786 sFieldNumber
= aIter
.toString();
788 case XML_ELEMENT( TABLE
, XML_FUNCTION
):
789 sFunction
= aIter
.toString();
795 ScXMLSubTotalFieldContext::~ScXMLSubTotalFieldContext()
799 void SAL_CALL
ScXMLSubTotalFieldContext::endFastElement( sal_Int32
/*nElement*/ )
801 sheet::SubTotalColumn aSubTotalColumn
;
802 aSubTotalColumn
.Column
= sFieldNumber
.toInt32();
803 aSubTotalColumn
.Function
= ScXMLConverter::GetFunctionFromString( sFunction
);
804 pSubTotalRuleContext
->AddSubTotalColumn(aSubTotalColumn
);
807 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */