summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorVikas <vikasmahato0@gmail.com>2018-06-29 13:52:02 +0530
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2018-07-02 23:42:58 +0200
commitcb875f3ef1aa14b931131c4c0ddc595e3841273d (patch)
tree52a820a82e377e74bfc5425c70780a94ed611a03 /sc
parentb7a02f2bb66b990289eb7f4dc80069d1545179a4 (diff)
Export data transformations to odf
Change-Id: Ie36aef4a4ee550a1bb5407305f13726d55eeea58 Reviewed-on: https://gerrit.libreoffice.org/56665 Tested-by: Jenkins Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx81
-rw-r--r--sc/source/filter/xml/xmlexprt.hxx3
-rw-r--r--sc/source/ui/dataprovider/datatransformation.cxx50
-rw-r--r--sc/source/ui/inc/datatransformation.hxx22
4 files changed, 154 insertions, 2 deletions
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index bcfe73fe22d8..58d0e197b975 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -159,6 +159,8 @@
#include <vector>
#include <vbahelper/vbaaccesshelper.hxx>
+
+
//! not found in unonames.hxx
#define SC_LAYERID "LayerID"
@@ -4061,6 +4063,7 @@ void ScXMLExport::WriteExternalDataMapping()
sc::ExternalDataMapper& rDataMapper = pDoc->GetExternalDataMapper();
auto& rDataSources = rDataMapper.getDataSources();
+
if (!rDataSources.empty())
{
SvXMLElementExport aMappings(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_MAPPINGS, true, true);
@@ -4071,11 +4074,89 @@ void ScXMLExport::WriteExternalDataMapping()
AddAttribute(XML_NAMESPACE_CALC_EXT, XML_DATA_FREQUENCY, OUString::number(itr.getUpdateFrequency()));
AddAttribute(XML_NAMESPACE_CALC_EXT, XML_ID, itr.getID());
AddAttribute(XML_NAMESPACE_CALC_EXT, XML_DATABASE_NAME, itr.getDBName());
+
+ // Add the data transformations
+ WriteExternalDataTransformations(itr.getDataTransformation());
+
SvXMLElementExport aMapping(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_MAPPING, true, true);
}
}
}
+void ScXMLExport::WriteExternalDataTransformations(const std::vector<std::shared_ptr<sc::DataTransformation>>& aDataTransformations)
+{
+ SvXMLElementExport aTransformations(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_TRANSFORMATIONS, true, true);
+ for (auto& itr : aDataTransformations)
+ {
+ sc::TransformationType aTransformationType = itr->getTransformationType();
+
+ switch(aTransformationType)
+ {
+ case sc::TransformationType::DELETE_TRANSFORMATION:
+ {
+ // Delete Columns Transformation
+ std::shared_ptr<sc::ColumnRemoveTransformation> aDeleteTransformation = std::dynamic_pointer_cast<sc::ColumnRemoveTransformation>(itr);
+ std::set<SCCOL> aColumns = aDeleteTransformation->getColumns();
+ SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_REMOVE_TRANSFORMATION, true, true);
+ for(auto& col : aColumns)
+ {
+ // Add Columns
+ AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLUMN, OUString::number(col));
+ SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
+ }
+ }
+ break;
+ case sc::TransformationType::SPLIT_TRANSFORMATION:
+ {
+ std::shared_ptr<sc::SplitColumnTransformation> aSplitTransformation = std::dynamic_pointer_cast<sc::SplitColumnTransformation>(itr);
+
+ AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLUMN, OUString::number(aSplitTransformation->getColumn()));
+ AddAttribute(XML_NAMESPACE_CALC_EXT, XML_SEPARATOR, OUString::number(aSplitTransformation->getSeparator()));
+ SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_SPLIT_TRANSFORMATION, true, true);
+ }
+ break;
+ case sc::TransformationType::MERGE_TRANSFORMATION:
+ {
+ // Merge Transformation
+ std::shared_ptr<sc::MergeColumnTransformation> aMergeTransformation = std::dynamic_pointer_cast<sc::MergeColumnTransformation>(itr);
+ std::set<SCCOL> aColumns = aMergeTransformation->getColumns();
+
+ AddAttribute(XML_NAMESPACE_CALC_EXT, XML_MERGE_STRING, aMergeTransformation->getMergeString());
+ SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_MERGE_TRANSFORMATION, true, true);
+
+ for(auto& col : aColumns)
+ {
+ // Columns
+ AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLUMN, OUString::number(col));
+ SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
+ }
+ }
+ break;
+ case sc::TransformationType::SORT_TRANSFORMATION:
+ {
+ // Sort Transformation
+ std::shared_ptr<sc::SortTransformation> aSortTransformation = std::dynamic_pointer_cast<sc::SortTransformation>(itr);
+ ScSortParam aSortParam = aSortTransformation->getSortParam();
+ const sc::DocumentLinkManager& rMgr = pDoc->GetDocLinkManager();
+ const sc::DataStream* pStrm = rMgr.getDataStream();
+ if (!pStrm)
+ // No data stream.
+ return;
+
+ // Streamed range
+ ScRange aRange = pStrm->GetRange();
+
+ SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_SORT_TRANSFORMATION, true, true);
+
+ writeSort(*this, aSortParam, aRange, pDoc);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
void ScXMLExport::WriteDataStream()
{
if (!pDoc)
diff --git a/sc/source/filter/xml/xmlexprt.hxx b/sc/source/filter/xml/xmlexprt.hxx
index 6107aa86d102..e0eeea036dc7 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -30,6 +30,8 @@
#include <memory>
#include <unordered_map>
+#include <datatransformation.hxx>
+
namespace com { namespace sun { namespace star {
namespace beans { class XPropertySet; }
@@ -196,6 +198,7 @@ class ScXMLExport : public SvXMLExport
void WriteLabelRanges( const css::uno::Reference< css::container::XIndexAccess >& xRangesIAccess, bool bColumn );
void WriteNamedExpressions();
void WriteExternalDataMapping();
+ void WriteExternalDataTransformations(const std::vector<std::shared_ptr<sc::DataTransformation>>& aDataTransformations);
void WriteDataStream();
void WriteNamedRange(ScRangeName* pRangeName);
void ExportConditionalFormat(SCTAB nTab);
diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx
index bbb9bd068c7f..09370a8e82c7 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -43,6 +43,16 @@ void ColumnRemoveTransformation::Transform(ScDocument& rDoc) const
}
}
+TransformationType ColumnRemoveTransformation::getTransformationType() const
+{
+ return TransformationType::DELETE_TRANSFORMATION;
+}
+
+std::set<SCCOL> ColumnRemoveTransformation::getColumns() const
+{
+ return maColumns;
+}
+
SplitColumnTransformation::SplitColumnTransformation(SCCOL nCol, sal_Unicode cSeparator):
mnCol(nCol),
mcSeparator(cSeparator)
@@ -71,6 +81,21 @@ void SplitColumnTransformation::Transform(ScDocument& rDoc) const
}
}
+TransformationType SplitColumnTransformation::getTransformationType() const
+{
+ return TransformationType::SPLIT_TRANSFORMATION;
+}
+
+SCCOL SplitColumnTransformation::getColumn() const
+{
+ return mnCol;
+}
+
+sal_Unicode SplitColumnTransformation::getSeparator() const
+{
+ return mcSeparator;
+}
+
MergeColumnTransformation::MergeColumnTransformation(const std::set<SCCOL>& rColumns, const OUString& rMergeString):
maColumns(rColumns),
maMergeString(rMergeString)
@@ -113,6 +138,21 @@ void MergeColumnTransformation::Transform(ScDocument& rDoc) const
}
}
+TransformationType MergeColumnTransformation::getTransformationType() const
+{
+ return TransformationType::MERGE_TRANSFORMATION;
+}
+
+OUString MergeColumnTransformation::getMergeString() const
+{
+ return maMergeString;
+}
+
+std::set<SCCOL> MergeColumnTransformation::getColumns() const
+{
+ return maColumns;
+}
+
SortTransformation::SortTransformation(const ScSortParam& rSortParam):
maSortParam(rSortParam)
{
@@ -123,6 +163,16 @@ void SortTransformation::Transform(ScDocument& rDoc) const
rDoc.Sort(0, maSortParam, false, false, nullptr, nullptr);
}
+TransformationType SortTransformation::getTransformationType() const
+{
+ return TransformationType::SORT_TRANSFORMATION;
+}
+
+ScSortParam SortTransformation::getSortParam() const
+{
+ return maSortParam;
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/datatransformation.hxx b/sc/source/ui/inc/datatransformation.hxx
index 251397ca8304..8dbae9600384 100644
--- a/sc/source/ui/inc/datatransformation.hxx
+++ b/sc/source/ui/inc/datatransformation.hxx
@@ -21,6 +21,14 @@ class ScDocument;
namespace sc {
+enum class TransformationType
+{
+ MERGE_TRANSFORMATION,
+ SPLIT_TRANSFORMATION,
+ DELETE_TRANSFORMATION,
+ SORT_TRANSFORMATION
+};
+
class SC_DLLPUBLIC DataTransformation
{
protected:
@@ -32,6 +40,8 @@ public:
virtual void Transform(ScDocument& rDoc) const = 0;
+ virtual TransformationType getTransformationType() const = 0;
+
};
class SC_DLLPUBLIC ColumnRemoveTransformation : public DataTransformation
@@ -42,8 +52,9 @@ public:
ColumnRemoveTransformation(const std::set<SCCOL>& rColumns);
virtual ~ColumnRemoveTransformation() override;
-
virtual void Transform(ScDocument& rDoc) const override;
+ virtual TransformationType getTransformationType() const override;
+ std::set<SCCOL> getColumns() const;
};
class SC_DLLPUBLIC SplitColumnTransformation : public DataTransformation
@@ -55,6 +66,9 @@ public:
SplitColumnTransformation(SCCOL nCol, sal_Unicode cSeparator);
virtual void Transform(ScDocument& rDoc) const override;
+ virtual TransformationType getTransformationType() const override;
+ SCCOL getColumn() const;
+ sal_Unicode getSeparator() const;
};
class SC_DLLPUBLIC MergeColumnTransformation : public DataTransformation
@@ -66,6 +80,9 @@ public:
MergeColumnTransformation(const std::set<SCCOL>& rColumns, const OUString& rMergeString);
virtual void Transform(ScDocument& rDoc) const override;
+ virtual TransformationType getTransformationType() const override;
+ OUString getMergeString() const;
+ std::set<SCCOL> getColumns() const;
};
class SC_DLLPUBLIC SortTransformation : public DataTransformation
@@ -74,8 +91,9 @@ class SC_DLLPUBLIC SortTransformation : public DataTransformation
public:
SortTransformation(const ScSortParam& rParam);
-
virtual void Transform(ScDocument& rDoc) const override;
+ virtual TransformationType getTransformationType() const override;
+ ScSortParam getSortParam() const;
};
}