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 .
21 #include <xmloff/xmlexp.hxx>
22 #include <com/sun/star/table/CellRangeAddress.hpp>
23 #include <com/sun/star/io/XInputStream.hpp>
25 #include <address.hxx>
26 #include "XMLExportIterator.hxx"
29 #include <unordered_map>
32 namespace com::sun::star
{
33 namespace beans
{ class XPropertySet
; }
36 namespace com::sun::star::table
{ class XCellRange
; }
37 namespace com::sun::star::sheet
{ class XSpreadsheet
; }
38 namespace com::sun::star::sheet
{ class XSpreadsheetDocument
; }
40 namespace sc
{ class DataTransformation
; }
43 class SvXMLExportPropertyMapper
;
44 class ScMyMergedRangesContainer
;
45 class ScMyValidationsContainer
;
46 class ScMyNotEmptyCellsIterator
;
47 class ScChangeTrackingExportHelper
;
50 class ScFormatRangeStyles
;
51 class ScRowFormatRanges
;
52 class ScMyOpenCloseColumnRowGroup
;
56 class ScMyDefaultStyles
;
57 class XMLNumberFormatAttributesExportHelper
;
59 class ScXMLCachedRowAttrAccess
;
61 class ScXMLEditAttributeMap
;
67 class CompileFormulaContext
;
72 class ScXMLExport
: public SvXMLExport
74 css::uno::Reference
<css::sheet::XSpreadsheet
> xCurrentTable
;
76 css::uno::Reference
<css::io::XInputStream
> xSourceStream
;
77 sal_Int64 nSourceStreamPos
;
79 mutable std::unique_ptr
<ScXMLEditAttributeMap
> mpEditAttrMap
;
80 std::unique_ptr
<ScMyNotEmptyCellsIterator
> mpCellsItr
;
81 std::unique_ptr
<sc::CompileFormulaContext
> mpCompileFormulaCxt
;
82 rtl::Reference
< XMLPropertyHandlerFactory
> xScPropHdlFactory
;
83 rtl::Reference
< XMLPropertySetMapper
> xCellStylesPropertySetMapper
;
84 rtl::Reference
< XMLPropertySetMapper
> xColumnStylesPropertySetMapper
;
85 rtl::Reference
< XMLPropertySetMapper
> xRowStylesPropertySetMapper
;
86 rtl::Reference
< XMLPropertySetMapper
> xTableStylesPropertySetMapper
;
87 rtl::Reference
< SvXMLExportPropertyMapper
> xCellStylesExportPropertySetMapper
;
88 rtl::Reference
< SvXMLExportPropertyMapper
> xColumnStylesExportPropertySetMapper
;
89 rtl::Reference
< SvXMLExportPropertyMapper
> xRowStylesExportPropertySetMapper
;
90 rtl::Reference
< SvXMLExportPropertyMapper
> xTableStylesExportPropertySetMapper
;
91 std::unique_ptr
<XMLNumberFormatAttributesExportHelper
> pNumberFormatAttributesExportHelper
;
92 typedef std::unordered_map
<sal_Int32
, sal_Int32
> NumberFormatIndexMap
;
93 NumberFormatIndexMap aNumFmtIndexMap
;
94 std::unique_ptr
<ScMySharedData
> pSharedData
;
95 std::unique_ptr
<ScColumnStyles
> pColumnStyles
;
96 std::unique_ptr
<ScRowStyles
> pRowStyles
;
97 std::unique_ptr
<ScFormatRangeStyles
> pCellStyles
;
98 std::unique_ptr
<ScRowFormatRanges
> pRowFormatRanges
;
99 std::vector
<OUString
> aTableStyles
;
100 ScRange aRowHeaderRange
;
101 std::unique_ptr
<ScMyOpenCloseColumnRowGroup
> pGroupColumns
;
102 std::unique_ptr
<ScMyOpenCloseColumnRowGroup
> pGroupRows
;
103 std::unique_ptr
<ScMyDefaultStyles
> pDefaults
;
104 const ScMyCell
* pCurrentCell
;
106 std::unique_ptr
<ScMyMergedRangesContainer
> pMergedRangesContainer
;
107 std::unique_ptr
<ScMyValidationsContainer
> pValidationsContainer
;
108 std::unique_ptr
<ScChangeTrackingExportHelper
> pChangeTrackingExportHelper
;
109 OUString sExternalRefTabStyleName
;
111 OUString sAttrStyleName
;
112 OUString sAttrColumnsRepeated
;
113 OUString sAttrFormula
;
114 OUString sAttrValueType
;
115 OUString sAttrStringValue
;
117 OUString sElemCoveredCell
;
123 sal_Int32 nProgressCount
;
124 sal_uInt16 nCurrentTable
;
128 sal_Int32
GetNumberFormatStyleIndex(sal_Int32 nNumFmt
) const;
129 void CollectSharedData(SCTAB
& nTableCount
, sal_Int32
& nShapesCount
);
130 void CollectShapesAutoStyles(SCTAB nTableCount
);
131 void RegisterDefinedStyleNames( const css::uno::Reference
< css::sheet::XSpreadsheetDocument
> & xSpreadDoc
);
132 virtual void ExportFontDecls_() override
;
133 virtual void ExportStyles_( bool bUsed
) override
;
134 virtual void ExportAutoStyles_() override
;
135 virtual void ExportMasterStyles_() override
;
136 virtual void SetBodyAttributes() override
;
137 virtual void ExportContent_() override
;
138 virtual void ExportMeta_() override
;
140 void CollectInternalShape(ScDocument
& rDoc
, css::uno::Reference
< css::drawing::XShape
> const & xShape
);
142 static css::table::CellRangeAddress
GetEndAddress(const css::uno::Reference
<css::sheet::XSpreadsheet
>& xTable
);
143 static ScMyAreaLinksContainer
GetAreaLinks(ScDocument
& rDoc
);
144 ScMyDetectiveOpContainer
GetDetectiveOpList(ScDocument
& rDoc
);
145 void WriteSingleColumn(const sal_Int32 nRepeatColumns
, const sal_Int32 nStyleIndex
,
146 const sal_Int32 nIndex
, const bool bIsAutoStyle
, const bool bIsVisible
);
147 void WriteColumn(const sal_Int32 nColumn
, const sal_Int32 nRepeatColumns
,
148 const sal_Int32 nStyleIndex
, const bool bIsVisible
);
149 void OpenHeaderColumn();
150 void CloseHeaderColumn();
151 void ExportColumns(const sal_Int32 nTable
, const ScRange
& aColumnHeaderRange
, const bool bHasColumnHeader
);
152 void ExportExternalRefCacheStyles(ScDocument
& rDoc
);
153 void ExportCellTextAutoStyles(ScDocument
& rDoc
, sal_Int32 nTable
);
154 void ExportFormatRanges(ScDocument
& rDoc
, const sal_Int32 nStartCol
, const sal_Int32 nStartRow
,
155 const sal_Int32 nEndCol
, const sal_Int32 nEndRow
, const sal_Int32 nSheet
);
156 void WriteRowContent();
157 void WriteRowStartTag(const sal_Int32 nIndex
, const sal_Int32 nEmptyRows
, bool bHidden
, bool bFiltered
);
158 void OpenHeaderRows();
159 void CloseHeaderRows();
160 void OpenNewRow(const sal_Int32 nIndex
, const sal_Int32 nStartRow
, const sal_Int32 nEmptyRows
,
161 bool bHidden
, bool bFiltered
);
162 void OpenAndCloseRow(const sal_Int32 nIndex
, const sal_Int32 nStartRow
, const sal_Int32 nEmptyRows
,
163 bool bHidden
, bool bFiltered
);
164 void OpenRow(const sal_Int32 nTable
, const sal_Int32 nStartRow
, const sal_Int32 nRepeatRow
, ScXMLCachedRowAttrAccess
& rRowAttr
);
165 void CloseRow(const sal_Int32 nRow
);
166 void GetColumnRowHeader(ScDocument
& rDoc
, bool& bHasColumnHeader
, ScRange
& aColumnHeaderRange
,
167 bool& bHasRowHeader
, ScRange
& aRowHeaderRange
, OUString
& rPrintRanges
) const;
168 static void FillFieldGroup(ScOutlineArray
* pFields
, ScMyOpenCloseColumnRowGroup
* pGroups
);
169 void FillColumnRowGroups(ScDocument
& rDoc
);
171 bool GetMerged (const css::table::CellRangeAddress
* pCellRange
,
172 const css::uno::Reference
<css::sheet::XSpreadsheet
>& xTable
);
174 void WriteTable(ScDocument
& rDoc
, sal_Int32 nTable
, const css::uno::Reference
< css::sheet::XSpreadsheet
>& xTable
);
175 void WriteCell(ScDocument
& rDoc
, ScMyCell
& aCell
, sal_Int32 nEqualCellCount
);
176 void WriteEditCell(ScDocument
& rDoc
, const EditTextObject
* pText
);
177 void WriteMultiLineFormulaResult(const ScFormulaCell
* pCell
);
178 void WriteAreaLink(const ScMyCell
& rMyCell
);
179 void WriteAnnotation(ScDocument
& rDoc
, const ScMyCell
& rMyCell
);
180 void WriteDetective(ScDocument
& rDoc
, const ScMyCell
& rMyCell
);
181 void ExportShape(ScDocument
& rDoc
, const css::uno::Reference
< css::drawing::XShape
>& xShape
, css::awt::Point
* pPoint
);
182 void WriteShapes(ScDocument
& rDoc
, const ScMyCell
& rMyCell
);
183 void WriteTableShapes(ScDocument
& rDoc
);
184 void SetRepeatAttribute(sal_Int32 nEqualCellCount
, bool bIncProgress
);
186 static bool IsEditCell(const ScMyCell
& rCell
);
187 static bool IsCellEqual(ScDocument
& rDoc
, const ScMyCell
& aCell1
, const ScMyCell
& aCell2
);
189 void WriteCalculationSettings(ScDocument
& rDoc
, const css::uno::Reference
<css::sheet::XSpreadsheetDocument
>& xSpreadDoc
);
190 void WriteTableSource();
191 void WriteScenario(ScDocument
& rDoc
); // core implementation
192 void WriteTheLabelRanges(ScDocument
& rDoc
, const css::uno::Reference
< css::sheet::XSpreadsheetDocument
>& xSpreadDoc
);
193 void WriteLabelRanges(ScDocument
& rDoc
, const css::uno::Reference
< css::container::XIndexAccess
>& xRangesIAccess
, bool bColumn
);
194 void WriteNamedExpressions(ScDocument
& rDoc
);
195 void WriteExternalDataMapping(ScDocument
& rDoc
);
196 void WriteExternalDataTransformations(ScDocument
& rDoc
, const std::vector
<std::shared_ptr
<sc::DataTransformation
>>& rDataTransformations
);
197 void WriteDataStream(ScDocument
& rDoc
);
198 void WriteNamedRange(ScDocument
& rDoc
, ScRangeName
* pRangeName
);
199 void exportSparklineGroups(ScDocument
& rDoc
, SCTAB nTab
);
200 void ExportConditionalFormat(ScDocument
& rDoc
, SCTAB nTab
);
201 void WriteExternalRefCaches(ScDocument
& rDoc
);
202 void WriteConsolidation(ScDocument
& rDoc
); // core implementation
204 void CollectUserDefinedNamespaces(const SfxItemPool
* pPool
, sal_uInt16 nAttrib
);
206 void AddStyleFromCells(
207 const css::uno::Reference
< css::beans::XPropertySet
>& xProperties
,
208 const css::uno::Reference
< css::sheet::XSpreadsheet
>& xTable
,
209 sal_Int32 nTable
, const OUString
* pOldName
);
210 void AddStyleFromColumn(
211 const css::uno::Reference
< css::beans::XPropertySet
>& xColumnProperties
,
212 const OUString
* pOldName
, sal_Int32
& rIndex
, bool& rIsVisible
);
213 void AddStyleFromRow(
214 const css::uno::Reference
< css::beans::XPropertySet
>& xRowProperties
,
215 const OUString
* pOldName
, sal_Int32
& rIndex
);
217 void IncrementProgressBar(bool bFlush
, sal_Int32 nInc
= 1);
219 void CopySourceStream( sal_Int64 nStartOffset
, sal_Int64 nEndOffset
, sal_Int64
& rNewStart
, sal_Int64
& rNewEnd
);
221 const ScXMLEditAttributeMap
& GetEditAttributeMap() const;
226 virtual SvXMLAutoStylePoolP
* CreateAutoStylePool() override
;
227 virtual XMLPageExport
* CreatePageExport() override
;
228 virtual XMLShapeExport
* CreateShapeExport() override
;
229 virtual XMLFontAutoStylePool
* CreateFontAutoStylePool() override
;
232 const css::uno::Reference
< css::uno::XComponentContext
>& rContext
,
233 OUString
const & implementationName
, SvXMLExportFlags nExportFlag
);
235 virtual ~ScXMLExport() override
;
237 void collectAutoStyles() override
;
239 static sal_Int16
GetMeasureUnit();
240 SAL_RET_MAYBENULL ScDocument
* GetDocument();
241 static bool IsMatrix (ScDocument
& rDoc
, const ScAddress
& aCell
,
242 ScRange
& aCellAddress
, bool& bIsFirst
);
244 const rtl::Reference
< XMLPropertySetMapper
>& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper
; }
245 const rtl::Reference
< XMLPropertySetMapper
>& GetTableStylesPropertySetMapper() const { return xTableStylesPropertySetMapper
; }
247 void SetSourceStream( const css::uno::Reference
<css::io::XInputStream
>& xNewStream
);
249 static void GetChangeTrackViewSettings(ScDocument
& rDoc
, css::uno::Sequence
<css::beans::PropertyValue
>& rProps
);
250 virtual void GetViewSettings(css::uno::Sequence
<css::beans::PropertyValue
>& rProps
) override
;
251 virtual void GetConfigurationSettings(css::uno::Sequence
<css::beans::PropertyValue
>& rProps
) override
;
253 virtual void exportAnnotationMeta( const css::uno::Reference
< css::drawing::XShape
>& xShape
) override
;
255 void SetSharedData(std::unique_ptr
<ScMySharedData
> pTemp
);
256 ScMySharedData
* GetSharedData() { return pSharedData
.get(); }
257 std::unique_ptr
<ScMySharedData
> ReleaseSharedData();
258 XMLNumberFormatAttributesExportHelper
* GetNumberFormatAttributesExportHelper();
260 // Export the document.
261 virtual ErrCode
exportDoc( enum ::xmloff::token::XMLTokenEnum eClass
= ::xmloff::token::XML_TOKEN_INVALID
) override
;
264 virtual void SAL_CALL
setSourceDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
) override
;
267 virtual sal_Bool SAL_CALL
filter( const css::uno::Sequence
< css::beans::PropertyValue
>& aDescriptor
) override
;
268 virtual void SAL_CALL
cancel() override
;
271 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
273 virtual void DisposingModel() override
;
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */