29#include <unonames.hxx>
31#include <document.hxx>
42#include <com/sun/star/beans/XPropertySet.hpp>
43#include <com/sun/star/frame/XModel.hpp>
44#include <com/sun/star/sheet/DataImportMode.hpp>
45#include <com/sun/star/sheet/XDatabaseRanges.hpp>
46#include <com/sun/star/sheet/XDatabaseRange.hpp>
48#include <osl/diagnose.h>
61 size_t nSortCount = 0;
96 for (
size_t i = 0;
i < nSortCount; ++
i)
122 : rExport(rTempExport),
132 uno::Reference <beans::XPropertySet> xPropertySet (
rExport.
GetModel(), uno::UNO_QUERY);
133 if (xPropertySet.is())
135 uno::Reference <sheet::XDatabaseRanges> xDatabaseRanges(xPropertySet->getPropertyValue(
SC_UNO_DATABASERNG), uno::UNO_QUERY);
137 if (xDatabaseRanges.is())
139 const uno::Sequence <OUString> aRanges(xDatabaseRanges->getElementNames());
140 for (
const OUString& sDatabaseRangeName : aRanges)
142 uno::Reference <sheet::XDatabaseRange> xDatabaseRange(xDatabaseRanges->getByName(sDatabaseRangeName), uno::UNO_QUERY);
143 if (xDatabaseRange.is())
145 uno::Reference <beans::XPropertySet> xDatabaseRangePropertySet (xDatabaseRange, uno::UNO_QUERY);
146 if (xDatabaseRangePropertySet.is() &&
149 const uno::Sequence <beans::PropertyValue> aImportProperties(xDatabaseRange->getImportDescriptor());
150 sheet::DataImportMode nSourceType = sheet::DataImportMode_NONE;
151 for (
const auto& rProp : aImportProperties)
153 rProp.Value >>= nSourceType;
154 if (nSourceType != sheet::DataImportMode_NONE)
156 table::CellRangeAddress aArea = xDatabaseRange->getDataArea();
174class WriteDatabaseRange
183 mrExport(rExport), mpDoc(pDoc), mnCounter(0), meRangeType(
ScDBCollection::GlobalNamed) {}
190 void operator() (const ::std::pair<SCTAB, const ScDBData*>& r)
197 OUString::number(
static_cast<sal_Int32
>(r.first));
199 write(aBuf, *r.second);
202 void operator() (
const ScDBData& rData)
215 void operator() (std::unique_ptr<ScDBData>
const& p)
217 return operator()(*p);
221 void write(
const OUString& rName,
const ScDBData& rData)
223 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, rName);
231 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_TARGET_RANGE_ADDRESS, aRangeStr);
235 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_IS_SELECTION, XML_TRUE);
237 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_FILTER_BUTTONS, XML_TRUE);
239 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_ON_UPDATE_KEEP_STYLES, XML_TRUE);
241 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_ON_UPDATE_KEEP_SIZE, XML_FALSE);
243 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_HAS_PERSISTENT_DATA, XML_FALSE);
248 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_CONTAINS_HEADER, XML_FALSE);
253 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_ORIENTATION, XML_COLUMN);
256 if (nRefreshDelaySeconds)
260 static_cast<double>(nRefreshDelaySeconds) / 86400.0);
261 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_REFRESH_DELAY,
aBuf.makeStringAndClear());
264 SvXMLElementExport aElemDR(mrExport, XML_NAMESPACE_TABLE, XML_DATABASE_RANGE,
true,
true);
271 writeSort(mrExport, aParam, aRange, mpDoc);
272 writeSubtotals(rData);
275 void writeImport(
const ScDBData& rData)
280 OUString sDatabaseName;
287 sDatabaseName = aParam.
aDBName;
294 sheet::DataImportMode nSourceType = sheet::DataImportMode_NONE;
298 nSourceType = sheet::DataImportMode_SQL;
300 nSourceType = sheet::DataImportMode_QUERY;
302 nSourceType = sheet::DataImportMode_TABLE;
307 case sheet::DataImportMode_NONE :
break;
308 case sheet::DataImportMode_QUERY :
310 if (!sDatabaseName.isEmpty())
311 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, sDatabaseName);
313 SvXMLElementExport aElemID(mrExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_QUERY,
true,
true);
314 if (!sConRes.isEmpty())
316 mrExport.
AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sConRes );
317 SvXMLElementExport aElemCR(mrExport, XML_NAMESPACE_FORM, XML_CONNECTION_RESOURCE,
true,
true);
321 case sheet::DataImportMode_TABLE :
323 if (!sDatabaseName.isEmpty())
324 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, sDatabaseName);
326 SvXMLElementExport aElemID(mrExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_TABLE,
true,
true);
327 if (!sConRes.isEmpty())
329 mrExport.
AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sConRes );
330 SvXMLElementExport aElemCR(mrExport, XML_NAMESPACE_FORM, XML_CONNECTION_RESOURCE,
true,
true);
334 case sheet::DataImportMode_SQL :
336 if (!sDatabaseName.isEmpty())
337 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_DATABASE_NAME, sDatabaseName);
340 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_PARSE_SQL_STATEMENT, XML_TRUE);
341 SvXMLElementExport aElemID(mrExport, XML_NAMESPACE_TABLE, XML_DATABASE_SOURCE_SQL,
true,
true);
342 if (!sConRes.isEmpty())
344 mrExport.
AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sConRes );
345 SvXMLElementExport aElemCR(mrExport, XML_NAMESPACE_FORM, XML_CONNECTION_RESOURCE,
true,
true);
415 explicit WriteSetItem(
ScXMLExport& r) : mrExport(r) {}
419 SvXMLElementExport aElem(mrExport, XML_NAMESPACE_TABLE, XML_FILTER_SET_ITEM,
true,
true);
429 OSL_FAIL(
"Query entry has no items at all! It must have at least one!");
433 if (rItems.size() == 1)
451 mrExport.
AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATA_TYPE, XML_TEXT_COLOR);
453 mrExport.
AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATA_TYPE,
454 XML_BACKGROUND_COLOR);
466 OUStringBuffer buffer;
468 colorValue = buffer.makeStringAndClear();
470 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_VALUE, colorValue);
474 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_DATA_TYPE, XML_NUMBER);
478 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_OPERATOR, getOperatorXML(rEntry, eSearchType));
479 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_FIELD_NUMBER, OUString::number(rEntry.
nField - nFieldStart));
481 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_CASE_SENSITIVE, XML_TRUE);
482 SvXMLElementExport aElemC(mrExport, XML_NAMESPACE_TABLE, XML_FILTER_CONDITION,
true,
true);
487 assert( rItems.size() > 1 &&
"rItems should have more than 1 element");
492 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_OPERATOR, OUString(
"="));
493 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_FIELD_NUMBER, OUString::number(rEntry.
nField - nFieldStart));
495 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_CASE_SENSITIVE, XML_TRUE);
496 SvXMLElementExport aElemC(mrExport, XML_NAMESPACE_TABLE, XML_FILTER_CONDITION,
true,
true);
498 std::for_each(rItems.begin(), rItems.end(), WriteSetItem(mrExport));
502 void writeFilter(
const ScDBData& rData)
507 for (
size_t n = aParam.
GetEntryCount(); nCount < n; ++nCount)
522 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_TARGET_RANGE_ADDRESS, aAddrStr);
531 if (!aAddrStr.isEmpty())
532 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_CONDITION_SOURCE_RANGE_ADDRESS, aAddrStr);
536 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_DUPLICATES, XML_FALSE);
563 else if (bAnd && !bOr)
565 SvXMLElementExport aElemAnd(mrExport, XML_NAMESPACE_TABLE, XML_FILTER_AND,
true,
true);
569 else if (nCount == 1)
578 bool bOpenAndElement =
false;
584 bOpenAndElement =
true;
587 bOpenAndElement =
false;
598 bOpenAndElement =
true;
605 bOpenAndElement =
false;
615 bOpenAndElement =
false;
634 void writeSubtotals(
const ScDBData& rData)
650 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_BIND_STYLES_TO_CONTENT, XML_FALSE);
653 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_PAGE_BREAKS_ON_GROUP_CHANGE, XML_TRUE);
656 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_CASE_SENSITIVE, XML_TRUE);
658 SvXMLElementExport aElemSTRs(mrExport, XML_NAMESPACE_TABLE, XML_SUBTOTAL_RULES,
true,
true);
663 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_ORDER, XML_DESCENDING);
668 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_DATA_TYPE, aBuf);
670 SvXMLElementExport aElemSGs(mrExport, XML_NAMESPACE_TABLE, XML_SORT_GROUPS,
true,
true);
679 sal_Int32 nFieldCol =
static_cast<sal_Int32
>(aParam.
nField[
i]);
680 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_GROUP_BY_FIELD_NUMBER, OUString::number(nFieldCol));
681 SvXMLElementExport aElemSTR(mrExport, XML_NAMESPACE_TABLE, XML_SUBTOTAL_RULE,
true,
true);
685 sal_Int32 nCol =
static_cast<sal_Int32
>(aParam.
pSubTotals[
i][j]);
688 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_FIELD_NUMBER, OUString::number(nCol));
690 mrExport.
AddAttribute(XML_NAMESPACE_TABLE, XML_FUNCTION, aFuncStr);
692 SvXMLElementExport aElemSTF(mrExport, XML_NAMESPACE_TABLE, XML_SUBTOTAL_FIELD,
true,
true);
708 std::map<SCTAB, const ScDBData*> aSheetDBs;
709 for (
SCTAB i = 0;
i < nTabCount; ++
i)
713 aSheetDBs.emplace(
i,
p);
716 bool bHasRanges = !aSheetDBs.empty();
739 ::std::for_each(rNamedDBs.
begin(), rNamedDBs.
end(), func);
744 ::std::for_each(rAnonDBs.
begin(), rAnonDBs.
end(), func);
749 ::std::for_each(aSheetDBs.begin(), aSheetDBs.end(), func);
void writeSort(ScXMLExport &mrExport, const ScSortParam &aParam, const ScRange &aRange, const ScDocument *mpDoc)
constexpr OUStringLiteral SC_USERLIST
not found in unonames.hxx
Stores global anonymous database ranges.
Stores global named database ranges.
void GetImportParam(ScImportParam &rImportParam) const
bool HasAutoFilter() const
const OUString & GetName() const
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
SC_DLLPUBLIC bool GetAdvancedQuerySource(ScRange &rSource) const
SC_DLLPUBLIC void GetSortParam(ScSortParam &rSortParam) const
SC_DLLPUBLIC void GetQueryParam(ScQueryParam &rQueryParam) const
bool HasImportSelection() const
void GetSubTotalParam(ScSubTotalParam &rSubTotalParam) const
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
SC_DLLPUBLIC ScDBData * GetAnonymousDBData(SCTAB nTab)
SC_DLLPUBLIC SCTAB GetTableCount() const
void AddNewEmptyDatabaseRange(const css::table::CellRangeAddress &aCellRangeAddress)
void SetLastColumn(const sal_Int32 nTable, const sal_Int32 nCol)
void SetLastRow(const sal_Int32 nTable, const sal_Int32 nRow)
static void GetStringFromRange(OUString &rString, const ScRange &rRange, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ', bool bAppendStr=false, ScRefFlags nFormatFlags=ScRefFlags::VALID|ScRefFlags::TAB_3D)
static void GetStringFromAddress(OUString &rString, const ScAddress &rAddress, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ', bool bAppendStr=false, ScRefFlags nFormatFlags=ScRefFlags::VALID|ScRefFlags::TAB_3D)
Range to String core.
sal_Int32 GetRefreshDelaySeconds() const
static OUString GetStringFromFunction(const sal_Int16 eFunction)
ScMyEmptyDatabaseRangesContainer GetEmptyDatabaseRanges()
ScXMLExportDatabaseRanges(ScXMLExport &rExport)
void WriteDatabaseRanges()
ScDocument * GetDocument()
ScMySharedData * GetSharedData()
const SvXMLNamespaceMap & GetNamespaceMap() const
void StartElement(sal_uInt16 nPrefix, enum ::xmloff::token::XMLTokenEnum eName, bool bIgnWSOutside)
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
const css::uno::Reference< css::frame::XModel > & GetModel() const
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
void AddLanguageTagAttributes(sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc, const css::lang::Locale &rLocale, bool bWriteEmpty)
void EndElement(sal_uInt16 nPrefix, enum ::xmloff::token::XMLTokenEnum eName, bool bIgnWSInside)
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
const OUString & getString() const
bool has(DataAccessDescriptorProperty _eWhich) const
void setDataSource(const OUString &_sDataSourceNameOrLocation)
constexpr OUStringLiteral STR_DB_GLOBAL_NONAME
constexpr OUStringLiteral STR_DB_LOCAL_NONAME
XML_BIND_STYLES_TO_CONTENT
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
svl::SharedString maString
Each instance of this struct represents a single filtering criteria.
bool IsQueryByNonEmpty() const
std::vector< Item > QueryItemsType
bool IsQueryByEmpty() const
QueryItemsType & GetQueryItems()
SC_DLLPUBLIC const ScQueryEntry & GetEntry(SCSIZE n) const
utl::SearchParam::SearchType eSearchType
SC_DLLPUBLIC SCSIZE GetEntryCount() const
::std::vector< ScSortKeyState > maKeyState
OUString aCollatorAlgorithm
ScDataAreaExtras aDataAreaExtras
css::lang::Locale aCollatorLocale
sal_uInt16 GetSortKeyCount() const
bool bUserDef
sort user defined
bool bPagebreak
page break at change of group
bool bAscending
sort ascending
bool bGroupActive[MAXSUBTOTAL]
active groups
sal_uInt16 nUserIndex
index into list
SCCOL nField[MAXSUBTOTAL]
associated field
SCCOL nSubTotals[MAXSUBTOTAL]
number of SubTotals
std::unique_ptr< ScSubTotalFunc[]> pFunctions[MAXSUBTOTAL]
array of associated functions
std::unique_ptr< SCCOL[]> pSubTotals[MAXSUBTOTAL]
array of columns to be calculated
bool bIncludePattern
sort formats
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
constexpr OUStringLiteral SC_UNO_DATABASERNG
constexpr OUStringLiteral SC_UNONAME_STRIPDAT
constexpr OUStringLiteral SC_UNONAME_SRCTYPE
constexpr sal_uInt16 XML_NAMESPACE_TABLE