Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <editeng/eeitem.hxx>
21 :
22 : #include "xmlexprt.hxx"
23 : #include "XMLConverter.hxx"
24 : #include "xmlstyle.hxx"
25 : #include "unonames.hxx"
26 : #include "document.hxx"
27 : #include "olinetab.hxx"
28 : #include "cellsuno.hxx"
29 : #include "formulacell.hxx"
30 : #include "rangenam.hxx"
31 : #include "XMLTableMasterPageExport.hxx"
32 : #include "drwlayer.hxx"
33 : #include "XMLExportDataPilot.hxx"
34 : #include "XMLExportDatabaseRanges.hxx"
35 : #include "XMLExportDDELinks.hxx"
36 : #include "XMLExportIterator.hxx"
37 : #include "XMLColumnRowGroupExport.hxx"
38 : #include "XMLStylesExportHelper.hxx"
39 : #include "XMLChangeTrackingExportHelper.hxx"
40 : #include "sheetdata.hxx"
41 : #include "docoptio.hxx"
42 : #include "XMLExportSharedData.hxx"
43 : #include "chgviset.hxx"
44 : #include "docuno.hxx"
45 : #include "textuno.hxx"
46 : #include "chartlis.hxx"
47 : #include "scitems.hxx"
48 : #include "docpool.hxx"
49 : #include "userdat.hxx"
50 : #include "dociter.hxx"
51 : #include "chgtrack.hxx"
52 : #include "rangeutl.hxx"
53 : #include "convuno.hxx"
54 : #include "postit.hxx"
55 : #include "externalrefmgr.hxx"
56 : #include "editutil.hxx"
57 : #include "tabprotection.hxx"
58 : #include "cachedattraccess.hxx"
59 : #include "colorscale.hxx"
60 : #include "conditio.hxx"
61 : #include "cellvalue.hxx"
62 : #include "stylehelper.hxx"
63 :
64 : #include <xmloff/xmltoken.hxx>
65 : #include <xmloff/xmlnmspe.hxx>
66 : #include <xmloff/xmluconv.hxx>
67 : #include <xmloff/nmspmap.hxx>
68 : #include <xmloff/families.hxx>
69 : #include <xmloff/numehelp.hxx>
70 : #include <xmloff/txtparae.hxx>
71 : #include <editeng/xmlcnitm.hxx>
72 : #include <xmloff/xmlerror.hxx>
73 : #include <xmloff/XMLEventExport.hxx>
74 :
75 : #include <sax/tools/converter.hxx>
76 :
77 : #include <rtl/ustring.hxx>
78 :
79 : #include "tools/color.hxx"
80 : #include <rtl/math.hxx>
81 : #include <svl/zforlist.hxx>
82 : #include <svx/unoshape.hxx>
83 : #include <comphelper/extract.hxx>
84 : #include <toolkit/helper/convert.hxx>
85 : #include <svx/svdobj.hxx>
86 : #include <svx/svdocapt.hxx>
87 : #include <editeng/outlobj.hxx>
88 : #include <svx/svditer.hxx>
89 : #include <svx/svdpage.hxx>
90 :
91 : #include <comphelper/processfactory.hxx>
92 : #include <com/sun/star/beans/XPropertySet.hpp>
93 : #include <com/sun/star/container/XNamed.hpp>
94 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
95 : #include <com/sun/star/form/XFormsSupplier2.hpp>
96 : #include <com/sun/star/io/XActiveDataSource.hpp>
97 : #include <com/sun/star/io/XSeekable.hpp>
98 : #include <com/sun/star/sheet/XUsedAreaCursor.hpp>
99 : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
100 : #include <com/sun/star/sheet/XAreaLinks.hpp>
101 : #include <com/sun/star/sheet/XAreaLink.hpp>
102 : #include <com/sun/star/sheet/XPrintAreas.hpp>
103 : #include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp>
104 : #include <com/sun/star/sheet/XCellRangesQuery.hpp>
105 : #include <com/sun/star/sheet/CellFlags.hpp>
106 : #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
107 : #include <com/sun/star/sheet/XLabelRanges.hpp>
108 : #include <com/sun/star/sheet/XLabelRange.hpp>
109 : #include <com/sun/star/sheet/XNamedRanges.hpp>
110 : #include <com/sun/star/sheet/XNamedRange.hpp>
111 : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
112 : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
113 : #include <com/sun/star/sheet/XSheetLinkable.hpp>
114 : #include <com/sun/star/sheet/GlobalSheetSettings.hpp>
115 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
116 : #include <com/sun/star/table/XColumnRowRange.hpp>
117 : #include <com/sun/star/text/XText.hpp>
118 : #include <com/sun/star/util/XMergeable.hpp>
119 : #include <com/sun/star/util/XProtectable.hpp>
120 :
121 : #include <com/sun/star/chart2/XChartDocument.hpp>
122 : #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
123 : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
124 :
125 : #include <com/sun/star/document/XDocumentProperties.hpp>
126 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
127 :
128 : #include "XMLCodeNameProvider.hxx"
129 :
130 : #include <sfx2/objsh.hxx>
131 :
132 : #include <vector>
133 : #include <vbahelper/vbaaccesshelper.hxx>
134 :
135 : //! not found in unonames.hxx
136 : #define SC_LAYERID "LayerID"
137 :
138 : #define SC_VIEWCHANGES_COUNT 13
139 : #define SC_SHOW_CHANGES 0
140 : #define SC_SHOW_ACCEPTED_CHANGES 1
141 : #define SC_SHOW_REJECTED_CHANGES 2
142 : #define SC_SHOW_CHANGES_BY_DATETIME 3
143 : #define SC_SHOW_CHANGES_BY_DATETIME_MODE 4
144 : #define SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME 5
145 : #define SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME 6
146 : #define SC_SHOW_CHANGES_BY_AUTHOR 7
147 : #define SC_SHOW_CHANGES_BY_AUTHOR_NAME 8
148 : #define SC_SHOW_CHANGES_BY_COMMENT 9
149 : #define SC_SHOW_CHANGES_BY_COMMENT_TEXT 10
150 : #define SC_SHOW_CHANGES_BY_RANGES 11
151 : #define SC_SHOW_CHANGES_BY_RANGES_LIST 12
152 :
153 : using namespace formula;
154 : using namespace com::sun::star;
155 : using namespace xmloff::token;
156 : using ::std::vector;
157 : using ::com::sun::star::uno::Reference;
158 : using ::com::sun::star::uno::UNO_QUERY;
159 :
160 : //----------------------------------------------------------------------------
161 :
162 : namespace
163 : {
164 0 : OUString lcl_RangeSequenceToString(
165 : const uno::Sequence< OUString > & rRanges,
166 : const uno::Reference< chart2::data::XRangeXMLConversion > & xFormatConverter )
167 : {
168 0 : OUStringBuffer aResult;
169 0 : const sal_Int32 nMaxIndex( rRanges.getLength() - 1 );
170 0 : const sal_Unicode cSep( sal_Char(' '));
171 0 : for( sal_Int32 i=0; i<=nMaxIndex; ++i )
172 : {
173 0 : OUString aRange( rRanges[i] );
174 0 : if( xFormatConverter.is())
175 0 : aRange = xFormatConverter->convertRangeToXML( aRange );
176 0 : aResult.append( aRange );
177 0 : if( i < nMaxIndex )
178 0 : aResult.append( cSep );
179 0 : }
180 0 : return aResult.makeStringAndClear();
181 : }
182 :
183 8 : OUString lcl_GetRawString( ScDocument* pDoc, const ScAddress& rPos )
184 : {
185 : // return text/edit cell string content, with line feeds in edit cells
186 :
187 8 : if (!pDoc)
188 0 : return EMPTY_OUSTRING;
189 :
190 8 : switch (pDoc->GetCellType(rPos))
191 : {
192 : case CELLTYPE_STRING:
193 8 : return pDoc->GetString(rPos);
194 : case CELLTYPE_EDIT:
195 : {
196 0 : const EditTextObject* pData = pDoc->GetEditText(rPos);
197 0 : if (!pData)
198 0 : return EMPTY_OUSTRING;
199 :
200 0 : EditEngine& rEngine = pDoc->GetEditEngine();
201 0 : rEngine.SetText(*pData);
202 0 : return rEngine.GetText(LINEEND_LF);
203 : }
204 : break;
205 : default:
206 : ;
207 : }
208 :
209 0 : return EMPTY_OUSTRING;
210 : }
211 :
212 : } // anonymous namespace
213 :
214 : //----------------------------------------------------------------------------
215 :
216 49 : OUString SAL_CALL ScXMLOOoExport_getImplementationName() throw()
217 : {
218 49 : return OUString( "com.sun.star.comp.Calc.XMLExporter" );
219 : }
220 :
221 1 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_getSupportedServiceNames() throw()
222 : {
223 1 : const OUString aServiceName( ScXMLOOoExport_getImplementationName() );
224 1 : return uno::Sequence< OUString >( &aServiceName, 1 );
225 : }
226 :
227 2 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_createInstance(
228 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
229 : {
230 2 : return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), EXPORT_ALL );
231 : }
232 :
233 48 : OUString SAL_CALL ScXMLOOoExport_Meta_getImplementationName() throw()
234 : {
235 48 : return OUString( "com.sun.star.comp.Calc.XMLMetaExporter" );
236 : }
237 :
238 1 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_Meta_getSupportedServiceNames() throw()
239 : {
240 1 : const OUString aServiceName( ScXMLOOoExport_Meta_getImplementationName() );
241 1 : return uno::Sequence< OUString > ( &aServiceName, 1 );
242 : }
243 :
244 1 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Meta_createInstance(
245 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
246 : {
247 1 : return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), EXPORT_META );
248 : }
249 :
250 49 : OUString SAL_CALL ScXMLOOoExport_Styles_getImplementationName() throw()
251 : {
252 49 : return OUString( "com.sun.star.comp.Calc.XMLStylesExporter" );
253 : }
254 :
255 2 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_Styles_getSupportedServiceNames() throw()
256 : {
257 2 : const OUString aServiceName( ScXMLOOoExport_Styles_getImplementationName() );
258 2 : return uno::Sequence< OUString > ( &aServiceName, 1 );
259 : }
260 :
261 3 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Styles_createInstance(
262 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
263 : {
264 3 : return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS);
265 : }
266 :
267 45 : OUString SAL_CALL ScXMLOOoExport_Content_getImplementationName() throw()
268 : {
269 45 : return OUString( "com.sun.star.comp.Calc.XMLContentExporter" );
270 : }
271 :
272 1 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_Content_getSupportedServiceNames() throw()
273 : {
274 1 : const OUString aServiceName( ScXMLOOoExport_Content_getImplementationName() );
275 1 : return uno::Sequence< OUString > ( &aServiceName, 1 );
276 : }
277 :
278 1 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Content_createInstance(
279 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
280 : {
281 1 : return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS);
282 : }
283 :
284 46 : OUString SAL_CALL ScXMLOOoExport_Settings_getImplementationName() throw()
285 : {
286 46 : return OUString( "com.sun.star.comp.Calc.XMLSettingsExporter" );
287 : }
288 :
289 2 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_Settings_getSupportedServiceNames() throw()
290 : {
291 2 : const OUString aServiceName( ScXMLOOoExport_Settings_getImplementationName() );
292 2 : return uno::Sequence< OUString > ( &aServiceName, 1 );
293 : }
294 :
295 3 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Settings_createInstance(
296 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
297 : {
298 3 : return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), EXPORT_SETTINGS );
299 : }
300 :
301 : // Oasis Filter
302 :
303 40 : OUString SAL_CALL ScXMLOasisExport_getImplementationName() throw()
304 : {
305 40 : return OUString( "com.sun.star.comp.Calc.XMLOasisExporter" );
306 : }
307 :
308 0 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_getSupportedServiceNames() throw()
309 : {
310 0 : const OUString aServiceName( ScXMLOasisExport_getImplementationName() );
311 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
312 0 : return aSeq;
313 : }
314 :
315 0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_createInstance(
316 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
317 : {
318 0 : return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), EXPORT_ALL|EXPORT_OASIS);
319 : }
320 :
321 44 : OUString SAL_CALL ScXMLOasisExport_Meta_getImplementationName() throw()
322 : {
323 44 : return OUString( "com.sun.star.comp.Calc.XMLOasisMetaExporter" );
324 : }
325 :
326 2 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Meta_getSupportedServiceNames() throw()
327 : {
328 2 : const OUString aServiceName( ScXMLOasisExport_Meta_getImplementationName() );
329 2 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
330 2 : return aSeq;
331 : }
332 :
333 3 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Meta_createInstance(
334 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
335 : {
336 3 : return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), EXPORT_META|EXPORT_OASIS);
337 : }
338 :
339 44 : OUString SAL_CALL ScXMLOasisExport_Styles_getImplementationName() throw()
340 : {
341 44 : return OUString( "com.sun.star.comp.Calc.XMLOasisStylesExporter" );
342 : }
343 :
344 3 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Styles_getSupportedServiceNames() throw()
345 : {
346 3 : const OUString aServiceName( ScXMLOasisExport_Styles_getImplementationName() );
347 3 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
348 3 : return aSeq;
349 : }
350 :
351 7 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Styles_createInstance(
352 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
353 : {
354 7 : return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS|EXPORT_OASIS);
355 : }
356 :
357 41 : OUString SAL_CALL ScXMLOasisExport_Content_getImplementationName() throw()
358 : {
359 41 : return OUString( "com.sun.star.comp.Calc.XMLOasisContentExporter" );
360 : }
361 :
362 3 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Content_getSupportedServiceNames() throw()
363 : {
364 3 : const OUString aServiceName( ScXMLOasisExport_Content_getImplementationName() );
365 3 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
366 3 : return aSeq;
367 : }
368 :
369 7 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Content_createInstance(
370 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
371 : {
372 7 : return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS|EXPORT_OASIS);
373 : }
374 :
375 38 : OUString SAL_CALL ScXMLOasisExport_Settings_getImplementationName() throw()
376 : {
377 38 : return OUString( "com.sun.star.comp.Calc.XMLOasisSettingsExporter" );
378 : }
379 :
380 3 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Settings_getSupportedServiceNames() throw()
381 : {
382 3 : const OUString aServiceName( ScXMLOasisExport_Settings_getImplementationName() );
383 3 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
384 3 : return aSeq;
385 : }
386 :
387 7 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Settings_createInstance(
388 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
389 : {
390 7 : return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), EXPORT_SETTINGS|EXPORT_OASIS);
391 : }
392 : //----------------------------------------------------------------------------
393 :
394 : class ScXMLShapeExport : public XMLShapeExport
395 : {
396 : public:
397 16 : ScXMLShapeExport(SvXMLExport& rExp) : XMLShapeExport(rExp) {}
398 : ~ScXMLShapeExport();
399 :
400 : /** is called before a shape element for the given XShape is exported */
401 : virtual void onExport( const uno::Reference < drawing::XShape >& xShape );
402 : };
403 :
404 32 : ScXMLShapeExport::~ScXMLShapeExport()
405 : {
406 32 : }
407 :
408 2 : void ScXMLShapeExport::onExport( const uno::Reference < drawing::XShape >& xShape )
409 : {
410 2 : uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
411 2 : if( xShapeProp.is() )
412 : {
413 2 : sal_Int16 nLayerID = 0;
414 2 : if( (xShapeProp->getPropertyValue(OUString( SC_LAYERID )) >>= nLayerID) && (nLayerID == SC_LAYER_BACK) )
415 0 : GetExport().AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_BACKGROUND, XML_TRUE);
416 2 : }
417 2 : }
418 :
419 : //----------------------------------------------------------------------------
420 :
421 34 : sal_Int16 ScXMLExport::GetFieldUnit()
422 : {
423 : css::uno::Reference<css::sheet::XGlobalSheetSettings> xProperties =
424 34 : css::sheet::GlobalSheetSettings::create( comphelper::getProcessComponentContext() );
425 34 : return xProperties->getMetric();
426 : }
427 :
428 :
429 : // #110680#
430 34 : ScXMLExport::ScXMLExport(
431 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
432 : const sal_uInt16 nExportFlag)
433 34 : : SvXMLExport( SvXMLUnitConverter::GetMeasureUnit(GetFieldUnit()),
434 : xContext, XML_SPREADSHEET, nExportFlag ),
435 : pDoc(NULL),
436 : nSourceStreamPos(0),
437 : pNumberFormatAttributesExportHelper(NULL),
438 : pSharedData(NULL),
439 : pColumnStyles(NULL),
440 : pRowStyles(NULL),
441 : pCellStyles(NULL),
442 : pRowFormatRanges(NULL),
443 : aTableStyles(),
444 : pGroupColumns (NULL),
445 : pGroupRows (NULL),
446 : pDefaults(NULL),
447 : pChartListener(NULL),
448 : pCurrentCell(NULL),
449 : pMergedRangesContainer(NULL),
450 : pValidationsContainer(NULL),
451 : pCellsItr(NULL),
452 : pChangeTrackingExportHelper(NULL),
453 : sLayerID( SC_LAYERID ),
454 : sCaptionShape("com.sun.star.drawing.CaptionShape"),
455 : nOpenRow(-1),
456 : nProgressCount(0),
457 : nCurrentTable(0),
458 : bHasRowHeader(false),
459 : bRowHeaderOpen(false),
460 68 : mbShowProgress( false )
461 : {
462 34 : if (getExportFlags() & EXPORT_CONTENT)
463 : {
464 10 : pGroupColumns = new ScMyOpenCloseColumnRowGroup(*this, XML_TABLE_COLUMN_GROUP);
465 10 : pGroupRows = new ScMyOpenCloseColumnRowGroup(*this, XML_TABLE_ROW_GROUP);
466 10 : pColumnStyles = new ScColumnStyles();
467 10 : pRowStyles = new ScRowStyles();
468 10 : pRowFormatRanges = new ScRowFormatRanges();
469 10 : pMergedRangesContainer = new ScMyMergedRangesContainer();
470 10 : pValidationsContainer = new ScMyValidationsContainer();
471 10 : pCellsItr = new ScMyNotEmptyCellsIterator(*this);
472 10 : pDefaults = new ScMyDefaultStyles();
473 : }
474 34 : pCellStyles = new ScFormatRangeStyles();
475 :
476 : // document is not set here - create ScChangeTrackingExportHelper later
477 :
478 34 : xScPropHdlFactory = new XMLScPropHdlFactory;
479 34 : xCellStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScCellStylesProperties, xScPropHdlFactory);
480 34 : xColumnStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScColumnStylesProperties, xScPropHdlFactory);
481 34 : xRowStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScRowStylesProperties, xScPropHdlFactory);
482 34 : xTableStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScTableStylesProperties, xScPropHdlFactory);
483 34 : xCellStylesExportPropertySetMapper = new ScXMLCellExportPropertyMapper(xCellStylesPropertySetMapper);
484 34 : xCellStylesExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(*this));
485 34 : xColumnStylesExportPropertySetMapper = new ScXMLColumnExportPropertyMapper(xColumnStylesPropertySetMapper);
486 34 : xRowStylesExportPropertySetMapper = new ScXMLRowExportPropertyMapper(xRowStylesPropertySetMapper);
487 34 : xTableStylesExportPropertySetMapper = new ScXMLTableExportPropertyMapper(xTableStylesPropertySetMapper);
488 :
489 : GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_CELL, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME),
490 34 : xCellStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX));
491 : GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_COLUMN, OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME),
492 34 : xColumnStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX));
493 : GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_ROW, OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME),
494 34 : xRowStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX));
495 : GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_TABLE, OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME),
496 34 : xTableStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX));
497 :
498 34 : if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
499 : {
500 : // This name is reserved for the external ref cache tables. This
501 : // should not conflict with user-defined styles since this name is
502 : // used for a table style which is not available in the UI.
503 20 : sExternalRefTabStyleName = OUString("ta_extref");
504 20 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_TABLE, sExternalRefTabStyleName);
505 :
506 20 : sAttrName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_NAME));
507 20 : sAttrStyleName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_STYLE_NAME));
508 20 : sAttrColumnsRepeated = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_NUMBER_COLUMNS_REPEATED));
509 20 : sAttrFormula = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_FORMULA));
510 20 : sAttrStringValue = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_STRING_VALUE));
511 20 : sAttrValueType = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE_TYPE));
512 20 : sElemCell = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_CELL));
513 20 : sElemCoveredCell = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_COVERED_TABLE_CELL));
514 20 : sElemCol = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_COLUMN));
515 20 : sElemRow = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_ROW));
516 20 : sElemTab = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE));
517 20 : sElemP = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TEXT, GetXMLToken(XML_P));
518 : }
519 34 : }
520 :
521 :
522 102 : ScXMLExport::~ScXMLExport()
523 : {
524 34 : delete pGroupColumns;
525 34 : delete pGroupRows;
526 34 : delete pColumnStyles;
527 34 : delete pRowStyles;
528 34 : delete pCellStyles;
529 34 : delete pRowFormatRanges;
530 34 : delete pMergedRangesContainer;
531 34 : delete pValidationsContainer;
532 34 : delete pChangeTrackingExportHelper;
533 34 : delete pChartListener;
534 34 : delete pCellsItr;
535 34 : delete pDefaults;
536 34 : delete pNumberFormatAttributesExportHelper;
537 68 : }
538 :
539 0 : void ScXMLExport::SetSourceStream( const uno::Reference<io::XInputStream>& xNewStream )
540 : {
541 0 : xSourceStream = xNewStream;
542 :
543 0 : if ( xSourceStream.is() )
544 : {
545 : // make sure it's a plain UTF-8 stream as written by OOo itself
546 :
547 0 : const sal_Char pXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
548 0 : sal_Int32 nLen = strlen(pXmlHeader);
549 :
550 0 : uno::Sequence<sal_Int8> aFileStart(nLen);
551 0 : sal_Int32 nRead = xSourceStream->readBytes( aFileStart, nLen );
552 :
553 0 : if ( nRead != nLen || memcmp( aFileStart.getConstArray(), pXmlHeader, nLen ) != 0 )
554 : {
555 : // invalid - ignore stream, save normally
556 0 : xSourceStream.clear();
557 : }
558 : else
559 : {
560 : // keep track of the bytes already read
561 0 : nSourceStreamPos = nRead;
562 :
563 0 : const ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetModel())->GetSheetSaveData();
564 0 : if (pSheetData)
565 : {
566 : // add the loaded namespaces to the name space map
567 :
568 0 : if ( !pSheetData->AddLoadedNamespaces( _GetNamespaceMap() ) )
569 : {
570 : // conflicts in the namespaces - ignore the stream, save normally
571 0 : xSourceStream.clear();
572 : }
573 : }
574 0 : }
575 : }
576 0 : }
577 :
578 0 : sal_Int32 ScXMLExport::GetNumberFormatStyleIndex(sal_Int32 nNumFmt) const
579 : {
580 0 : NumberFormatIndexMap::const_iterator itr = aNumFmtIndexMap.find(nNumFmt);
581 0 : if (itr == aNumFmtIndexMap.end())
582 0 : return -1;
583 :
584 0 : return itr->second;
585 : }
586 :
587 : namespace {
588 :
589 : /**
590 : * Update the progress bar state when an instance of this class goes out of
591 : * scope.
592 : */
593 : class ProgressBarUpdater
594 : {
595 : ProgressBarHelper& mrHelper;
596 : const sal_Int32& mrTableCount;
597 : const sal_Int32& mrShapesCount;
598 : const sal_Int32 mnCellCount;
599 : public:
600 : ProgressBarUpdater(ProgressBarHelper& rHelper,
601 : const sal_Int32& rTableCount, const sal_Int32& rShapesCount,
602 : const sal_Int32 nCellCount) :
603 : mrHelper(rHelper),
604 : mrTableCount(rTableCount),
605 : mrShapesCount(rShapesCount),
606 : mnCellCount(nCellCount) {}
607 :
608 : ~ProgressBarUpdater()
609 : {
610 : sal_Int32 nRef = mnCellCount + (2 * mrTableCount) + (2 * mrShapesCount);
611 : mrHelper.SetReference(nRef);
612 : mrHelper.SetValue(0);
613 : }
614 : };
615 :
616 : }
617 :
618 8 : void ScXMLExport::CollectSharedData(sal_Int32& nTableCount, sal_Int32& nShapesCount)
619 : {
620 8 : if (!GetModel().is())
621 0 : return;
622 :
623 8 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc(GetModel(), uno::UNO_QUERY);
624 8 : if (!xSpreadDoc.is())
625 0 : return;
626 :
627 16 : uno::Reference<container::XIndexAccess> xIndex(xSpreadDoc->getSheets(), uno::UNO_QUERY);
628 8 : if (!xIndex.is())
629 0 : return;
630 :
631 8 : nTableCount = xIndex->getCount();
632 8 : if (!pSharedData)
633 8 : CreateSharedData(nTableCount);
634 :
635 8 : pCellStyles->AddNewTable(nTableCount - 1);
636 :
637 17 : for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
638 : {
639 9 : pDoc->GetNotes(nTable)->CreateAllNoteCaptions(nTable);
640 9 : nCurrentTable = sal::static_int_cast<sal_uInt16>(nTable);
641 9 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIndex->getByIndex(nTable), uno::UNO_QUERY);
642 9 : if (!xDrawPageSupplier.is())
643 0 : continue;
644 :
645 18 : uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage());
646 18 : ScMyDrawPage aDrawPage;
647 9 : aDrawPage.bHasForms = false;
648 9 : aDrawPage.xDrawPage.set(xDrawPage);
649 9 : pSharedData->AddDrawPage(aDrawPage, nTable);
650 18 : uno::Reference<container::XIndexAccess> xShapesIndex(xDrawPage, uno::UNO_QUERY);
651 9 : if (!xShapesIndex.is())
652 0 : continue;
653 :
654 9 : sal_Int32 nShapes = xShapesIndex->getCount();
655 11 : for (sal_Int32 nShape = 0; nShape < nShapes; ++nShape)
656 : {
657 2 : uno::Reference<drawing::XShape> xShape(xShapesIndex->getByIndex(nShape), uno::UNO_QUERY);
658 2 : if (!xShape.is())
659 0 : continue;
660 :
661 4 : uno::Reference<beans::XPropertySet> xShapeProp(xShape, uno::UNO_QUERY);
662 2 : if (!xShapeProp.is())
663 0 : continue;
664 :
665 2 : sal_Int16 nLayerID = 0;
666 2 : bool bExtracted = xShapeProp->getPropertyValue(sLayerID) >>= nLayerID;
667 2 : if (!bExtracted)
668 0 : continue;
669 :
670 2 : if ((nLayerID == SC_LAYER_INTERN) || (nLayerID == SC_LAYER_HIDDEN))
671 : {
672 0 : CollectInternalShape(xShape);
673 0 : continue;
674 : }
675 :
676 2 : ++nShapesCount;
677 :
678 2 : SvxShape* pShapeImp = SvxShape::getImplementation(xShape);
679 2 : if (!pShapeImp)
680 0 : continue;
681 :
682 2 : SdrObject* pSdrObj = pShapeImp->GetSdrObject();
683 2 : if (!pSdrObj)
684 0 : continue;
685 :
686 2 : if (ScDrawObjData *pAnchor = ScDrawLayer::GetNonRotatedObjData(pSdrObj))
687 : {
688 2 : ScMyShape aMyShape;
689 2 : aMyShape.aAddress = pAnchor->maStart;
690 : SAL_WARN_IF(aMyShape.aAddress.Tab() != nTable, "sc", "not anchored to current sheet!");
691 2 : aMyShape.aAddress.SetTab(nTable);
692 2 : aMyShape.aEndAddress = pAnchor->maEnd;
693 2 : aMyShape.aEndAddress.SetTab( nTable );
694 2 : aMyShape.nEndX = pAnchor->maEndOffset.X();
695 2 : aMyShape.nEndY = pAnchor->maEndOffset.Y();
696 2 : aMyShape.xShape = xShape;
697 2 : pSharedData->AddNewShape(aMyShape);
698 2 : pSharedData->SetLastColumn(nTable, pAnchor->maStart.Col());
699 2 : pSharedData->SetLastRow(nTable, pAnchor->maStart.Row());
700 : }
701 : else
702 0 : pSharedData->AddTableShape(nTable, xShape);
703 2 : }
704 17 : }
705 : }
706 :
707 8 : void ScXMLExport::CollectShapesAutoStyles(const sal_Int32 nTableCount)
708 : {
709 : // #i84077# To avoid compiler warnings about uninitialized aShapeItr,
710 : // it's initialized using this dummy list. The iterator contains shapes
711 : // from all sheets, so it can't be declared inside the nTable loop where
712 : // it is used.
713 8 : ScMyShapeList aDummyInitList;
714 :
715 8 : pSharedData->SortShapesContainer();
716 8 : pSharedData->SortNoteShapes();
717 8 : const ScMyShapeList* pShapeList(NULL);
718 8 : ScMyShapeList::const_iterator aShapeItr = aDummyInitList.end();
719 8 : if (pSharedData->GetShapesContainer())
720 : {
721 2 : pShapeList = pSharedData->GetShapesContainer()->GetShapes();
722 2 : aShapeItr = pShapeList->begin();
723 : }
724 8 : if (pSharedData->HasDrawPage())
725 : {
726 17 : for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
727 : {
728 9 : uno::Reference<drawing::XDrawPage> xDrawPage(pSharedData->GetDrawPage(nTable));
729 18 : uno::Reference<drawing::XShapes> xShapes (xDrawPage, uno::UNO_QUERY);
730 :
731 9 : if (xShapes.is())
732 : {
733 9 : GetShapeExport()->seekShapes(xShapes);
734 9 : uno::Reference< form::XFormsSupplier2 > xFormsSupplier( xDrawPage, uno::UNO_QUERY );
735 9 : if( xFormsSupplier.is() && xFormsSupplier->hasForms() )
736 : {
737 0 : GetFormExport()->examineForms(xDrawPage);
738 0 : pSharedData->SetDrawPageHasForms(nTable, true);
739 : }
740 9 : ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
741 9 : if (pTableShapes)
742 : {
743 0 : ScMyTableXShapes::iterator aItr((*pTableShapes)[nTable].begin());
744 0 : ScMyTableXShapes::iterator aEndItr((*pTableShapes)[nTable].end());
745 0 : while (aItr != aEndItr)
746 : {
747 0 : GetShapeExport()->collectShapeAutoStyles(*aItr);
748 0 : IncrementProgressBar(false);
749 0 : ++aItr;
750 : }
751 : }
752 9 : if (pShapeList)
753 : {
754 2 : ScMyShapeList::const_iterator aEndItr(pShapeList->end());
755 6 : while (aShapeItr != aEndItr && (static_cast<sal_Int32>(aShapeItr->aAddress.Tab()) == nTable))
756 : {
757 2 : GetShapeExport()->collectShapeAutoStyles(aShapeItr->xShape);
758 2 : IncrementProgressBar(false);
759 2 : ++aShapeItr;
760 : }
761 : }
762 9 : const ScMyNoteShapeList* pNoteShapes = NULL;
763 9 : ScMyNoteShapeList::const_iterator aNoteShapeItr;
764 9 : ScMyNoteShapeList::const_iterator aNoteShapeEndItr;
765 9 : if (pSharedData->GetNoteShapes())
766 : {
767 0 : pNoteShapes = pSharedData->GetNoteShapes()->GetNotes();
768 0 : if (pNoteShapes)
769 : {
770 0 : aNoteShapeItr = pNoteShapes->begin();
771 0 : aNoteShapeEndItr = pNoteShapes->end();
772 : }
773 : }
774 9 : if (pNoteShapes)
775 : {
776 0 : while (aNoteShapeItr != aNoteShapeEndItr)
777 : {
778 0 : if (static_cast<sal_Int32>(aNoteShapeItr->aPos.Tab()) == nTable)
779 0 : GetShapeExport()->collectShapeAutoStyles(aNoteShapeItr->xShape);
780 0 : ++aNoteShapeItr;
781 : }
782 9 : }
783 : }
784 9 : }
785 : }
786 8 : pSharedData->SortNoteShapes(); // sort twice, because some more shapes are added
787 8 : }
788 :
789 4 : void ScXMLExport::_ExportMeta()
790 : {
791 4 : sal_Int32 nCellCount(pDoc ? pDoc->GetCellCount() : 0);
792 4 : sal_Int32 nTableCount(0);
793 4 : sal_Int32 nShapesCount(0);
794 4 : GetAutoStylePool()->ClearEntries();
795 4 : CollectSharedData(nTableCount, nShapesCount);
796 :
797 4 : uno::Sequence<beans::NamedValue> stats(3);
798 8 : stats[0] = beans::NamedValue(OUString("TableCount"),
799 4 : uno::makeAny(nTableCount));
800 8 : stats[1] = beans::NamedValue(OUString("CellCount"),
801 4 : uno::makeAny(nCellCount));
802 8 : stats[2] = beans::NamedValue(OUString("ObjectCount"),
803 4 : uno::makeAny(nShapesCount));
804 :
805 : // update document statistics at the model
806 4 : uno::Reference<document::XDocumentPropertiesSupplier> xPropSup(GetModel(),
807 8 : uno::UNO_QUERY_THROW);
808 : uno::Reference<document::XDocumentProperties> xDocProps(
809 8 : xPropSup->getDocumentProperties());
810 4 : if (xDocProps.is()) {
811 4 : xDocProps->setDocumentStatistics(stats);
812 : }
813 :
814 : // export document properties
815 8 : SvXMLExport::_ExportMeta();
816 4 : }
817 :
818 16 : void ScXMLExport::_ExportFontDecls()
819 : {
820 16 : GetFontAutoStylePool(); // make sure the pool is created
821 16 : SvXMLExport::_ExportFontDecls();
822 16 : }
823 :
824 18 : table::CellRangeAddress ScXMLExport::GetEndAddress(const uno::Reference<sheet::XSpreadsheet>& xTable, const sal_Int32 /* nTable */)
825 : {
826 18 : table::CellRangeAddress aCellAddress;
827 18 : uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursor());
828 36 : uno::Reference<sheet::XUsedAreaCursor> xUsedArea (xCursor, uno::UNO_QUERY);
829 36 : uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
830 18 : if (xUsedArea.is() && xCellAddress.is())
831 : {
832 18 : xUsedArea->gotoEndOfUsedArea(true);
833 18 : aCellAddress = xCellAddress->getRangeAddress();
834 : }
835 36 : return aCellAddress;
836 : }
837 :
838 8 : void ScXMLExport::GetAreaLinks( uno::Reference< sheet::XSpreadsheetDocument>& xSpreadDoc,
839 : ScMyAreaLinksContainer& rAreaLinks )
840 : {
841 8 : uno::Reference< beans::XPropertySet > xPropSet( xSpreadDoc, uno::UNO_QUERY );
842 16 : if( !xPropSet.is() ) return;
843 :
844 16 : uno::Reference< container::XIndexAccess > xLinksIAccess( xPropSet->getPropertyValue( OUString( SC_UNO_AREALINKS ) ), uno::UNO_QUERY);
845 8 : if( xLinksIAccess.is() )
846 : {
847 8 : const OUString sFilter( SC_UNONAME_FILTER );
848 16 : const OUString sFilterOpt( SC_UNONAME_FILTOPT );
849 16 : const OUString sURL( SC_UNONAME_LINKURL );
850 16 : const OUString sRefresh( SC_UNONAME_REFDELAY );
851 :
852 8 : sal_Int32 nCount(xLinksIAccess->getCount());
853 8 : for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
854 : {
855 0 : uno::Reference< sheet::XAreaLink > xAreaLink(xLinksIAccess->getByIndex( nIndex ), uno::UNO_QUERY);
856 0 : if( xAreaLink.is() )
857 : {
858 0 : ScMyAreaLink aAreaLink;
859 0 : aAreaLink.aDestRange = xAreaLink->getDestArea();
860 0 : aAreaLink.sSourceStr = xAreaLink->getSourceArea();
861 0 : uno::Reference< beans::XPropertySet > xLinkProp( xAreaLink, uno::UNO_QUERY );
862 0 : if( xLinkProp.is() )
863 : {
864 0 : xLinkProp->getPropertyValue( sFilter ) >>= aAreaLink.sFilter;
865 0 : xLinkProp->getPropertyValue( sFilterOpt ) >>= aAreaLink.sFilterOptions;
866 0 : xLinkProp->getPropertyValue( sURL ) >>= aAreaLink.sURL;
867 0 : xLinkProp->getPropertyValue( sRefresh ) >>= aAreaLink.nRefresh;
868 : }
869 0 : rAreaLinks.AddNewAreaLink( aAreaLink );
870 : }
871 8 : }
872 : }
873 16 : rAreaLinks.Sort();
874 : }
875 :
876 : // core implementation
877 8 : void ScXMLExport::GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp )
878 : {
879 8 : if (pDoc)
880 : {
881 8 : ScDetOpList* pOpList(pDoc->GetDetOpList());
882 8 : if( pOpList )
883 : {
884 0 : size_t nCount = pOpList->Count();
885 0 : for (size_t nIndex = 0; nIndex < nCount; ++nIndex )
886 : {
887 0 : const ScDetOpData* pDetData = pOpList->GetObject( nIndex);
888 0 : if( pDetData )
889 : {
890 0 : const ScAddress& rDetPos = pDetData->GetPos();
891 0 : SCTAB nTab = rDetPos.Tab();
892 0 : if ( nTab < pDoc->GetTableCount() )
893 : {
894 0 : rDetOp.AddOperation( pDetData->GetOperation(), rDetPos, static_cast<sal_uInt32>( nIndex) );
895 :
896 : // cells with detective operations are written even if empty
897 0 : pSharedData->SetLastColumn( nTab, rDetPos.Col() );
898 0 : pSharedData->SetLastRow( nTab, rDetPos.Row() );
899 : }
900 : }
901 : }
902 0 : rDetOp.Sort();
903 : }
904 : }
905 8 : }
906 :
907 20 : void ScXMLExport::WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex,
908 : const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible)
909 : {
910 20 : CheckAttrList();
911 20 : AddAttribute(sAttrStyleName, *pColumnStyles->GetStyleNameByIndex(nStyleIndex));
912 20 : if (!bIsVisible)
913 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
914 20 : if (nRepeatColumns > 1)
915 : {
916 3 : OUString sOUEndCol(OUString::number(nRepeatColumns));
917 3 : AddAttribute(sAttrColumnsRepeated, sOUEndCol);
918 : }
919 20 : if (nIndex != -1)
920 20 : AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
921 20 : SvXMLElementExport aElemC(*this, sElemCol, true, true);
922 20 : }
923 :
924 10 : void ScXMLExport::WriteColumn(const sal_Int32 nColumn, const sal_Int32 nRepeatColumns,
925 : const sal_Int32 nStyleIndex, const bool bIsVisible)
926 : {
927 10 : sal_Int32 nRepeat(1);
928 10 : sal_Int32 nPrevIndex((*pDefaults->GetColDefaults())[nColumn].nIndex);
929 10 : bool bPrevAutoStyle((*pDefaults->GetColDefaults())[nColumn].bIsAutoStyle);
930 2080 : for (sal_Int32 i = nColumn + 1; i < nColumn + nRepeatColumns; ++i)
931 : {
932 4132 : if (((*pDefaults->GetColDefaults())[i].nIndex != nPrevIndex) ||
933 2062 : ((*pDefaults->GetColDefaults())[i].bIsAutoStyle != bPrevAutoStyle))
934 : {
935 10 : WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
936 10 : nPrevIndex = (*pDefaults->GetColDefaults())[i].nIndex;
937 10 : bPrevAutoStyle = (*pDefaults->GetColDefaults())[i].bIsAutoStyle;
938 10 : nRepeat = 1;
939 : }
940 : else
941 2060 : ++nRepeat;
942 : }
943 10 : WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
944 10 : }
945 :
946 0 : void ScXMLExport::OpenHeaderColumn()
947 : {
948 0 : StartElement( XML_NAMESPACE_TABLE, XML_TABLE_HEADER_COLUMNS, true );
949 0 : }
950 :
951 0 : void ScXMLExport::CloseHeaderColumn()
952 : {
953 0 : EndElement(XML_NAMESPACE_TABLE, XML_TABLE_HEADER_COLUMNS, true);
954 0 : }
955 :
956 9 : void ScXMLExport::ExportColumns(const sal_Int32 nTable, const table::CellRangeAddress& aColumnHeaderRange, const bool bHasColumnHeader)
957 : {
958 9 : sal_Int32 nColsRepeated (1);
959 : sal_Int32 nIndex;
960 9 : sal_Int32 nPrevColumn(0);
961 9 : bool bPrevIsVisible (true);
962 9 : bool bWasHeader (false);
963 9 : bool bIsHeader (false);
964 9 : bool bIsClosed (true);
965 9 : sal_Int32 nPrevIndex (-1);
966 : sal_Int32 nColumn;
967 2089 : for (nColumn = 0; nColumn <= pSharedData->GetLastColumn(nTable); ++nColumn)
968 : {
969 2080 : CheckAttrList();
970 2080 : bool bIsVisible(true);
971 2080 : nIndex = pColumnStyles->GetStyleNameIndex(nTable, nColumn, bIsVisible);
972 :
973 2080 : bIsHeader = bHasColumnHeader && (aColumnHeaderRange.StartColumn <= nColumn) && (nColumn <= aColumnHeaderRange.EndColumn);
974 2080 : if (bIsHeader != bWasHeader)
975 : {
976 0 : if (bIsHeader)
977 : {
978 0 : if (nColumn > 0)
979 : {
980 0 : WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
981 0 : if (pGroupColumns->IsGroupEnd(nColumn - 1))
982 0 : pGroupColumns->CloseGroups(nColumn - 1);
983 : }
984 0 : bPrevIsVisible = bIsVisible;
985 0 : nPrevIndex = nIndex;
986 0 : nPrevColumn = nColumn;
987 0 : nColsRepeated = 1;
988 0 : if(pGroupColumns->IsGroupStart(nColumn))
989 0 : pGroupColumns->OpenGroups(nColumn);
990 0 : OpenHeaderColumn();
991 0 : bWasHeader = true;
992 0 : bIsClosed = false;
993 : }
994 : else
995 : {
996 0 : WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
997 0 : CloseHeaderColumn();
998 0 : if (pGroupColumns->IsGroupEnd(nColumn - 1))
999 0 : pGroupColumns->CloseGroups(nColumn - 1);
1000 0 : if(pGroupColumns->IsGroupStart(nColumn))
1001 0 : pGroupColumns->OpenGroups(nColumn);
1002 0 : bPrevIsVisible = bIsVisible;
1003 0 : nPrevIndex = nIndex;
1004 0 : nPrevColumn = nColumn;
1005 0 : nColsRepeated = 1;
1006 0 : bWasHeader = false;
1007 0 : bIsClosed = true;
1008 : }
1009 : }
1010 2080 : else if (nColumn == 0)
1011 : {
1012 9 : if (pGroupColumns->IsGroupStart(nColumn))
1013 0 : pGroupColumns->OpenGroups(nColumn);
1014 9 : bPrevIsVisible = bIsVisible;
1015 9 : nPrevIndex = nIndex;
1016 : }
1017 8283 : else if ((bIsVisible == bPrevIsVisible) && (nIndex == nPrevIndex) &&
1018 6211 : !pGroupColumns->IsGroupStart(nColumn) && !pGroupColumns->IsGroupEnd(nColumn - 1))
1019 2070 : ++nColsRepeated;
1020 : else
1021 : {
1022 1 : WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
1023 1 : if (pGroupColumns->IsGroupEnd(nColumn - 1))
1024 : {
1025 0 : if (bIsHeader)
1026 0 : CloseHeaderColumn();
1027 0 : pGroupColumns->CloseGroups(nColumn - 1);
1028 0 : if (bIsHeader)
1029 0 : OpenHeaderColumn();
1030 : }
1031 1 : if (pGroupColumns->IsGroupStart(nColumn))
1032 : {
1033 0 : if (bIsHeader)
1034 0 : CloseHeaderColumn();
1035 0 : pGroupColumns->OpenGroups(nColumn);
1036 0 : if (bIsHeader)
1037 0 : OpenHeaderColumn();
1038 : }
1039 1 : bPrevIsVisible = bIsVisible;
1040 1 : nPrevIndex = nIndex;
1041 1 : nPrevColumn = nColumn;
1042 1 : nColsRepeated = 1;
1043 : }
1044 : }
1045 9 : WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
1046 9 : if (!bIsClosed)
1047 0 : CloseHeaderColumn();
1048 9 : if (pGroupColumns->IsGroupEnd(nColumn - 1))
1049 0 : pGroupColumns->CloseGroups(nColumn - 1);
1050 9 : }
1051 :
1052 8 : void ScXMLExport::ExportExternalRefCacheStyles()
1053 : {
1054 : sal_Int32 nEntryIndex = GetCellStylesPropertySetMapper()->FindEntryIndex(
1055 8 : "NumberFormat", XML_NAMESPACE_STYLE, OUString("data-style-name"));
1056 :
1057 8 : if (nEntryIndex < 0)
1058 : // No entry index for the number format is found.
1059 8 : return;
1060 :
1061 8 : ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
1062 8 : if (!pRefMgr->hasExternalData())
1063 : // No external reference data cached.
1064 8 : return;
1065 :
1066 : // Export each unique number format used in the external ref cache.
1067 0 : vector<sal_uInt32> aNumFmts;
1068 0 : pRefMgr->getAllCachedNumberFormats(aNumFmts);
1069 0 : const OUString aDefaultStyle = OUString("Default").intern();
1070 0 : for (vector<sal_uInt32>::const_iterator itr = aNumFmts.begin(), itrEnd = aNumFmts.end();
1071 : itr != itrEnd; ++itr)
1072 : {
1073 0 : sal_Int32 nNumFmt = static_cast<sal_Int32>(*itr);
1074 :
1075 0 : addDataStyle(nNumFmt);
1076 :
1077 0 : uno::Any aVal;
1078 0 : aVal <<= nNumFmt;
1079 0 : vector<XMLPropertyState> aProps;
1080 0 : aProps.push_back(XMLPropertyState(nEntryIndex, aVal));
1081 0 : aVal <<= aDefaultStyle;
1082 0 : aProps.push_back(XMLPropertyState(nEntryIndex, aVal));
1083 :
1084 0 : OUString aName;
1085 : sal_Int32 nIndex;
1086 0 : if (GetAutoStylePool()->Add(aName, XML_STYLE_FAMILY_TABLE_CELL, aDefaultStyle, aProps))
1087 : {
1088 0 : OUString* pTemp(new OUString(aName));
1089 0 : if (!pCellStyles->AddStyleName(pTemp, nIndex, true))
1090 0 : delete pTemp;
1091 : }
1092 : else
1093 : {
1094 : bool bIsAuto;
1095 : nIndex = pCellStyles->GetIndexOfStyleName(
1096 0 : aName, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX), bIsAuto);
1097 : }
1098 :
1099 : // store the number format to index mapping for later use.
1100 0 : aNumFmtIndexMap.insert(NumberFormatIndexMap::value_type(nNumFmt, nIndex));
1101 0 : }
1102 : }
1103 :
1104 261 : void ScXMLExport::WriteRowContent()
1105 : {
1106 261 : ScMyRowFormatRange aRange;
1107 261 : sal_Int32 nIndex(-1);
1108 : #if OSL_DEBUG_LEVEL > 0
1109 : sal_Int32 nPrevCol(0);
1110 : #endif
1111 261 : sal_Int32 nCols(0);
1112 261 : sal_Int32 nPrevValidationIndex(-1);
1113 261 : bool bIsAutoStyle(true);
1114 261 : bool bIsFirst(true);
1115 788 : while (pRowFormatRanges->GetNext(aRange))
1116 : {
1117 : #if OSL_DEBUG_LEVEL > 0
1118 : OSL_ENSURE(bIsFirst || (!bIsFirst && (nPrevCol + nCols == aRange.nStartColumn)), "here are some columns missing");
1119 : #endif
1120 266 : if (bIsFirst)
1121 : {
1122 223 : nIndex = aRange.nIndex;
1123 223 : nPrevValidationIndex = aRange.nValidationIndex;
1124 223 : bIsAutoStyle = aRange.bIsAutoStyle;
1125 223 : nCols = aRange.nRepeatColumns;
1126 223 : bIsFirst = false;
1127 : #if OSL_DEBUG_LEVEL > 0
1128 : nPrevCol = aRange.nStartColumn;
1129 : #endif
1130 : }
1131 : else
1132 : {
1133 56 : if (((aRange.nIndex == nIndex && aRange.bIsAutoStyle == bIsAutoStyle) ||
1134 43 : (aRange.nIndex == nIndex && nIndex == -1)) &&
1135 30 : nPrevValidationIndex == aRange.nValidationIndex)
1136 30 : nCols += aRange.nRepeatColumns;
1137 : else
1138 : {
1139 13 : if (nIndex != -1)
1140 6 : AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
1141 13 : if (nPrevValidationIndex > -1)
1142 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
1143 13 : if (nCols > 1)
1144 : {
1145 0 : OUStringBuffer aBuf;
1146 0 : ::sax::Converter::convertNumber(aBuf, nCols);
1147 0 : AddAttribute(sAttrColumnsRepeated, aBuf.makeStringAndClear());
1148 : }
1149 13 : SvXMLElementExport aElemC(*this, sElemCell, true, true);
1150 13 : nIndex = aRange.nIndex;
1151 13 : bIsAutoStyle = aRange.bIsAutoStyle;
1152 13 : nCols = aRange.nRepeatColumns;
1153 13 : nPrevValidationIndex = aRange.nValidationIndex;
1154 : #if OSL_DEBUG_LEVEL > 0
1155 : nPrevCol = aRange.nStartColumn;
1156 : #endif
1157 : }
1158 : }
1159 : }
1160 261 : if (!bIsFirst)
1161 : {
1162 223 : table::CellAddress aCellAddress;
1163 223 : if (nIndex != -1)
1164 3 : AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
1165 223 : if (nPrevValidationIndex > -1)
1166 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
1167 223 : if (nCols > 1)
1168 : {
1169 12 : OUStringBuffer aBuf;
1170 12 : ::sax::Converter::convertNumber(aBuf, nCols);
1171 12 : AddAttribute(sAttrColumnsRepeated, aBuf.makeStringAndClear());
1172 : }
1173 223 : SvXMLElementExport aElemC(*this, sElemCell, true, true);
1174 : }
1175 261 : }
1176 :
1177 49 : void ScXMLExport::WriteRowStartTag(
1178 : sal_Int32 nRow, const sal_Int32 nIndex, const sal_Int32 nEqualRows,
1179 : bool bHidden, bool bFiltered)
1180 : {
1181 49 : AddAttribute(sAttrStyleName, *pRowStyles->GetStyleNameByIndex(nIndex));
1182 49 : if (bHidden)
1183 : {
1184 0 : if (bFiltered)
1185 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_FILTER);
1186 : else
1187 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
1188 : }
1189 49 : if (nEqualRows > 1)
1190 : {
1191 5 : OUStringBuffer aBuf;
1192 5 : ::sax::Converter::convertNumber(aBuf, nEqualRows);
1193 5 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, aBuf.makeStringAndClear());
1194 : }
1195 :
1196 49 : const ScMyDefaultStyleList& rRowDefaults = *pDefaults->GetRowDefaults();
1197 49 : if ( nRow >= sal::static_int_cast<sal_Int32>( rRowDefaults.size() ) )
1198 : {
1199 : // used to happen with detective operations - if there are more cases, use the last row's style
1200 : OSL_FAIL("WriteRowStartTag: not enough defaults");
1201 0 : nRow = rRowDefaults.size() - 1;
1202 : }
1203 49 : sal_Int32 nCellStyleIndex(rRowDefaults[nRow].nIndex);
1204 49 : if (nCellStyleIndex != -1)
1205 : AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME,
1206 : *pCellStyles->GetStyleNameByIndex(nCellStyleIndex,
1207 0 : (*pDefaults->GetRowDefaults())[nRow].bIsAutoStyle));
1208 49 : StartElement( sElemRow, true);
1209 49 : }
1210 :
1211 0 : void ScXMLExport::OpenHeaderRows()
1212 : {
1213 0 : StartElement( XML_NAMESPACE_TABLE, XML_TABLE_HEADER_ROWS, true);
1214 0 : bRowHeaderOpen = true;
1215 0 : }
1216 :
1217 0 : void ScXMLExport::CloseHeaderRows()
1218 : {
1219 0 : EndElement(XML_NAMESPACE_TABLE, XML_TABLE_HEADER_ROWS, true);
1220 0 : }
1221 :
1222 49 : void ScXMLExport::OpenNewRow(
1223 : const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
1224 : bool bHidden, bool bFiltered)
1225 : {
1226 49 : nOpenRow = nStartRow;
1227 49 : if (pGroupRows->IsGroupStart(nStartRow))
1228 : {
1229 0 : if (bHasRowHeader && bRowHeaderOpen)
1230 0 : CloseHeaderRows();
1231 0 : pGroupRows->OpenGroups(nStartRow);
1232 0 : if (bHasRowHeader && bRowHeaderOpen)
1233 0 : OpenHeaderRows();
1234 : }
1235 49 : if (bHasRowHeader && !bRowHeaderOpen && nStartRow >= aRowHeaderRange.StartRow && nStartRow <= aRowHeaderRange.EndRow)
1236 : {
1237 0 : if (nStartRow == aRowHeaderRange.StartRow)
1238 0 : OpenHeaderRows();
1239 : sal_Int32 nEquals;
1240 0 : if (aRowHeaderRange.EndRow < nStartRow + nEqualRows - 1)
1241 0 : nEquals = aRowHeaderRange.EndRow - nStartRow + 1;
1242 : else
1243 0 : nEquals = nEqualRows;
1244 0 : WriteRowStartTag(nStartRow, nIndex, nEquals, bHidden, bFiltered);
1245 0 : nOpenRow = nStartRow + nEquals - 1;
1246 0 : if (nEquals < nEqualRows)
1247 : {
1248 0 : CloseRow(nStartRow + nEquals - 1);
1249 0 : WriteRowStartTag(nStartRow, nIndex, nEqualRows - nEquals, bHidden, bFiltered);
1250 0 : nOpenRow = nStartRow + nEqualRows - 1;
1251 0 : }
1252 : }
1253 : else
1254 49 : WriteRowStartTag(nStartRow, nIndex, nEqualRows, bHidden, bFiltered);
1255 49 : }
1256 :
1257 0 : void ScXMLExport::OpenAndCloseRow(
1258 : const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
1259 : bool bHidden, bool bFiltered)
1260 : {
1261 0 : OpenNewRow(nIndex, nStartRow, nEqualRows, bHidden, bFiltered);
1262 0 : WriteRowContent();
1263 0 : CloseRow(nStartRow + nEqualRows - 1);
1264 0 : pRowFormatRanges->Clear();
1265 0 : }
1266 :
1267 49 : void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLCachedRowAttrAccess& rRowAttr)
1268 : {
1269 49 : if (nRepeatRow > 1)
1270 : {
1271 5 : sal_Int32 nPrevIndex(0), nIndex;
1272 5 : bool bPrevHidden = false;
1273 5 : bool bPrevFiltered = false;
1274 5 : bool bHidden = false;
1275 5 : bool bFiltered = false;
1276 5 : sal_Int32 nEqualRows(1);
1277 5 : sal_Int32 nEndRow(nStartRow + nRepeatRow);
1278 : sal_Int32 nRow;
1279 3145706 : for (nRow = nStartRow; nRow < nEndRow; ++nRow)
1280 : {
1281 3145701 : if (nRow == nStartRow)
1282 : {
1283 5 : nPrevIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
1284 5 : if (pDoc)
1285 : {
1286 5 : bPrevHidden = rRowAttr.rowHidden(nTable, nRow);
1287 5 : bPrevFiltered = rRowAttr.rowFiltered(nTable, nRow);
1288 : }
1289 : }
1290 : else
1291 : {
1292 3145696 : nIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
1293 3145696 : if (pDoc)
1294 : {
1295 3145696 : bHidden = rRowAttr.rowHidden(nTable, nRow);
1296 3145696 : bFiltered = rRowAttr.rowFiltered(nTable, nRow);
1297 : }
1298 9437088 : if (nIndex == nPrevIndex && bHidden == bPrevHidden && bFiltered == bPrevFiltered &&
1299 6291392 : !(bHasRowHeader && ((nRow == aRowHeaderRange.StartRow) || (nRow - 1 == aRowHeaderRange.EndRow))) &&
1300 9437088 : !(pGroupRows->IsGroupStart(nRow)) &&
1301 3145696 : !(pGroupRows->IsGroupEnd(nRow - 1)))
1302 3145696 : ++nEqualRows;
1303 : else
1304 : {
1305 0 : if (nRow < nEndRow)
1306 : {
1307 0 : ScRowFormatRanges* pTempRowFormatRanges = new ScRowFormatRanges(pRowFormatRanges);
1308 0 : OpenAndCloseRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
1309 0 : delete pRowFormatRanges;
1310 0 : pRowFormatRanges = pTempRowFormatRanges;
1311 : }
1312 : else
1313 0 : OpenAndCloseRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
1314 0 : nEqualRows = 1;
1315 0 : nPrevIndex = nIndex;
1316 0 : bPrevHidden = bHidden;
1317 0 : bPrevFiltered = bFiltered;
1318 : }
1319 : }
1320 : }
1321 5 : OpenNewRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
1322 : }
1323 : else
1324 : {
1325 44 : sal_Int32 nIndex = pRowStyles->GetStyleNameIndex(nTable, nStartRow);
1326 44 : bool bHidden = false;
1327 44 : bool bFiltered = false;
1328 44 : if (pDoc)
1329 : {
1330 44 : bHidden = rRowAttr.rowHidden(nTable, nStartRow);
1331 44 : bFiltered = rRowAttr.rowFiltered(nTable, nStartRow);
1332 : }
1333 44 : OpenNewRow(nIndex, nStartRow, 1, bHidden, bFiltered);
1334 : }
1335 49 : nOpenRow = nStartRow + nRepeatRow - 1;
1336 49 : }
1337 :
1338 79 : void ScXMLExport::CloseRow(const sal_Int32 nRow)
1339 : {
1340 79 : if (nOpenRow > -1)
1341 : {
1342 49 : EndElement(sElemRow, true);
1343 49 : if (bHasRowHeader && nRow == aRowHeaderRange.EndRow)
1344 : {
1345 0 : CloseHeaderRows();
1346 0 : bRowHeaderOpen = false;
1347 : }
1348 49 : if (pGroupRows->IsGroupEnd(nRow))
1349 : {
1350 0 : if (bHasRowHeader && bRowHeaderOpen)
1351 0 : CloseHeaderRows();
1352 0 : pGroupRows->CloseGroups(nRow);
1353 0 : if (bHasRowHeader && bRowHeaderOpen)
1354 0 : OpenHeaderRows();
1355 : }
1356 : }
1357 79 : nOpenRow = -1;
1358 79 : }
1359 :
1360 221 : void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32 nStartRow,
1361 : const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet)
1362 : {
1363 221 : pRowFormatRanges->Clear();
1364 221 : ScXMLCachedRowAttrAccess aRowAttr(pDoc);
1365 221 : if (nStartRow == nEndRow)
1366 : {
1367 185 : pCellStyles->GetFormatRanges(nStartCol, nEndCol, nStartRow, nSheet, pRowFormatRanges);
1368 185 : if (nOpenRow == - 1)
1369 7 : OpenRow(nSheet, nStartRow, 1, aRowAttr);
1370 185 : WriteRowContent();
1371 185 : pRowFormatRanges->Clear();
1372 : }
1373 : else
1374 : {
1375 36 : if (nOpenRow > -1)
1376 : {
1377 34 : pCellStyles->GetFormatRanges(nStartCol, pSharedData->GetLastColumn(nSheet), nStartRow, nSheet, pRowFormatRanges);
1378 34 : WriteRowContent();
1379 34 : CloseRow(nStartRow);
1380 34 : sal_Int32 nRows(1);
1381 34 : sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
1382 72 : while (nRows < nTotalRows)
1383 : {
1384 4 : pRowFormatRanges->Clear();
1385 4 : pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1386 4 : sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
1387 : OSL_ENSURE(nMaxRows, "something wents wrong");
1388 4 : if (nMaxRows >= nTotalRows - nRows)
1389 : {
1390 4 : OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
1391 4 : nRows += nTotalRows - nRows;
1392 : }
1393 : else
1394 : {
1395 0 : OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
1396 0 : nRows += nMaxRows;
1397 : }
1398 4 : if (!pRowFormatRanges->GetSize())
1399 0 : pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1400 4 : WriteRowContent();
1401 4 : CloseRow(nStartRow + nRows - 1);
1402 : }
1403 34 : if (nTotalRows == 1)
1404 30 : CloseRow(nStartRow);
1405 34 : OpenRow(nSheet, nEndRow, 1, aRowAttr);
1406 34 : pRowFormatRanges->Clear();
1407 34 : pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
1408 34 : WriteRowContent();
1409 : }
1410 : else
1411 : {
1412 2 : sal_Int32 nRows(0);
1413 2 : sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
1414 6 : while (nRows < nTotalRows)
1415 : {
1416 2 : pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1417 2 : sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
1418 2 : if (nMaxRows >= nTotalRows - nRows)
1419 : {
1420 2 : OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
1421 2 : nRows += nTotalRows - nRows;
1422 : }
1423 : else
1424 : {
1425 0 : OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
1426 0 : nRows += nMaxRows;
1427 : }
1428 2 : if (!pRowFormatRanges->GetSize())
1429 0 : pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1430 2 : WriteRowContent();
1431 2 : CloseRow(nStartRow + nRows - 1);
1432 : }
1433 2 : OpenRow(nSheet, nEndRow, 1, aRowAttr);
1434 2 : pRowFormatRanges->Clear();
1435 2 : pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
1436 2 : WriteRowContent();
1437 : }
1438 : }
1439 221 : }
1440 :
1441 9 : void ScXMLExport::GetColumnRowHeader(bool& rHasColumnHeader, table::CellRangeAddress& rColumnHeaderRange,
1442 : bool& rHasRowHeader, table::CellRangeAddress& rRowHeaderRange,
1443 : OUString& rPrintRanges) const
1444 : {
1445 9 : uno::Reference <sheet::XPrintAreas> xPrintAreas (xCurrentTable, uno::UNO_QUERY);
1446 9 : if (xPrintAreas.is())
1447 : {
1448 9 : rHasRowHeader = xPrintAreas->getPrintTitleRows();
1449 9 : rHasColumnHeader = xPrintAreas->getPrintTitleColumns();
1450 9 : rRowHeaderRange = xPrintAreas->getTitleRows();
1451 9 : rColumnHeaderRange = xPrintAreas->getTitleColumns();
1452 9 : uno::Sequence< table::CellRangeAddress > aRangeList( xPrintAreas->getPrintAreas() );
1453 9 : ScRangeStringConverter::GetStringFromRangeList( rPrintRanges, aRangeList, pDoc, FormulaGrammar::CONV_OOO );
1454 9 : }
1455 9 : }
1456 :
1457 0 : void ScXMLExport::FillFieldGroup(ScOutlineArray* pFields, ScMyOpenCloseColumnRowGroup* pGroups)
1458 : {
1459 0 : size_t nDepth = pFields->GetDepth();
1460 0 : for (size_t i = 0; i < nDepth; ++i)
1461 : {
1462 0 : size_t nFields = pFields->GetCount(i);
1463 0 : for (size_t j = 0; j < nFields; ++j)
1464 : {
1465 0 : ScMyColumnRowGroup aGroup;
1466 0 : const ScOutlineEntry* pEntry = pFields->GetEntry(i, j);
1467 0 : aGroup.nField = pEntry->GetStart();
1468 0 : aGroup.nLevel = static_cast<sal_Int16>(i);
1469 0 : aGroup.bDisplay = !(pEntry->IsHidden());
1470 0 : pGroups->AddGroup(aGroup, pEntry->GetEnd());
1471 : }
1472 : }
1473 0 : if (nDepth)
1474 0 : pGroups->Sort();
1475 0 : }
1476 :
1477 9 : void ScXMLExport::FillColumnRowGroups()
1478 : {
1479 9 : if (pDoc)
1480 : {
1481 9 : ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable( static_cast<SCTAB>(nCurrentTable), false );
1482 9 : if(pOutlineTable)
1483 : {
1484 0 : ScOutlineArray* pCols(pOutlineTable->GetColArray());
1485 0 : ScOutlineArray* pRows(pOutlineTable->GetRowArray());
1486 0 : if (pCols)
1487 0 : FillFieldGroup(pCols, pGroupColumns);
1488 0 : if (pRows)
1489 0 : FillFieldGroup(pRows, pGroupRows);
1490 0 : pSharedData->SetLastColumn(nCurrentTable, pGroupColumns->GetLast());
1491 0 : pSharedData->SetLastRow(nCurrentTable, pGroupRows->GetLast());
1492 : }
1493 : }
1494 9 : }
1495 :
1496 8 : void ScXMLExport::SetBodyAttributes()
1497 : {
1498 8 : if (pDoc && pDoc->IsDocProtected())
1499 : {
1500 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_STRUCTURE_PROTECTED, XML_TRUE);
1501 0 : OUStringBuffer aBuffer;
1502 0 : uno::Sequence<sal_Int8> aPassHash;
1503 0 : ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
1504 0 : const ScDocProtection* p = pDoc->GetDocProtection();
1505 0 : if (p)
1506 : {
1507 0 : if (p->hasPasswordHash(PASSHASH_SHA1))
1508 : {
1509 0 : aPassHash = p->getPasswordHash(PASSHASH_SHA1);
1510 0 : eHashUsed = PASSHASH_SHA1;
1511 : }
1512 0 : else if (p->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
1513 : {
1514 0 : aPassHash = p->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
1515 0 : eHashUsed = PASSHASH_XL;
1516 : }
1517 : }
1518 0 : ::sax::Converter::encodeBase64(aBuffer, aPassHash);
1519 0 : if (!aBuffer.isEmpty())
1520 : {
1521 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
1522 0 : if ( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
1523 : {
1524 0 : if (eHashUsed == PASSHASH_XL)
1525 : {
1526 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
1527 0 : ScPassHashHelper::getHashURI(PASSHASH_XL));
1528 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
1529 0 : ScPassHashHelper::getHashURI(PASSHASH_SHA1));
1530 : }
1531 0 : else if (eHashUsed == PASSHASH_SHA1)
1532 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
1533 0 : ScPassHashHelper::getHashURI(PASSHASH_SHA1));
1534 : }
1535 0 : }
1536 : }
1537 8 : }
1538 :
1539 0 : static bool lcl_CopyStreamElement( const uno::Reference< io::XInputStream >& xInput,
1540 : const uno::Reference< io::XOutputStream >& xOutput,
1541 : sal_Int32 nCount )
1542 : {
1543 0 : const sal_Int32 nBufSize = 16*1024;
1544 0 : uno::Sequence<sal_Int8> aSequence(nBufSize);
1545 :
1546 0 : sal_Int32 nRemaining = nCount;
1547 0 : bool bFirst = true;
1548 :
1549 0 : while ( nRemaining > 0 )
1550 : {
1551 0 : sal_Int32 nRead = xInput->readBytes( aSequence, std::min( nRemaining, nBufSize ) );
1552 0 : if (bFirst)
1553 : {
1554 : // safety check: Make sure the copied part actually points to the start of an element
1555 0 : if ( nRead < 1 || aSequence[0] != static_cast<sal_Int8>('<') )
1556 : {
1557 0 : return false; // abort and set an error
1558 : }
1559 0 : bFirst = false;
1560 : }
1561 0 : if (nRead == nRemaining)
1562 : {
1563 : // safety check: Make sure the copied part also ends at the end of an element
1564 0 : if ( aSequence[nRead-1] != static_cast<sal_Int8>('>') )
1565 : {
1566 0 : return false; // abort and set an error
1567 : }
1568 : }
1569 :
1570 0 : if ( nRead == nBufSize )
1571 : {
1572 0 : xOutput->writeBytes( aSequence );
1573 0 : nRemaining -= nRead;
1574 : }
1575 : else
1576 : {
1577 0 : if ( nRead > 0 )
1578 : {
1579 0 : uno::Sequence<sal_Int8> aTempBuf( aSequence.getConstArray(), nRead );
1580 0 : xOutput->writeBytes( aTempBuf );
1581 : }
1582 0 : nRemaining = 0;
1583 : }
1584 : }
1585 0 : return true; // successful
1586 : }
1587 :
1588 0 : static void lcl_SkipBytesInBlocks( const uno::Reference< io::XInputStream >& xInput, sal_Int32 nBytesToSkip )
1589 : {
1590 : // skipBytes in zip stream is implemented as reading.
1591 : // For now, split into several calls to avoid allocating a large buffer.
1592 : // Later, skipBytes should be changed.
1593 :
1594 0 : const sal_Int32 nMaxSize = 32*1024;
1595 :
1596 0 : if ( nBytesToSkip > 0 )
1597 : {
1598 0 : sal_Int32 nRemaining = nBytesToSkip;
1599 0 : while ( nRemaining > 0 )
1600 : {
1601 0 : sal_Int32 nSkip = std::min( nRemaining, nMaxSize );
1602 0 : xInput->skipBytes( nSkip );
1603 0 : nRemaining -= nSkip;
1604 : }
1605 : }
1606 0 : }
1607 :
1608 0 : void ScXMLExport::CopySourceStream( sal_Int32 nStartOffset, sal_Int32 nEndOffset, sal_Int32& rNewStart, sal_Int32& rNewEnd )
1609 : {
1610 0 : uno::Reference<xml::sax::XDocumentHandler> xHandler = GetDocHandler();
1611 0 : uno::Reference<io::XActiveDataSource> xDestSource( xHandler, uno::UNO_QUERY );
1612 0 : if ( xDestSource.is() )
1613 : {
1614 0 : uno::Reference<io::XOutputStream> xDestStream = xDestSource->getOutputStream();
1615 0 : uno::Reference<io::XSeekable> xDestSeek( xDestStream, uno::UNO_QUERY );
1616 0 : if ( xDestSeek.is() )
1617 : {
1618 : // temporary: set same stream again to clear buffer
1619 0 : xDestSource->setOutputStream( xDestStream );
1620 :
1621 0 : if ( getExportFlags() & EXPORT_PRETTY )
1622 : {
1623 0 : const OString aOutStr("\n ");
1624 0 : uno::Sequence<sal_Int8> aOutSeq( (sal_Int8*)aOutStr.getStr(), aOutStr.getLength() );
1625 0 : xDestStream->writeBytes( aOutSeq );
1626 : }
1627 :
1628 0 : rNewStart = (sal_Int32)xDestSeek->getPosition();
1629 :
1630 0 : if ( nStartOffset > nSourceStreamPos )
1631 0 : lcl_SkipBytesInBlocks( xSourceStream, nStartOffset - nSourceStreamPos );
1632 :
1633 0 : if ( !lcl_CopyStreamElement( xSourceStream, xDestStream, nEndOffset - nStartOffset ) )
1634 : {
1635 : // If copying went wrong, set an error.
1636 : // ScXMLImportWrapper then resets all stream flags, so the next save attempt will use normal saving.
1637 :
1638 0 : uno::Sequence<OUString> aEmptySeq;
1639 0 : SetError(XMLERROR_CANCEL|XMLERROR_FLAG_SEVERE, aEmptySeq);
1640 : }
1641 0 : nSourceStreamPos = nEndOffset;
1642 :
1643 0 : rNewEnd = (sal_Int32)xDestSeek->getPosition();
1644 0 : }
1645 0 : }
1646 0 : }
1647 :
1648 8 : void ScXMLExport::_ExportContent()
1649 : {
1650 8 : nCurrentTable = 0;
1651 8 : if (!pSharedData)
1652 : {
1653 0 : sal_Int32 nTableCount(0);
1654 0 : sal_Int32 nShapesCount(0);
1655 0 : CollectSharedData(nTableCount, nShapesCount);
1656 : OSL_FAIL("no shared data setted");
1657 : }
1658 8 : ScXMLExportDatabaseRanges aExportDatabaseRanges(*this);
1659 8 : if (!GetModel().is())
1660 0 : return;
1661 :
1662 16 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
1663 8 : if ( !xSpreadDoc.is() )
1664 0 : return;
1665 :
1666 8 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(xSpreadDoc)->GetSheetSaveData();
1667 8 : if (pSheetData)
1668 8 : pSheetData->ResetSaveEntries();
1669 :
1670 16 : uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
1671 8 : if ( xIndex.is() )
1672 : {
1673 : //_GetNamespaceMap().ClearQNamesCache();
1674 8 : pChangeTrackingExportHelper->CollectAndWriteChanges();
1675 8 : WriteCalculationSettings(xSpreadDoc);
1676 8 : sal_Int32 nTableCount(xIndex->getCount());
1677 8 : ScMyAreaLinksContainer aAreaLinks;
1678 8 : GetAreaLinks( xSpreadDoc, aAreaLinks );
1679 16 : ScMyEmptyDatabaseRangesContainer aEmptyRanges(aExportDatabaseRanges.GetEmptyDatabaseRanges());
1680 16 : ScMyDetectiveOpContainer aDetectiveOpContainer;
1681 8 : GetDetectiveOpList( aDetectiveOpContainer );
1682 :
1683 8 : pCellStyles->Sort();
1684 8 : pMergedRangesContainer->Sort();
1685 8 : pSharedData->GetDetectiveObjContainer()->Sort();
1686 :
1687 8 : pCellsItr->Clear();
1688 8 : pCellsItr->SetShapes( pSharedData->GetShapesContainer() );
1689 8 : pCellsItr->SetNoteShapes( pSharedData->GetNoteShapes() );
1690 8 : pCellsItr->SetMergedRanges( pMergedRangesContainer );
1691 8 : pCellsItr->SetAreaLinks( &aAreaLinks );
1692 8 : pCellsItr->SetEmptyDatabaseRanges( &aEmptyRanges );
1693 8 : pCellsItr->SetDetectiveObj( pSharedData->GetDetectiveObjContainer() );
1694 8 : pCellsItr->SetDetectiveOp( &aDetectiveOpContainer );
1695 :
1696 8 : if (nTableCount > 0)
1697 8 : pValidationsContainer->WriteValidations(*this);
1698 8 : WriteTheLabelRanges( xSpreadDoc );
1699 17 : for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable)
1700 : {
1701 9 : sal_Int32 nStartOffset = -1;
1702 9 : sal_Int32 nEndOffset = -1;
1703 9 : if (pSheetData && pDoc && pDoc->IsStreamValid((SCTAB)nTable) && !pDoc->GetChangeTrack())
1704 0 : pSheetData->GetStreamPos( nTable, nStartOffset, nEndOffset );
1705 :
1706 9 : if ( nStartOffset >= 0 && nEndOffset >= 0 && xSourceStream.is() )
1707 : {
1708 0 : sal_Int32 nNewStart = -1;
1709 0 : sal_Int32 nNewEnd = -1;
1710 0 : CopySourceStream( nStartOffset, nEndOffset, nNewStart, nNewEnd );
1711 :
1712 : // store position of copied sheet in output
1713 0 : pSheetData->AddSavePos( nTable, nNewStart, nNewEnd );
1714 :
1715 : // skip iterator entries for this sheet
1716 0 : pCellsItr->SkipTable(static_cast<SCTAB>(nTable));
1717 : }
1718 : else
1719 : {
1720 9 : uno::Reference<sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
1721 9 : WriteTable(nTable, xTable);
1722 : }
1723 9 : IncrementProgressBar(false);
1724 8 : }
1725 : }
1726 8 : WriteExternalRefCaches();
1727 8 : WriteNamedExpressions();
1728 8 : aExportDatabaseRanges.WriteDatabaseRanges();
1729 16 : ScXMLExportDataPilot aExportDataPilot(*this);
1730 8 : aExportDataPilot.WriteDataPilots(xSpreadDoc);
1731 8 : WriteConsolidation();
1732 16 : ScXMLExportDDELinks aExportDDELinks(*this);
1733 8 : aExportDDELinks.WriteDDELinks(xSpreadDoc);
1734 8 : IncrementProgressBar(true, 0);
1735 16 : GetProgressBarHelper()->SetValue(GetProgressBarHelper()->GetReference());
1736 : }
1737 :
1738 8 : void ScXMLExport::_ExportStyles( sal_Bool bUsed )
1739 : {
1740 8 : if (!pSharedData)
1741 : {
1742 4 : sal_Int32 nTableCount(0);
1743 4 : sal_Int32 nShapesCount(0);
1744 4 : CollectSharedData(nTableCount, nShapesCount);
1745 : }
1746 8 : ScXMLStyleExport aStylesExp(*this, OUString(), GetAutoStylePool().get());
1747 8 : if (GetModel().is())
1748 : {
1749 8 : uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
1750 8 : if (xMultiServiceFactory.is())
1751 : {
1752 8 : uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance("com.sun.star.sheet.Defaults"), uno::UNO_QUERY);
1753 8 : if (xProperties.is())
1754 8 : aStylesExp.exportDefaultStyle(xProperties, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), xCellStylesExportPropertySetMapper);
1755 8 : if (pSharedData->HasShapes())
1756 : {
1757 2 : GetShapeExport()->ExportGraphicDefaults();
1758 8 : }
1759 : }
1760 16 : uno::Reference <style::XStyleFamiliesSupplier> xStyleFamiliesSupplier (GetModel(), uno::UNO_QUERY);
1761 8 : if (xStyleFamiliesSupplier.is())
1762 : {
1763 8 : uno::Reference <container::XNameAccess> xStylesFamilies(xStyleFamiliesSupplier->getStyleFamilies());
1764 8 : if (xStylesFamilies.is())
1765 : {
1766 8 : uno::Reference <container::XIndexAccess> xCellStyles(xStylesFamilies->getByName("CellStyles"), uno::UNO_QUERY);
1767 8 : if (xCellStyles.is())
1768 : {
1769 8 : sal_Int32 nCount(xCellStyles->getCount());
1770 8 : OUString sNumberFormat(SC_UNONAME_NUMFMT);
1771 56 : for (sal_Int32 i = 0; i < nCount; ++i)
1772 : {
1773 48 : uno::Reference <beans::XPropertySet> xCellProperties(xCellStyles->getByIndex(i), uno::UNO_QUERY);
1774 48 : if (xCellProperties.is())
1775 : {
1776 48 : sal_Int32 nNumberFormat = 0;
1777 48 : if (xCellProperties->getPropertyValue(sNumberFormat) >>= nNumberFormat)
1778 48 : addDataStyle(nNumberFormat);
1779 : }
1780 56 : }
1781 8 : }
1782 8 : }
1783 8 : }
1784 : }
1785 8 : exportDataStyles();
1786 :
1787 : aStylesExp.exportStyleFamily(OUString("CellStyles"),
1788 8 : OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), xCellStylesExportPropertySetMapper, false, XML_STYLE_FAMILY_TABLE_CELL);
1789 :
1790 8 : SvXMLExport::_ExportStyles(bUsed);
1791 8 : }
1792 :
1793 23 : void ScXMLExport::AddStyleFromCells(const uno::Reference<beans::XPropertySet>& xProperties,
1794 : const uno::Reference<sheet::XSpreadsheet>& xTable,
1795 : sal_Int32 nTable, const OUString* pOldName)
1796 : {
1797 : //! pass xCellRanges instead
1798 23 : uno::Reference<sheet::XSheetCellRanges> xCellRanges( xProperties, uno::UNO_QUERY );
1799 :
1800 46 : OUString SC_SCELLPREFIX(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX);
1801 46 : OUString SC_NUMBERFORMAT(SC_UNONAME_NUMFMT);
1802 :
1803 46 : OUString sStyleName;
1804 23 : sal_Int32 nNumberFormat(-1);
1805 23 : sal_Int32 nValidationIndex(-1);
1806 46 : std::vector< XMLPropertyState > xPropStates(xCellStylesExportPropertySetMapper->Filter( xProperties ));
1807 23 : std::vector< XMLPropertyState >::iterator aItr(xPropStates.begin());
1808 23 : std::vector< XMLPropertyState >::iterator aEndItr(xPropStates.end());
1809 23 : sal_Int32 nCount(0);
1810 97 : while (aItr != aEndItr)
1811 : {
1812 51 : if (aItr->mnIndex != -1)
1813 : {
1814 51 : switch (xCellStylesPropertySetMapper->GetEntryContextId(aItr->mnIndex))
1815 : {
1816 : case CTF_SC_VALIDATION :
1817 : {
1818 0 : pValidationsContainer->AddValidation(aItr->maValue, nValidationIndex);
1819 : // this is not very slow, because it is most the last property or
1820 : // if it is not the last property it is the property before the last property,
1821 : // so in the worst case only one property has to be copied, but in the best case no
1822 : // property has to be copied
1823 0 : aItr = xPropStates.erase(aItr);
1824 0 : aEndItr = xPropStates.end(); // old aEndItr is invalidated!
1825 : }
1826 0 : break;
1827 : case CTF_SC_CELLSTYLE :
1828 : {
1829 23 : aItr->maValue >>= sStyleName;
1830 23 : aItr->mnIndex = -1;
1831 23 : ++aItr;
1832 23 : ++nCount;
1833 : }
1834 23 : break;
1835 : case CTF_SC_NUMBERFORMAT :
1836 : {
1837 0 : if (aItr->maValue >>= nNumberFormat)
1838 0 : addDataStyle(nNumberFormat);
1839 0 : ++aItr;
1840 0 : ++nCount;
1841 : }
1842 0 : break;
1843 : default:
1844 : {
1845 28 : ++aItr;
1846 28 : ++nCount;
1847 : }
1848 28 : break;
1849 : }
1850 : }
1851 : else
1852 : {
1853 0 : ++aItr;
1854 0 : ++nCount;
1855 : }
1856 : }
1857 23 : if (nCount == 1) // this is the CellStyle and should be removed if alone
1858 9 : xPropStates.clear();
1859 23 : if (nNumberFormat == -1)
1860 23 : xProperties->getPropertyValue(SC_NUMBERFORMAT) >>= nNumberFormat;
1861 23 : if (!sStyleName.isEmpty())
1862 : {
1863 23 : if (!xPropStates.empty())
1864 : {
1865 : sal_Int32 nIndex;
1866 14 : if (pOldName)
1867 : {
1868 0 : if (GetAutoStylePool()->AddNamed(*pOldName, XML_STYLE_FAMILY_TABLE_CELL, sStyleName, xPropStates))
1869 : {
1870 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_CELL, *pOldName);
1871 : // add to pCellStyles, so the name is found for normal sheets
1872 0 : OUString* pTemp(new OUString(*pOldName));
1873 0 : if (!pCellStyles->AddStyleName(pTemp, nIndex))
1874 0 : delete pTemp;
1875 : }
1876 : }
1877 : else
1878 : {
1879 14 : OUString sName;
1880 14 : bool bIsAutoStyle(true);
1881 14 : if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_CELL, sStyleName, xPropStates))
1882 : {
1883 14 : OUString* pTemp(new OUString(sName));
1884 14 : if (!pCellStyles->AddStyleName(pTemp, nIndex))
1885 0 : delete pTemp;
1886 : }
1887 : else
1888 0 : nIndex = pCellStyles->GetIndexOfStyleName(sName, SC_SCELLPREFIX, bIsAutoStyle);
1889 :
1890 28 : uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
1891 14 : table::CellRangeAddress* pAddresses(aAddresses.getArray());
1892 14 : bool bGetMerge(true);
1893 28 : for (sal_Int32 i = 0; i < aAddresses.getLength(); ++i, ++pAddresses)
1894 : {
1895 14 : pSharedData->SetLastColumn(nTable, pAddresses->EndColumn);
1896 14 : pSharedData->SetLastRow(nTable, pAddresses->EndRow);
1897 14 : pCellStyles->AddRangeStyleName(*pAddresses, nIndex, bIsAutoStyle, nValidationIndex, nNumberFormat);
1898 14 : if (bGetMerge)
1899 14 : bGetMerge = GetMerged(pAddresses, xTable);
1900 14 : }
1901 : }
1902 : }
1903 : else
1904 : {
1905 9 : OUString* pTemp(new OUString(EncodeStyleName(sStyleName)));
1906 9 : sal_Int32 nIndex(0);
1907 9 : if (!pCellStyles->AddStyleName(pTemp, nIndex, false))
1908 : {
1909 1 : delete pTemp;
1910 1 : pTemp = NULL;
1911 : }
1912 9 : if ( !pOldName )
1913 : {
1914 9 : uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
1915 9 : table::CellRangeAddress* pAddresses(aAddresses.getArray());
1916 9 : bool bGetMerge(true);
1917 60 : for (sal_Int32 i = 0; i < aAddresses.getLength(); ++i, ++pAddresses)
1918 : {
1919 51 : if (bGetMerge)
1920 9 : bGetMerge = GetMerged(pAddresses, xTable);
1921 51 : pCellStyles->AddRangeStyleName(*pAddresses, nIndex, false, nValidationIndex, nNumberFormat);
1922 51 : if (!sStyleName.equalsAsciiL("Default", 7) || nValidationIndex != -1)
1923 : {
1924 0 : pSharedData->SetLastColumn(nTable, pAddresses->EndColumn);
1925 0 : pSharedData->SetLastRow(nTable, pAddresses->EndRow);
1926 : }
1927 9 : }
1928 : }
1929 : }
1930 23 : }
1931 23 : }
1932 :
1933 10 : void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>& xColumnProperties,
1934 : const OUString* pOldName, sal_Int32& rIndex, bool& rIsVisible)
1935 : {
1936 10 : OUString SC_SCOLUMNPREFIX(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX);
1937 :
1938 20 : std::vector<XMLPropertyState> xPropStates(xColumnStylesExportPropertySetMapper->Filter(xColumnProperties));
1939 10 : if(!xPropStates.empty())
1940 : {
1941 10 : std::vector< XMLPropertyState >::iterator aItr(xPropStates.begin());
1942 10 : std::vector< XMLPropertyState >::iterator aEndItr(xPropStates.end());
1943 30 : while (aItr != aEndItr)
1944 : {
1945 20 : if (xColumnStylesPropertySetMapper->GetEntryContextId(aItr->mnIndex) == CTF_SC_ISVISIBLE)
1946 : {
1947 10 : aItr->maValue >>= rIsVisible;
1948 10 : break;
1949 : }
1950 10 : ++aItr;
1951 : }
1952 :
1953 10 : OUString sParent;
1954 10 : if (pOldName)
1955 : {
1956 0 : if (GetAutoStylePool()->AddNamed(*pOldName, XML_STYLE_FAMILY_TABLE_COLUMN, sParent, xPropStates))
1957 : {
1958 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_COLUMN, *pOldName);
1959 : // add to pColumnStyles, so the name is found for normal sheets
1960 0 : OUString* pTemp(new OUString(*pOldName));
1961 0 : rIndex = pColumnStyles->AddStyleName(pTemp);
1962 : }
1963 : }
1964 : else
1965 : {
1966 10 : OUString sName;
1967 10 : if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_COLUMN, sParent, xPropStates))
1968 : {
1969 9 : OUString* pTemp(new OUString(sName));
1970 9 : rIndex = pColumnStyles->AddStyleName(pTemp);
1971 : }
1972 : else
1973 1 : rIndex = pColumnStyles->GetIndexOfStyleName(sName, SC_SCOLUMNPREFIX);
1974 10 : }
1975 10 : }
1976 10 : }
1977 :
1978 13 : void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRowProperties,
1979 : const OUString* pOldName, sal_Int32& rIndex)
1980 : {
1981 13 : OUString SC_SROWPREFIX(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX);
1982 :
1983 26 : std::vector<XMLPropertyState> xPropStates(xRowStylesExportPropertySetMapper->Filter(xRowProperties));
1984 13 : if(!xPropStates.empty())
1985 : {
1986 13 : OUString sParent;
1987 13 : if (pOldName)
1988 : {
1989 0 : if (GetAutoStylePool()->AddNamed(*pOldName, XML_STYLE_FAMILY_TABLE_ROW, sParent, xPropStates))
1990 : {
1991 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_ROW, *pOldName);
1992 : // add to pRowStyles, so the name is found for normal sheets
1993 0 : OUString* pTemp(new OUString(*pOldName));
1994 0 : rIndex = pRowStyles->AddStyleName(pTemp);
1995 : }
1996 : }
1997 : else
1998 : {
1999 13 : OUString sName;
2000 13 : if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_ROW, sParent, xPropStates))
2001 : {
2002 11 : OUString* pTemp(new OUString(sName));
2003 11 : rIndex = pRowStyles->AddStyleName(pTemp);
2004 : }
2005 : else
2006 2 : rIndex = pRowStyles->GetIndexOfStyleName(sName, SC_SROWPREFIX);
2007 13 : }
2008 13 : }
2009 13 : }
2010 :
2011 0 : static uno::Any lcl_GetEnumerated( uno::Reference<container::XEnumerationAccess> xEnumAccess, sal_Int32 nIndex )
2012 : {
2013 0 : uno::Any aRet;
2014 0 : uno::Reference<container::XEnumeration> xEnum( xEnumAccess->createEnumeration() );
2015 : try
2016 : {
2017 0 : sal_Int32 nSkip = nIndex;
2018 0 : while ( nSkip > 0 )
2019 : {
2020 0 : (void) xEnum->nextElement();
2021 0 : --nSkip;
2022 : }
2023 0 : aRet = xEnum->nextElement();
2024 : }
2025 0 : catch (container::NoSuchElementException&)
2026 : {
2027 : // leave aRet empty
2028 : }
2029 0 : return aRet;
2030 : }
2031 :
2032 16 : void ScXMLExport::_ExportAutoStyles()
2033 : {
2034 16 : if (!GetModel().is())
2035 0 : return;
2036 :
2037 16 : Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
2038 16 : if (!xSpreadDoc.is())
2039 0 : return;
2040 :
2041 32 : Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
2042 16 : if (!xIndex.is())
2043 0 : return;
2044 :
2045 16 : if (getExportFlags() & EXPORT_CONTENT)
2046 : {
2047 : // re-create automatic styles with old names from stored data
2048 8 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(xSpreadDoc)->GetSheetSaveData();
2049 8 : if (pSheetData && pDoc)
2050 : {
2051 : // formulas have to be calculated now, to detect changed results
2052 : // (during normal save, they will be calculated anyway)
2053 8 : SCTAB nTabCount = pDoc->GetTableCount();
2054 17 : for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
2055 9 : if (pDoc->IsStreamValid(nTab))
2056 0 : pDoc->InterpretDirtyCells(ScRange(0, 0, nTab, MAXCOL, MAXROW, nTab));
2057 :
2058 : // stored cell styles
2059 8 : const std::vector<ScCellStyleEntry>& rCellEntries = pSheetData->GetCellStyles();
2060 8 : std::vector<ScCellStyleEntry>::const_iterator aCellIter = rCellEntries.begin();
2061 8 : std::vector<ScCellStyleEntry>::const_iterator aCellEnd = rCellEntries.end();
2062 30 : while (aCellIter != aCellEnd)
2063 : {
2064 14 : ScAddress aPos = aCellIter->maCellPos;
2065 14 : sal_Int32 nTable = aPos.Tab();
2066 14 : bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2067 14 : if (bCopySheet)
2068 : {
2069 0 : Reference <sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2070 : Reference <beans::XPropertySet> xProperties(
2071 0 : xTable->getCellByPosition( aPos.Col(), aPos.Row() ), uno::UNO_QUERY );
2072 :
2073 0 : AddStyleFromCells(xProperties, xTable, nTable, &aCellIter->maName);
2074 : }
2075 14 : ++aCellIter;
2076 : }
2077 :
2078 : // stored column styles
2079 8 : const std::vector<ScCellStyleEntry>& rColumnEntries = pSheetData->GetColumnStyles();
2080 8 : std::vector<ScCellStyleEntry>::const_iterator aColumnIter = rColumnEntries.begin();
2081 8 : std::vector<ScCellStyleEntry>::const_iterator aColumnEnd = rColumnEntries.end();
2082 22 : while (aColumnIter != aColumnEnd)
2083 : {
2084 6 : ScAddress aPos = aColumnIter->maCellPos;
2085 6 : sal_Int32 nTable = aPos.Tab();
2086 6 : bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2087 6 : if (bCopySheet)
2088 : {
2089 0 : Reference<table::XColumnRowRange> xColumnRowRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2090 0 : Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns());
2091 0 : Reference<beans::XPropertySet> xColumnProperties(xTableColumns->getByIndex( aPos.Col() ), uno::UNO_QUERY);
2092 :
2093 0 : sal_Int32 nIndex(-1);
2094 0 : bool bIsVisible(true);
2095 0 : AddStyleFromColumn( xColumnProperties, &aColumnIter->maName, nIndex, bIsVisible );
2096 : }
2097 6 : ++aColumnIter;
2098 : }
2099 :
2100 : // stored row styles
2101 8 : const std::vector<ScCellStyleEntry>& rRowEntries = pSheetData->GetRowStyles();
2102 8 : std::vector<ScCellStyleEntry>::const_iterator aRowIter = rRowEntries.begin();
2103 8 : std::vector<ScCellStyleEntry>::const_iterator aRowEnd = rRowEntries.end();
2104 22 : while (aRowIter != aRowEnd)
2105 : {
2106 6 : ScAddress aPos = aRowIter->maCellPos;
2107 6 : sal_Int32 nTable = aPos.Tab();
2108 6 : bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2109 6 : if (bCopySheet)
2110 : {
2111 0 : Reference<table::XColumnRowRange> xColumnRowRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2112 0 : Reference<table::XTableRows> xTableRows(xColumnRowRange->getRows());
2113 0 : Reference<beans::XPropertySet> xRowProperties(xTableRows->getByIndex( aPos.Row() ), uno::UNO_QUERY);
2114 :
2115 0 : sal_Int32 nIndex(-1);
2116 0 : AddStyleFromRow( xRowProperties, &aRowIter->maName, nIndex );
2117 : }
2118 6 : ++aRowIter;
2119 : }
2120 :
2121 : // stored table styles
2122 8 : const std::vector<ScCellStyleEntry>& rTableEntries = pSheetData->GetTableStyles();
2123 8 : std::vector<ScCellStyleEntry>::const_iterator aTableIter = rTableEntries.begin();
2124 8 : std::vector<ScCellStyleEntry>::const_iterator aTableEnd = rTableEntries.end();
2125 21 : while (aTableIter != aTableEnd)
2126 : {
2127 5 : ScAddress aPos = aTableIter->maCellPos;
2128 5 : sal_Int32 nTable = aPos.Tab();
2129 5 : bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2130 5 : if (bCopySheet)
2131 : {
2132 : //! separate method AddStyleFromTable needed?
2133 0 : Reference<beans::XPropertySet> xTableProperties(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2134 0 : if (xTableProperties.is())
2135 : {
2136 0 : std::vector<XMLPropertyState> xPropStates(xTableStylesExportPropertySetMapper->Filter(xTableProperties));
2137 0 : OUString sParent;
2138 0 : OUString sName( aTableIter->maName );
2139 0 : GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TABLE_TABLE, sParent, xPropStates);
2140 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_TABLE, sName);
2141 0 : }
2142 : }
2143 5 : ++aTableIter;
2144 : }
2145 :
2146 : // stored styles for notes
2147 :
2148 8 : UniReference<SvXMLExportPropertyMapper> xShapeMapper = XMLShapeExport::CreateShapePropMapper( *this );
2149 8 : GetShapeExport(); // make sure the graphics styles family is added
2150 :
2151 8 : const std::vector<ScNoteStyleEntry>& rNoteEntries = pSheetData->GetNoteStyles();
2152 8 : std::vector<ScNoteStyleEntry>::const_iterator aNoteIter = rNoteEntries.begin();
2153 8 : std::vector<ScNoteStyleEntry>::const_iterator aNoteEnd = rNoteEntries.end();
2154 16 : while (aNoteIter != aNoteEnd)
2155 : {
2156 0 : ScAddress aPos = aNoteIter->maCellPos;
2157 0 : SCTAB nTable = aPos.Tab();
2158 0 : bool bCopySheet = pDoc->IsStreamValid( nTable );
2159 0 : if (bCopySheet)
2160 : {
2161 : //! separate method AddStyleFromNote needed?
2162 :
2163 0 : ScPostIt* pNote = pDoc->GetNotes( nTable )->findByAddress(aPos);
2164 : OSL_ENSURE( pNote, "note not found" );
2165 0 : if (pNote)
2166 : {
2167 0 : SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2168 : // all uno shapes are created anyway in CollectSharedData
2169 0 : Reference<beans::XPropertySet> xShapeProperties( pDrawObj->getUnoShape(), uno::UNO_QUERY );
2170 0 : if (xShapeProperties.is())
2171 : {
2172 0 : if ( !aNoteIter->maStyleName.isEmpty() )
2173 : {
2174 0 : std::vector<XMLPropertyState> xPropStates(xShapeMapper->Filter(xShapeProperties));
2175 0 : OUString sParent;
2176 0 : OUString sName( aNoteIter->maStyleName );
2177 0 : GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_SD_GRAPHICS_ID, sParent, xPropStates);
2178 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_SD_GRAPHICS_ID, sName);
2179 : }
2180 0 : if ( !aNoteIter->maTextStyle.isEmpty() )
2181 : {
2182 : std::vector<XMLPropertyState> xPropStates(
2183 0 : GetTextParagraphExport()->GetParagraphPropertyMapper()->Filter(xShapeProperties));
2184 0 : OUString sParent;
2185 0 : OUString sName( aNoteIter->maTextStyle );
2186 0 : GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_PARAGRAPH, sParent, xPropStates);
2187 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_PARAGRAPH, sName);
2188 : }
2189 0 : }
2190 : }
2191 : }
2192 0 : ++aNoteIter;
2193 : }
2194 :
2195 : // note paragraph styles
2196 :
2197 16 : UniReference<SvXMLExportPropertyMapper> xParaPropMapper = GetTextParagraphExport()->GetParagraphPropertyMapper();
2198 :
2199 8 : const std::vector<ScTextStyleEntry>& rNoteParaEntries = pSheetData->GetNoteParaStyles();
2200 8 : std::vector<ScTextStyleEntry>::const_iterator aNoteParaIter = rNoteParaEntries.begin();
2201 8 : std::vector<ScTextStyleEntry>::const_iterator aNoteParaEnd = rNoteParaEntries.end();
2202 16 : while (aNoteParaIter != aNoteParaEnd)
2203 : {
2204 0 : ScAddress aPos = aNoteParaIter->maCellPos;
2205 0 : SCTAB nTable = aPos.Tab();
2206 0 : bool bCopySheet = pDoc->IsStreamValid( nTable );
2207 0 : if (bCopySheet)
2208 : {
2209 0 : ScPostIt* pNote = pDoc->GetNotes(nTable)->findByAddress( aPos );
2210 : OSL_ENSURE( pNote, "note not found" );
2211 0 : if (pNote)
2212 : {
2213 0 : SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2214 0 : Reference<container::XEnumerationAccess> xCellText(pDrawObj->getUnoShape(), uno::UNO_QUERY);
2215 : Reference<beans::XPropertySet> xParaProp(
2216 0 : lcl_GetEnumerated( xCellText, aNoteParaIter->maSelection.nStartPara ), uno::UNO_QUERY );
2217 0 : if ( xParaProp.is() )
2218 : {
2219 0 : std::vector<XMLPropertyState> xPropStates(xParaPropMapper->Filter(xParaProp));
2220 0 : OUString sParent;
2221 0 : OUString sName( aNoteParaIter->maName );
2222 0 : GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_PARAGRAPH, sParent, xPropStates);
2223 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_PARAGRAPH, sName);
2224 0 : }
2225 : }
2226 : }
2227 0 : ++aNoteParaIter;
2228 : }
2229 :
2230 : // note text styles
2231 :
2232 16 : UniReference<SvXMLExportPropertyMapper> xTextPropMapper = XMLTextParagraphExport::CreateCharExtPropMapper( *this );
2233 :
2234 8 : const std::vector<ScTextStyleEntry>& rNoteTextEntries = pSheetData->GetNoteTextStyles();
2235 8 : std::vector<ScTextStyleEntry>::const_iterator aNoteTextIter = rNoteTextEntries.begin();
2236 8 : std::vector<ScTextStyleEntry>::const_iterator aNoteTextEnd = rNoteTextEntries.end();
2237 16 : while (aNoteTextIter != aNoteTextEnd)
2238 : {
2239 0 : ScAddress aPos = aNoteTextIter->maCellPos;
2240 0 : SCTAB nTable = aPos.Tab();
2241 0 : bool bCopySheet = pDoc->IsStreamValid( nTable );
2242 0 : if (bCopySheet)
2243 : {
2244 0 : ScPostIt* pNote = pDoc->GetNotes(nTable)->findByAddress( aPos );
2245 : OSL_ENSURE( pNote, "note not found" );
2246 0 : if (pNote)
2247 : {
2248 0 : SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2249 0 : Reference<text::XSimpleText> xCellText(pDrawObj->getUnoShape(), uno::UNO_QUERY);
2250 0 : Reference<beans::XPropertySet> xCursorProp(xCellText->createTextCursor(), uno::UNO_QUERY);
2251 0 : ScDrawTextCursor* pCursor = ScDrawTextCursor::getImplementation( xCursorProp );
2252 0 : if (pCursor)
2253 : {
2254 0 : pCursor->SetSelection( aNoteTextIter->maSelection );
2255 :
2256 0 : std::vector<XMLPropertyState> xPropStates(xTextPropMapper->Filter(xCursorProp));
2257 0 : OUString sParent;
2258 0 : OUString sName( aNoteTextIter->maName );
2259 0 : GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_TEXT, sParent, xPropStates);
2260 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_TEXT, sName);
2261 0 : }
2262 : }
2263 : }
2264 0 : ++aNoteTextIter;
2265 : }
2266 :
2267 : // stored text styles
2268 :
2269 8 : const std::vector<ScTextStyleEntry>& rTextEntries = pSheetData->GetTextStyles();
2270 8 : std::vector<ScTextStyleEntry>::const_iterator aTextIter = rTextEntries.begin();
2271 8 : std::vector<ScTextStyleEntry>::const_iterator aTextEnd = rTextEntries.end();
2272 16 : while (aTextIter != aTextEnd)
2273 : {
2274 0 : ScAddress aPos = aTextIter->maCellPos;
2275 0 : sal_Int32 nTable = aPos.Tab();
2276 0 : bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2277 0 : if (bCopySheet)
2278 : {
2279 : //! separate method AddStyleFromText needed?
2280 : //! cache sheet object
2281 :
2282 0 : Reference<table::XCellRange> xCellRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2283 0 : Reference<text::XSimpleText> xCellText(xCellRange->getCellByPosition(aPos.Col(), aPos.Row()), uno::UNO_QUERY);
2284 0 : Reference<beans::XPropertySet> xCursorProp(xCellText->createTextCursor(), uno::UNO_QUERY);
2285 0 : ScCellTextCursor* pCursor = ScCellTextCursor::getImplementation( xCursorProp );
2286 0 : if (pCursor)
2287 : {
2288 0 : pCursor->SetSelection( aTextIter->maSelection );
2289 :
2290 0 : std::vector<XMLPropertyState> xPropStates(xTextPropMapper->Filter(xCursorProp));
2291 0 : OUString sParent;
2292 0 : OUString sName( aTextIter->maName );
2293 0 : GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_TEXT, sParent, xPropStates);
2294 0 : GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_TEXT, sName);
2295 0 : }
2296 : }
2297 0 : ++aTextIter;
2298 8 : }
2299 : }
2300 :
2301 8 : ExportExternalRefCacheStyles();
2302 :
2303 8 : if (!pSharedData)
2304 : {
2305 0 : sal_Int32 nTableCount(0);
2306 0 : sal_Int32 nShapesCount(0);
2307 0 : CollectSharedData(nTableCount, nShapesCount);
2308 : }
2309 8 : sal_Int32 nTableCount(xIndex->getCount());
2310 8 : pCellStyles->AddNewTable(nTableCount - 1);
2311 8 : CollectShapesAutoStyles(nTableCount);
2312 17 : for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable, IncrementProgressBar(false))
2313 : {
2314 9 : bool bUseStream = pSheetData && pDoc && pDoc->IsStreamValid((SCTAB)nTable) &&
2315 9 : pSheetData->HasStreamPos(nTable) && xSourceStream.is() &&
2316 9 : !pDoc->GetChangeTrack();
2317 :
2318 9 : Reference <sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2319 9 : if (!xTable.is())
2320 0 : continue;
2321 :
2322 : // table styles array must be complete, including copied tables - Add should find the stored style
2323 18 : Reference<beans::XPropertySet> xTableProperties(xTable, uno::UNO_QUERY);
2324 9 : if (xTableProperties.is())
2325 : {
2326 9 : std::vector<XMLPropertyState> xPropStates(xTableStylesExportPropertySetMapper->Filter(xTableProperties));
2327 9 : if(!xPropStates.empty())
2328 : {
2329 9 : OUString sParent;
2330 18 : OUString sName;
2331 9 : GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_TABLE, sParent, xPropStates);
2332 18 : aTableStyles.push_back(sName);
2333 9 : }
2334 : }
2335 :
2336 9 : if (bUseStream)
2337 0 : continue;
2338 :
2339 : // collect other auto-styles only for non-copied sheets
2340 18 : Reference<sheet::XUniqueCellFormatRangesSupplier> xCellFormatRanges ( xTable, uno::UNO_QUERY );
2341 9 : if ( xCellFormatRanges.is() )
2342 : {
2343 9 : Reference<container::XIndexAccess> xFormatRangesIndex(xCellFormatRanges->getUniqueCellFormatRanges());
2344 9 : if (xFormatRangesIndex.is())
2345 : {
2346 9 : sal_Int32 nFormatRangesCount(xFormatRangesIndex->getCount());
2347 9 : GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nFormatRangesCount);
2348 32 : for (sal_Int32 nFormatRange = 0; nFormatRange < nFormatRangesCount; ++nFormatRange)
2349 : {
2350 23 : Reference< sheet::XSheetCellRanges> xCellRanges(xFormatRangesIndex->getByIndex(nFormatRange), uno::UNO_QUERY);
2351 23 : if (xCellRanges.is())
2352 : {
2353 23 : Reference <beans::XPropertySet> xProperties (xCellRanges, uno::UNO_QUERY);
2354 23 : if (xProperties.is())
2355 : {
2356 23 : AddStyleFromCells(xProperties, xTable, nTable, NULL);
2357 23 : IncrementProgressBar(false);
2358 23 : }
2359 : }
2360 23 : }
2361 9 : }
2362 : }
2363 18 : Reference<table::XColumnRowRange> xColumnRowRange (xTable, uno::UNO_QUERY);
2364 9 : if (xColumnRowRange.is())
2365 : {
2366 9 : if (pDoc)
2367 : {
2368 9 : pDoc->SyncColRowFlags();
2369 9 : Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns());
2370 9 : if (xTableColumns.is())
2371 : {
2372 9 : sal_Int32 nColumns(pDoc->GetLastChangedCol(sal::static_int_cast<SCTAB>(nTable)));
2373 9 : pSharedData->SetLastColumn(nTable, nColumns);
2374 9 : table::CellRangeAddress aCellAddress(GetEndAddress(xTable, nTable));
2375 9 : if (aCellAddress.EndColumn > nColumns)
2376 : {
2377 3 : ++nColumns;
2378 3 : pColumnStyles->AddNewTable(nTable, aCellAddress.EndColumn);
2379 : }
2380 : else
2381 6 : pColumnStyles->AddNewTable(nTable, nColumns);
2382 9 : sal_Int32 nColumn = 0;
2383 28 : while (nColumn <= MAXCOL)
2384 : {
2385 10 : sal_Int32 nIndex(-1);
2386 10 : bool bIsVisible(true);
2387 10 : Reference <beans::XPropertySet> xColumnProperties(xTableColumns->getByIndex(nColumn), uno::UNO_QUERY);
2388 10 : if (xColumnProperties.is())
2389 : {
2390 10 : AddStyleFromColumn( xColumnProperties, NULL, nIndex, bIsVisible );
2391 10 : pColumnStyles->AddFieldStyleName(nTable, nColumn, nIndex, bIsVisible);
2392 : }
2393 10 : sal_Int32 nOld(nColumn);
2394 10 : nColumn = pDoc->GetNextDifferentChangedCol(sal::static_int_cast<SCTAB>(nTable), static_cast<SCCOL>(nColumn));
2395 9216 : for (sal_Int32 i = nOld + 1; i < nColumn; ++i)
2396 9206 : pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
2397 10 : }
2398 9 : if (aCellAddress.EndColumn > nColumns)
2399 : {
2400 3 : bool bIsVisible(true);
2401 3 : sal_Int32 nIndex(pColumnStyles->GetStyleNameIndex(nTable, nColumns, bIsVisible));
2402 25 : for (sal_Int32 i = nColumns + 1; i <= aCellAddress.EndColumn; ++i)
2403 22 : pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
2404 : }
2405 : }
2406 18 : Reference<table::XTableRows> xTableRows(xColumnRowRange->getRows());
2407 9 : if (xTableRows.is())
2408 : {
2409 9 : sal_Int32 nRows(pDoc->GetLastChangedRow(sal::static_int_cast<SCTAB>(nTable)));
2410 9 : pSharedData->SetLastRow(nTable, nRows);
2411 :
2412 9 : pRowStyles->AddNewTable(nTable, MAXROW);
2413 9 : sal_Int32 nRow = 0;
2414 31 : while (nRow <= MAXROW)
2415 : {
2416 13 : sal_Int32 nIndex = 0;
2417 13 : Reference <beans::XPropertySet> xRowProperties(xTableRows->getByIndex(nRow), uno::UNO_QUERY);
2418 13 : if(xRowProperties.is())
2419 : {
2420 13 : AddStyleFromRow( xRowProperties, NULL, nIndex );
2421 13 : pRowStyles->AddFieldStyleName(nTable, nRow, nIndex);
2422 : }
2423 13 : sal_Int32 nOld(nRow);
2424 13 : nRow = pDoc->GetNextDifferentChangedRow(sal::static_int_cast<SCTAB>(nTable), static_cast<SCROW>(nRow), false);
2425 13 : if (nRow > nOld + 1)
2426 11 : pRowStyles->AddFieldStyleName(nTable, nOld + 1, nIndex, nRow - 1);
2427 13 : }
2428 9 : }
2429 : }
2430 : }
2431 18 : Reference<sheet::XCellRangesQuery> xCellRangesQuery (xTable, uno::UNO_QUERY);
2432 9 : if (xCellRangesQuery.is())
2433 : {
2434 9 : Reference<sheet::XSheetCellRanges> xSheetCellRanges(xCellRangesQuery->queryContentCells(sheet::CellFlags::FORMATTED));
2435 9 : if (xSheetCellRanges.is())
2436 : {
2437 9 : uno::Sequence< table::CellRangeAddress > aCellRangeAddresses (xSheetCellRanges->getRangeAddresses());
2438 9 : sal_uInt32 nCount(aCellRangeAddresses.getLength());
2439 18 : Reference<container::XEnumerationAccess> xCellsAccess(xSheetCellRanges->getCells());
2440 9 : if (xCellsAccess.is())
2441 : {
2442 9 : GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nCount);
2443 9 : Reference<container::XEnumeration> xCells(xCellsAccess->createEnumeration());
2444 9 : if (xCells.is())
2445 : {
2446 9 : sal_uInt32 nCount2(0);
2447 18 : while (xCells->hasMoreElements())
2448 : {
2449 0 : Reference<text::XText> xText(xCells->nextElement(), uno::UNO_QUERY);
2450 0 : if (xText.is())
2451 0 : GetTextParagraphExport()->collectTextAutoStyles(xText, false, false);
2452 0 : ++nCount2;
2453 0 : IncrementProgressBar(false);
2454 0 : }
2455 9 : if(nCount2 > nCount)
2456 0 : GetProgressBarHelper()->SetReference(GetProgressBarHelper()->GetReference() + nCount2 - nCount);
2457 9 : }
2458 9 : }
2459 9 : }
2460 : }
2461 9 : }
2462 8 : pChangeTrackingExportHelper->CollectAutoStyles();
2463 :
2464 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_COLUMN,
2465 8 : GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2466 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_ROW,
2467 8 : GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2468 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_TABLE,
2469 8 : GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2470 8 : exportAutoDataStyles();
2471 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_CELL,
2472 8 : GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2473 :
2474 8 : GetShapeExport()->exportAutoStyles();
2475 8 : GetFormExport()->exportAutoStyles( );
2476 :
2477 8 : if (pDoc)
2478 : {
2479 8 : ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
2480 : // #i100879# write the table style for cached tables only if there are cached tables
2481 : // (same logic as in ExportExternalRefCacheStyles)
2482 8 : if (pRefMgr->hasExternalData())
2483 : {
2484 : // Special table style for the external ref cache tables.
2485 0 : AddAttribute(XML_NAMESPACE_STYLE, XML_NAME, sExternalRefTabStyleName);
2486 0 : AddAttribute(XML_NAMESPACE_STYLE, XML_FAMILY, XML_TABLE);
2487 0 : SvXMLElementExport aElemStyle(*this, XML_NAMESPACE_STYLE, XML_STYLE, true, true);
2488 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_FALSE);
2489 0 : SvXMLElementExport aElemStyleTabProps(*this, XML_NAMESPACE_STYLE, XML_TABLE_PROPERTIES, true, true);
2490 : }
2491 : }
2492 : }
2493 :
2494 16 : if (getExportFlags() & EXPORT_MASTERSTYLES)
2495 : {
2496 8 : GetPageExport()->collectAutoStyles(true);
2497 8 : GetPageExport()->exportAutoStyles();
2498 : }
2499 :
2500 : // #i30251#; only write Text Styles once
2501 :
2502 16 : if ((getExportFlags() & EXPORT_CONTENT) || (getExportFlags() & EXPORT_MASTERSTYLES))
2503 32 : GetTextParagraphExport()->exportTextAutoStyles();
2504 : }
2505 :
2506 8 : void ScXMLExport::_ExportMasterStyles()
2507 : {
2508 8 : GetPageExport()->exportMasterStyles( true );
2509 8 : }
2510 :
2511 0 : void ScXMLExport::CollectInternalShape( uno::Reference< drawing::XShape > xShape )
2512 : {
2513 : // detective objects and notes
2514 0 : if( SvxShape* pShapeImp = SvxShape::getImplementation( xShape ) )
2515 : {
2516 0 : if( SdrObject* pObject = pShapeImp->GetSdrObject() )
2517 : {
2518 : // collect note caption objects from all layers (internal or hidden)
2519 0 : if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, static_cast< SCTAB >( nCurrentTable ) ) )
2520 : {
2521 0 : if(pDoc->GetNotes(nCurrentTable)->findByAddress(pCaptData->maStart))
2522 : {
2523 0 : pSharedData->AddNoteObj( xShape, pCaptData->maStart );
2524 :
2525 : // #i60851# When the file is saved while editing a new note,
2526 : // the cell is still empty -> last column/row must be updated
2527 : OSL_ENSURE( pCaptData->maStart.Tab() == nCurrentTable, "invalid table in object data" );
2528 0 : pSharedData->SetLastColumn( nCurrentTable, pCaptData->maStart.Col() );
2529 0 : pSharedData->SetLastRow( nCurrentTable, pCaptData->maStart.Row() );
2530 : }
2531 : }
2532 : // other objects from internal layer only (detective)
2533 0 : else if( pObject->GetLayer() == SC_LAYER_INTERN )
2534 : {
2535 0 : ScDetectiveFunc aDetFunc( pDoc, static_cast<SCTAB>(nCurrentTable) );
2536 0 : ScAddress aPosition;
2537 0 : ScRange aSourceRange;
2538 : bool bRedLine;
2539 : ScDetectiveObjType eObjType = aDetFunc.GetDetectiveObjectType(
2540 0 : pObject, nCurrentTable, aPosition, aSourceRange, bRedLine );
2541 0 : pSharedData->GetDetectiveObjContainer()->AddObject( eObjType, static_cast<SCTAB>(nCurrentTable), aPosition, aSourceRange, bRedLine );
2542 : }
2543 : }
2544 : }
2545 0 : }
2546 :
2547 23 : bool ScXMLExport::GetMerged (const table::CellRangeAddress* pCellAddress,
2548 : const uno::Reference <sheet::XSpreadsheet>& xTable)
2549 : {
2550 23 : bool bReady(false);
2551 23 : sal_Int32 nRow(pCellAddress->StartRow);
2552 23 : sal_Int32 nCol(pCellAddress->StartColumn);
2553 23 : sal_Int32 nEndRow(pCellAddress->EndRow);
2554 23 : sal_Int32 nEndCol(pCellAddress->EndColumn);
2555 23 : bool bRowInc(nEndRow > nRow);
2556 69 : while(!bReady && nRow <= nEndRow && nCol <= nEndCol)
2557 : {
2558 23 : uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xTable->getCellRangeByPosition(nCol, nRow, nCol, nRow), uno::UNO_QUERY);
2559 23 : if (xSheetCellRange.is())
2560 : {
2561 23 : uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursorByRange(xSheetCellRange));
2562 23 : if(xCursor.is())
2563 : {
2564 23 : uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
2565 23 : xCursor->collapseToMergedArea();
2566 23 : table::CellRangeAddress aCellAddress2(xCellAddress->getRangeAddress());
2567 46 : if ((aCellAddress2.EndRow > nRow ||
2568 23 : aCellAddress2.EndColumn > nCol) &&
2569 0 : aCellAddress2.StartRow == nRow &&
2570 0 : aCellAddress2.StartColumn == nCol)
2571 : {
2572 0 : pMergedRangesContainer->AddRange(aCellAddress2);
2573 0 : pSharedData->SetLastColumn(aCellAddress2.Sheet, aCellAddress2.EndColumn);
2574 0 : pSharedData->SetLastRow(aCellAddress2.Sheet, aCellAddress2.EndRow);
2575 : }
2576 : else
2577 23 : bReady = true;
2578 23 : }
2579 : }
2580 23 : if (!bReady)
2581 : {
2582 0 : if (bRowInc)
2583 0 : ++nRow;
2584 : else
2585 0 : ++nCol;
2586 : }
2587 23 : }
2588 : OSL_ENSURE(!(!bReady && nEndRow > nRow && nEndCol > nCol), "should not be possible");
2589 23 : return !bReady;
2590 : }
2591 :
2592 0 : bool ScXMLExport::IsMatrix (const ScAddress& aCell,
2593 : table::CellRangeAddress& aCellAddress, bool& bIsFirst) const
2594 : {
2595 0 : bIsFirst = false;
2596 :
2597 0 : ScRange aMatrixRange;
2598 :
2599 0 : if (pDoc && pDoc->GetMatrixFormulaRange(aCell, aMatrixRange))
2600 : {
2601 0 : ScUnoConversion::FillApiRange( aCellAddress, aMatrixRange );
2602 0 : if ((aCellAddress.StartColumn == aCell.Col() && aCellAddress.StartRow == aCell.Row()) &&
2603 0 : (aCellAddress.EndColumn > aCell.Col() || aCellAddress.EndRow > aCell.Row()))
2604 : {
2605 0 : bIsFirst = true;
2606 0 : return true;
2607 : }
2608 0 : else if (aCellAddress.StartColumn != aCell.Col() || aCellAddress.StartRow != aCell.Row() ||
2609 0 : aCellAddress.EndColumn != aCell.Col() || aCellAddress.EndRow != aCell.Row())
2610 0 : return true;
2611 : else
2612 : {
2613 0 : bIsFirst = true;
2614 0 : return true;
2615 : }
2616 : }
2617 :
2618 0 : return false;
2619 : }
2620 :
2621 218 : void ScXMLExport::GetCellText (ScMyCell& rMyCell, const ScAddress& aPos) const
2622 : {
2623 218 : if (!rMyCell.bHasStringValue)
2624 : {
2625 210 : rMyCell.sStringValue = ScCellObj::GetOutputString_Impl(pDoc, aPos);
2626 210 : rMyCell.bHasStringValue = true;
2627 : }
2628 218 : }
2629 :
2630 9 : void ScXMLExport::WriteTable(sal_Int32 nTable, const Reference<sheet::XSpreadsheet>& xTable)
2631 : {
2632 9 : if (!xTable.is())
2633 0 : return;
2634 :
2635 9 : xCurrentTable.set(xTable);
2636 9 : xCurrentTableCellRange.set(xTable, uno::UNO_QUERY);
2637 9 : uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
2638 9 : if (!xName.is())
2639 0 : return;
2640 :
2641 9 : nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
2642 18 : OUString sOUTableName(xName->getName());
2643 9 : AddAttribute(sAttrName, sOUTableName);
2644 9 : AddAttribute(sAttrStyleName, aTableStyles[nTable]);
2645 :
2646 18 : uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
2647 9 : ScTableProtection* pProtect = NULL;
2648 9 : if (xProtectable.is() && xProtectable->isProtected())
2649 : {
2650 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
2651 0 : if (pDoc)
2652 : {
2653 0 : pProtect = pDoc->GetTabProtection(nTable);
2654 0 : if (pProtect)
2655 : {
2656 0 : OUStringBuffer aBuffer;
2657 0 : ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
2658 0 : if (pProtect->hasPasswordHash(PASSHASH_SHA1))
2659 : {
2660 : ::sax::Converter::encodeBase64(aBuffer,
2661 0 : pProtect->getPasswordHash(PASSHASH_SHA1));
2662 0 : eHashUsed = PASSHASH_SHA1;
2663 : }
2664 0 : else if (pProtect->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
2665 : {
2666 : // Double-hash this by SHA1 on top of the legacy xls hash.
2667 0 : uno::Sequence<sal_Int8> aHash = pProtect->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
2668 0 : ::sax::Converter::encodeBase64(aBuffer, aHash);
2669 0 : eHashUsed = PASSHASH_XL;
2670 : }
2671 0 : if (!aBuffer.isEmpty())
2672 : {
2673 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
2674 0 : if ( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
2675 : {
2676 0 : if (eHashUsed == PASSHASH_XL)
2677 : {
2678 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
2679 0 : ScPassHashHelper::getHashURI(PASSHASH_XL));
2680 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
2681 0 : ScPassHashHelper::getHashURI(PASSHASH_SHA1));
2682 : }
2683 0 : else if (eHashUsed == PASSHASH_SHA1)
2684 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
2685 0 : ScPassHashHelper::getHashURI(PASSHASH_SHA1));
2686 : }
2687 0 : }
2688 : }
2689 : }
2690 : }
2691 18 : OUString sPrintRanges;
2692 9 : table::CellRangeAddress aColumnHeaderRange;
2693 : bool bHasColumnHeader;
2694 9 : GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
2695 9 : if( !sPrintRanges.isEmpty() )
2696 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT_RANGES, sPrintRanges );
2697 9 : else if (!pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
2698 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT, XML_FALSE);
2699 18 : SvXMLElementExport aElemT(*this, sElemTab, true, true);
2700 :
2701 9 : if (pProtect && pProtect->isProtected())
2702 : {
2703 0 : if (pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS))
2704 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_PROTECTED_CELLS, XML_TRUE);
2705 0 : if (pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS))
2706 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_UNPROTECTED_CELLS, XML_TRUE);
2707 :
2708 0 : OUString aElemName = GetNamespaceMap().GetQNameByKey(
2709 0 : XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_PROTECTION));
2710 :
2711 0 : SvXMLElementExport aElemProtected(*this, aElemName, true, true);
2712 : }
2713 :
2714 9 : CheckAttrList();
2715 :
2716 9 : if ( pDoc && pDoc->GetSheetEvents( static_cast<SCTAB>(nTable) ) &&
2717 0 : getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
2718 : {
2719 : // store sheet events
2720 0 : uno::Reference<document::XEventsSupplier> xSupplier(xTable, uno::UNO_QUERY);
2721 0 : uno::Reference<container::XNameAccess> xEvents(xSupplier->getEvents(), uno::UNO_QUERY);
2722 0 : GetEventExport().ExportExt( xEvents );
2723 : }
2724 :
2725 9 : WriteTableSource();
2726 9 : WriteScenario();
2727 18 : uno::Reference<drawing::XDrawPage> xDrawPage;
2728 9 : if (pSharedData->HasForm(nTable, xDrawPage) && xDrawPage.is())
2729 : {
2730 0 : ::xmloff::OOfficeFormsExport aForms(*this);
2731 0 : GetFormExport()->exportForms( xDrawPage );
2732 0 : bool bRet(GetFormExport()->seekPage( xDrawPage ));
2733 : OSL_ENSURE( bRet, "OFormLayerXMLExport::seekPage failed!" );
2734 0 : (void)bRet; // avoid warning in product version
2735 : }
2736 9 : if (pSharedData->HasDrawPage())
2737 : {
2738 9 : GetShapeExport()->seekShapes(uno::Reference<drawing::XShapes>(pSharedData->GetDrawPage(nTable), uno::UNO_QUERY));
2739 9 : WriteTableShapes();
2740 : }
2741 9 : table::CellRangeAddress aRange(GetEndAddress(xTable, nTable));
2742 9 : pSharedData->SetLastColumn(nTable, aRange.EndColumn);
2743 9 : pSharedData->SetLastRow(nTable, aRange.EndRow);
2744 9 : pCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
2745 9 : pGroupColumns->NewTable();
2746 9 : pGroupRows->NewTable();
2747 9 : FillColumnRowGroups();
2748 9 : if (bHasColumnHeader)
2749 0 : pSharedData->SetLastColumn(nTable, aColumnHeaderRange.EndColumn);
2750 9 : bRowHeaderOpen = sal_False;
2751 9 : if (bHasRowHeader)
2752 0 : pSharedData->SetLastRow(nTable, aRowHeaderRange.EndRow);
2753 : pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
2754 9 : pSharedData->GetLastColumn(nTable), pCellStyles, pDoc);
2755 9 : pRowFormatRanges->SetRowDefaults(pDefaults->GetRowDefaults());
2756 9 : pRowFormatRanges->SetColDefaults(pDefaults->GetColDefaults());
2757 9 : pCellStyles->SetRowDefaults(pDefaults->GetRowDefaults());
2758 9 : pCellStyles->SetColDefaults(pDefaults->GetColDefaults());
2759 9 : ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
2760 9 : bool bIsFirst(true);
2761 9 : sal_Int32 nEqualCells(0);
2762 18 : ScMyCell aCell;
2763 18 : ScMyCell aPrevCell;
2764 230 : while(pCellsItr->GetNext(aCell, pCellStyles))
2765 : {
2766 212 : if (bIsFirst)
2767 : {
2768 7 : ExportFormatRanges(0, 0, aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
2769 7 : aPrevCell = aCell;
2770 7 : bIsFirst = sal_False;
2771 : }
2772 : else
2773 : {
2774 379 : if ((aPrevCell.aCellAddress.Row == aCell.aCellAddress.Row) &&
2775 174 : (aPrevCell.aCellAddress.Column + nEqualCells + 1 == aCell.aCellAddress.Column))
2776 : {
2777 0 : if(IsCellEqual(aPrevCell, aCell))
2778 0 : ++nEqualCells;
2779 : else
2780 : {
2781 0 : WriteCell(aPrevCell, nEqualCells);
2782 0 : nEqualCells = 0;
2783 0 : aPrevCell = aCell;
2784 : }
2785 : }
2786 : else
2787 : {
2788 205 : WriteCell(aPrevCell, nEqualCells);
2789 205 : ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
2790 410 : aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
2791 205 : nEqualCells = 0;
2792 205 : aPrevCell = aCell;
2793 : }
2794 : }
2795 : }
2796 9 : if (!bIsFirst)
2797 : {
2798 7 : WriteCell(aPrevCell, nEqualCells);
2799 7 : ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
2800 14 : pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
2801 : }
2802 : else
2803 2 : ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
2804 :
2805 9 : CloseRow(pSharedData->GetLastRow(nTable));
2806 9 : nEqualCells = 0;
2807 :
2808 9 : if (pDoc)
2809 : {
2810 : // Export sheet-local named ranges.
2811 9 : ScRangeName* pRangeName = pDoc->GetRangeName(nTable);
2812 9 : if (pRangeName && !pRangeName->empty())
2813 : {
2814 0 : WriteNamedRange(pRangeName);
2815 : }
2816 :
2817 9 : if(getDefaultVersion() > SvtSaveOptions::ODFVER_012)
2818 : {
2819 : //export new conditional format information
2820 9 : ExportConditionalFormat(nTable);
2821 : }
2822 :
2823 9 : }
2824 : }
2825 :
2826 212 : void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
2827 : {
2828 : // nEqualCellCount is the number of additional cells
2829 212 : SetRepeatAttribute(nEqualCellCount, (aCell.nType != table::CellContentType_EMPTY));
2830 :
2831 212 : ScAddress aCellPos;
2832 212 : ScUnoConversion::FillScAddress( aCellPos, aCell.aCellAddress );
2833 212 : if (aCell.nStyleIndex != -1)
2834 168 : AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(aCell.nStyleIndex, aCell.bIsAutoStyle));
2835 212 : if (aCell.nValidationIndex > -1)
2836 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(aCell.nValidationIndex));
2837 212 : bool bIsMatrix(aCell.bIsMatrixBase || aCell.bIsMatrixCovered);
2838 212 : bool bIsFirstMatrixCell(aCell.bIsMatrixBase);
2839 212 : if (bIsFirstMatrixCell)
2840 : {
2841 0 : sal_Int32 nColumns(aCell.aMatrixRange.EndColumn - aCell.aMatrixRange.StartColumn + 1);
2842 0 : sal_Int32 nRows(aCell.aMatrixRange.EndRow - aCell.aMatrixRange.StartRow + 1);
2843 0 : OUStringBuffer sColumns;
2844 0 : OUStringBuffer sRows;
2845 0 : ::sax::Converter::convertNumber(sColumns, nColumns);
2846 0 : ::sax::Converter::convertNumber(sRows, nRows);
2847 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_MATRIX_COLUMNS_SPANNED, sColumns.makeStringAndClear());
2848 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_MATRIX_ROWS_SPANNED, sRows.makeStringAndClear());
2849 : }
2850 212 : bool bIsEmpty(false);
2851 212 : switch (aCell.nType)
2852 : {
2853 : case table::CellContentType_EMPTY :
2854 : {
2855 2 : bIsEmpty = true;
2856 : }
2857 2 : break;
2858 : case table::CellContentType_VALUE :
2859 : {
2860 202 : if (!aCell.bHasDoubleValue)
2861 : {
2862 202 : aCell.fValue = pDoc->GetValue( aCellPos );
2863 202 : aCell.bHasDoubleValue = true;
2864 : }
2865 : GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2866 202 : aCell.nNumberFormat, aCell.fValue);
2867 202 : if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
2868 : GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2869 202 : aCell.nNumberFormat, aCell.fValue, false, XML_NAMESPACE_CALC_EXT, false);
2870 : }
2871 202 : break;
2872 : case table::CellContentType_TEXT :
2873 : {
2874 8 : GetCellText(aCell, aCellPos);
2875 8 : OUString sFormula(lcl_GetRawString(pDoc, aCellPos));
2876 : GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2877 8 : sFormula, aCell.sStringValue, true, true);
2878 8 : if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
2879 : GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2880 8 : sFormula, aCell.sStringValue, false, true, XML_NAMESPACE_CALC_EXT);
2881 : }
2882 8 : break;
2883 : case table::CellContentType_FORMULA :
2884 : {
2885 0 : ScRefCellValue aCellVal;
2886 0 : aCellVal.assign(*pDoc, aCellPos);
2887 0 : if (aCellVal.meType == CELLTYPE_FORMULA)
2888 : {
2889 0 : OUStringBuffer sFormula;
2890 0 : ScFormulaCell* pFormulaCell = aCellVal.mpFormula;
2891 0 : if (!bIsMatrix || (bIsMatrix && bIsFirstMatrixCell))
2892 : {
2893 0 : const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
2894 0 : sal_uInt16 nNamespacePrefix = (eGrammar == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
2895 0 : pFormulaCell->GetFormula(sFormula, eGrammar);
2896 0 : OUString sOUFormula(sFormula.makeStringAndClear());
2897 0 : if (!bIsMatrix)
2898 : {
2899 0 : AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sOUFormula, false ));
2900 : }
2901 : else
2902 : {
2903 0 : AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sOUFormula.copy(1, sOUFormula.getLength() - 2), false ));
2904 0 : }
2905 : }
2906 0 : if (pFormulaCell->GetErrCode())
2907 : {
2908 0 : GetCellText(aCell, aCellPos);
2909 0 : AddAttribute(sAttrValueType, XML_STRING);
2910 0 : AddAttribute(sAttrStringValue, aCell.sStringValue);
2911 0 : if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
2912 : {
2913 : //export calcext:value-type="error"
2914 0 : AddAttribute(XML_NAMESPACE_CALC_EXT,XML_VALUE_TYPE, OUString("error"));
2915 : }
2916 : }
2917 0 : else if (pFormulaCell->IsValue())
2918 : {
2919 : bool bIsStandard;
2920 0 : OUString sCurrency;
2921 0 : GetNumberFormatAttributesExportHelper()->GetCellType(aCell.nNumberFormat, sCurrency, bIsStandard);
2922 0 : if (pDoc)
2923 : {
2924 : GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2925 0 : aCell.nNumberFormat, pDoc->GetValue( aCellPos ));
2926 0 : if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
2927 : {
2928 : GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2929 0 : aCell.nNumberFormat, pDoc->GetValue( aCellPos ), false, XML_NAMESPACE_CALC_EXT, false );
2930 : }
2931 0 : }
2932 : }
2933 : else
2934 : {
2935 0 : GetCellText(aCell, aCellPos);
2936 0 : if (!aCell.sStringValue.isEmpty())
2937 : {
2938 0 : AddAttribute(sAttrValueType, XML_STRING);
2939 0 : AddAttribute(sAttrStringValue, aCell.sStringValue);
2940 0 : if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
2941 : {
2942 0 : AddAttribute(XML_NAMESPACE_CALC_EXT,XML_VALUE_TYPE, XML_STRING);
2943 : }
2944 : }
2945 0 : }
2946 0 : }
2947 : }
2948 0 : break;
2949 : default:
2950 0 : break;
2951 : }
2952 212 : OUString* pCellString(&sElemCell);
2953 212 : if (aCell.bIsCovered)
2954 : {
2955 0 : pCellString = &sElemCoveredCell;
2956 : }
2957 : else
2958 : {
2959 212 : if (aCell.bIsMergedBase)
2960 : {
2961 0 : sal_Int32 nColumns(aCell.aMergeRange.EndColumn - aCell.aMergeRange.StartColumn + 1);
2962 0 : sal_Int32 nRows(aCell.aMergeRange.EndRow - aCell.aMergeRange.StartRow + 1);
2963 0 : OUStringBuffer sColumns;
2964 0 : OUStringBuffer sRows;
2965 0 : ::sax::Converter::convertNumber(sColumns, nColumns);
2966 0 : ::sax::Converter::convertNumber(sRows, nRows);
2967 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED, sColumns.makeStringAndClear());
2968 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED, sRows.makeStringAndClear());
2969 : }
2970 : }
2971 212 : SvXMLElementExport aElemC(*this, *pCellString, true, true);
2972 212 : CheckAttrList();
2973 212 : WriteAreaLink(aCell);
2974 212 : WriteAnnotation(aCell);
2975 212 : WriteDetective(aCell);
2976 :
2977 212 : bool bEditCell = false;
2978 :
2979 212 : if (!bIsEmpty)
2980 : {
2981 420 : if ((aCell.nType == table::CellContentType_TEXT && IsEditCell(aCell)) ||
2982 210 : (aCell.nType == table::CellContentType_FORMULA && IsMultiLineFormulaCell(aCell)))
2983 : {
2984 0 : bEditCell = true;
2985 0 : uno::Reference<text::XText> xText(xCurrentTableCellRange->getCellByPosition(aCell.aCellAddress.Column, aCell.aCellAddress.Row), uno::UNO_QUERY);
2986 0 : if ( xText.is())
2987 0 : GetTextParagraphExport()->exportText(xText, false, false);
2988 : }
2989 : else
2990 : {
2991 210 : SvXMLElementExport aElemP(*this, sElemP, true, false);
2992 210 : bool bPrevCharWasSpace(true);
2993 210 : GetCellText(aCell, aCellPos);
2994 210 : GetTextParagraphExport()->exportText(aCell.sStringValue, bPrevCharWasSpace);
2995 : }
2996 : }
2997 212 : WriteShapes(aCell);
2998 212 : if (!bIsEmpty)
2999 210 : IncrementProgressBar(bEditCell);
3000 212 : }
3001 :
3002 2 : void ScXMLExport::ExportShape(const uno::Reference < drawing::XShape >& xShape, awt::Point* pPoint)
3003 : {
3004 2 : uno::Reference < beans::XPropertySet > xShapeProps ( xShape, uno::UNO_QUERY );
3005 2 : bool bIsChart( false );
3006 4 : OUString sPropCLSID ("CLSID");
3007 4 : OUString sPropModel ("Model");
3008 4 : OUString sPersistName ("PersistName");
3009 2 : if (xShapeProps.is())
3010 : {
3011 2 : sal_Int32 nZOrder = 0;
3012 2 : if (xShapeProps->getPropertyValue("ZOrder") >>= nZOrder)
3013 : {
3014 2 : OUStringBuffer sBuffer;
3015 2 : ::sax::Converter::convertNumber(sBuffer, nZOrder);
3016 2 : AddAttribute(XML_NAMESPACE_DRAW, XML_ZINDEX, sBuffer.makeStringAndClear());
3017 : }
3018 2 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xShapeProps->getPropertySetInfo();
3019 2 : if( xPropSetInfo->hasPropertyByName( sPropCLSID ) )
3020 : {
3021 0 : OUString sCLSID;
3022 0 : if (xShapeProps->getPropertyValue( sPropCLSID ) >>= sCLSID)
3023 : {
3024 0 : if ( sCLSID.equalsIgnoreAsciiCase(GetChartExport()->getChartCLSID()) )
3025 : {
3026 : // we have a chart
3027 0 : OUString sRanges;
3028 0 : if ( pDoc )
3029 : {
3030 0 : OUString aChartName;
3031 0 : xShapeProps->getPropertyValue( sPersistName ) >>= aChartName;
3032 0 : ScChartListenerCollection* pCollection = pDoc->GetChartListenerCollection();
3033 0 : if (pCollection)
3034 : {
3035 0 : ScChartListener* pListener = pCollection->findByName(aChartName);
3036 0 : if (pListener)
3037 : {
3038 0 : const ScRangeListRef& rRangeList = pListener->GetRangeList();
3039 0 : if ( rRangeList.Is() )
3040 : {
3041 0 : ScRangeStringConverter::GetStringFromRangeList( sRanges, rRangeList, pDoc, FormulaGrammar::CONV_OOO );
3042 0 : if ( !sRanges.isEmpty() )
3043 : {
3044 0 : bIsChart = true;
3045 0 : SvXMLAttributeList* pAttrList = new SvXMLAttributeList();
3046 0 : if ( pAttrList )
3047 : {
3048 : pAttrList->AddAttribute(
3049 0 : GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken( XML_NOTIFY_ON_UPDATE_OF_RANGES ) ), sRanges );
3050 : }
3051 0 : GetShapeExport()->exportShape( xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList );
3052 : }
3053 0 : }
3054 : }
3055 0 : }
3056 : }
3057 :
3058 0 : if ( sRanges.isEmpty() )
3059 : {
3060 0 : uno::Reference< frame::XModel > xChartModel;
3061 0 : if( ( xShapeProps->getPropertyValue( sPropModel ) >>= xChartModel ) &&
3062 0 : xChartModel.is())
3063 : {
3064 0 : uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
3065 0 : uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartModel, uno::UNO_QUERY );
3066 0 : if( xChartDoc.is() && xReceiver.is() &&
3067 0 : ! xChartDoc->hasInternalDataProvider())
3068 : {
3069 : // we have a chart that gets its data from Calc
3070 0 : bIsChart = true;
3071 : uno::Sequence< OUString > aRepresentations(
3072 0 : xReceiver->getUsedRangeRepresentations());
3073 0 : SvXMLAttributeList* pAttrList = 0;
3074 0 : if(aRepresentations.getLength())
3075 : {
3076 : // add the ranges used by the chart to the shape
3077 : // element to be able to start listening after
3078 : // load (when the chart is not yet loaded)
3079 0 : uno::Reference< chart2::data::XRangeXMLConversion > xRangeConverter( xChartDoc->getDataProvider(), uno::UNO_QUERY );
3080 0 : sRanges = lcl_RangeSequenceToString( aRepresentations, xRangeConverter );
3081 0 : pAttrList = new SvXMLAttributeList();
3082 : pAttrList->AddAttribute(
3083 0 : GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken(XML_NOTIFY_ON_UPDATE_OF_RANGES) ), sRanges );
3084 : }
3085 0 : GetShapeExport()->exportShape(xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList);
3086 0 : }
3087 0 : }
3088 0 : }
3089 : }
3090 0 : }
3091 2 : }
3092 : }
3093 2 : if (!bIsChart)
3094 : {
3095 : // #i66550 HLINK_FOR_SHAPES
3096 2 : OUString sHlink;
3097 : try
3098 : {
3099 2 : uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
3100 2 : if ( xProps.is() )
3101 2 : xProps->getPropertyValue( OUString( SC_UNONAME_HYPERLINK ) ) >>= sHlink;
3102 : }
3103 0 : catch ( const beans::UnknownPropertyException& )
3104 : {
3105 : // no hyperlink property
3106 : }
3107 :
3108 4 : std::auto_ptr< SvXMLElementExport > pDrawA;
3109 : // enlose shapes with <draw:a> element only if sHlink contains something
3110 2 : if ( !sHlink.isEmpty() )
3111 : {
3112 : // need to get delete the attributes that are pre-loaded
3113 : // for the shape export ( otherwise they will become
3114 : // attributes of the draw:a element ) This *shouldn't*
3115 : // affect performance adversely as there are only a
3116 : // couple of attributes involved
3117 0 : uno::Reference< xml::sax::XAttributeList > xSaveAttribs( new SvXMLAttributeList( GetAttrList() ) );
3118 0 : ClearAttrList();
3119 : // Add Hlink
3120 0 : AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3121 0 : AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sHlink);
3122 0 : pDrawA.reset( new SvXMLElementExport( *this, XML_NAMESPACE_DRAW, XML_A, false, false ) );
3123 : // Attribute list has been cleared by previous operation
3124 : // re-add pre-loaded attributes
3125 0 : AddAttributeList( xSaveAttribs );
3126 : }
3127 4 : GetShapeExport()->exportShape(xShape, SEF_DEFAULT, pPoint);
3128 : }
3129 4 : IncrementProgressBar(false);
3130 2 : }
3131 :
3132 212 : void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
3133 : {
3134 212 : if( rMyCell.bHasShape && !rMyCell.aShapeList.empty() && pDoc )
3135 : {
3136 2 : awt::Point aPoint;
3137 : Rectangle aRect = pDoc->GetMMRect(static_cast<SCCOL>(rMyCell.aCellAddress.Column), static_cast<SCROW>(rMyCell.aCellAddress.Row),
3138 2 : static_cast<SCCOL>(rMyCell.aCellAddress.Column), static_cast<SCROW>(rMyCell.aCellAddress.Row), static_cast<SCTAB>(rMyCell.aCellAddress.Sheet));
3139 2 : bool bNegativePage(pDoc->IsNegativePage(rMyCell.aCellAddress.Sheet));
3140 2 : if (bNegativePage)
3141 0 : aPoint.X = aRect.Right();
3142 : else
3143 2 : aPoint.X = aRect.Left();
3144 2 : aPoint.Y = aRect.Top();
3145 2 : ScMyShapeList::const_iterator aItr = rMyCell.aShapeList.begin();
3146 2 : ScMyShapeList::const_iterator aEndItr(rMyCell.aShapeList.end());
3147 6 : while (aItr != aEndItr)
3148 : {
3149 2 : if (aItr->xShape.is())
3150 : {
3151 2 : if (bNegativePage)
3152 0 : aPoint.X = 2 * aItr->xShape->getPosition().X + aItr->xShape->getSize().Width - aPoint.X;
3153 2 : if ( !aItr->xShape->getShapeType().equals(sCaptionShape) )
3154 : {
3155 2 : OUString sEndAddress;
3156 2 : ScRangeStringConverter::GetStringFromAddress(sEndAddress, aItr->aEndAddress, pDoc, FormulaGrammar::CONV_OOO);
3157 2 : AddAttribute(XML_NAMESPACE_TABLE, XML_END_CELL_ADDRESS, sEndAddress);
3158 4 : OUStringBuffer sBuffer;
3159 2 : GetMM100UnitConverter().convertMeasureToXML(
3160 4 : sBuffer, aItr->nEndX);
3161 2 : AddAttribute(XML_NAMESPACE_TABLE, XML_END_X, sBuffer.makeStringAndClear());
3162 2 : GetMM100UnitConverter().convertMeasureToXML(
3163 4 : sBuffer, aItr->nEndY);
3164 4 : AddAttribute(XML_NAMESPACE_TABLE, XML_END_Y, sBuffer.makeStringAndClear());
3165 : }
3166 2 : ExportShape(aItr->xShape, &aPoint);
3167 : }
3168 2 : ++aItr;
3169 : }
3170 : }
3171 212 : }
3172 :
3173 9 : void ScXMLExport::WriteTableShapes()
3174 : {
3175 9 : ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
3176 9 : if (pTableShapes && !(*pTableShapes)[nCurrentTable].empty())
3177 : {
3178 : OSL_ENSURE(pTableShapes->size() > static_cast<size_t>(nCurrentTable), "wrong Table");
3179 0 : SvXMLElementExport aShapesElem(*this, XML_NAMESPACE_TABLE, XML_SHAPES, true, false);
3180 0 : ScMyTableXShapes::iterator aItr((*pTableShapes)[nCurrentTable].begin());
3181 0 : ScMyTableXShapes::iterator aEndItr((*pTableShapes)[nCurrentTable].end());
3182 0 : while (aItr != aEndItr)
3183 : {
3184 0 : if (aItr->is())
3185 : {
3186 0 : if (pDoc->IsNegativePage(static_cast<SCTAB>(nCurrentTable)))
3187 : {
3188 0 : awt::Point aPoint((*aItr)->getPosition());
3189 0 : awt::Size aSize((*aItr)->getSize());
3190 0 : aPoint.X += aPoint.X + aSize.Width;
3191 0 : aPoint.Y = 0;
3192 0 : ExportShape(*aItr, &aPoint);
3193 : }
3194 : else
3195 0 : ExportShape(*aItr, NULL);
3196 : }
3197 0 : aItr = (*pTableShapes)[nCurrentTable].erase(aItr);
3198 0 : }
3199 : }
3200 9 : }
3201 :
3202 212 : void ScXMLExport::WriteAreaLink( const ScMyCell& rMyCell )
3203 : {
3204 212 : if( rMyCell.bHasAreaLink )
3205 : {
3206 0 : const ScMyAreaLink& rAreaLink = rMyCell.aAreaLink;
3207 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, rAreaLink.sSourceStr );
3208 0 : AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3209 0 : AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetRelativeReference(rAreaLink.sURL) );
3210 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_FILTER_NAME, rAreaLink.sFilter );
3211 0 : if( !rAreaLink.sFilterOptions.isEmpty() )
3212 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_FILTER_OPTIONS, rAreaLink.sFilterOptions );
3213 0 : OUStringBuffer sValue;
3214 0 : ::sax::Converter::convertNumber( sValue, rAreaLink.GetColCount() );
3215 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_LAST_COLUMN_SPANNED, sValue.makeStringAndClear() );
3216 0 : ::sax::Converter::convertNumber( sValue, rAreaLink.GetRowCount() );
3217 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_LAST_ROW_SPANNED, sValue.makeStringAndClear() );
3218 0 : if( rAreaLink.nRefresh )
3219 : {
3220 : ::sax::Converter::convertDuration( sValue,
3221 0 : (double)rAreaLink.nRefresh / 86400 );
3222 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_REFRESH_DELAY, sValue.makeStringAndClear() );
3223 : }
3224 0 : SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_CELL_RANGE_SOURCE, true, true );
3225 : }
3226 212 : }
3227 :
3228 0 : void ScXMLExport::exportAnnotationMeta( const uno::Reference < drawing::XShape >& xShape)
3229 : {
3230 0 : if (pCurrentCell && pCurrentCell->xNoteShape.is() && pCurrentCell->xNoteShape.get() == xShape.get() && pCurrentCell->xAnnotation.is())
3231 : {
3232 0 : OUString sAuthor(pCurrentCell->xAnnotation->getAuthor());
3233 0 : if (!sAuthor.isEmpty())
3234 : {
3235 : SvXMLElementExport aCreatorElem( *this, XML_NAMESPACE_DC,
3236 : XML_CREATOR, true,
3237 0 : false );
3238 0 : Characters(sAuthor);
3239 : }
3240 :
3241 0 : String aDate(pCurrentCell->xAnnotation->getDate());
3242 0 : if (pDoc)
3243 : {
3244 0 : SvNumberFormatter* pNumForm = pDoc->GetFormatTable();
3245 : double fDate;
3246 0 : sal_uInt32 nfIndex = pNumForm->GetFormatIndex(NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
3247 0 : if (pNumForm->IsNumberFormat(aDate, nfIndex, fDate))
3248 : {
3249 0 : OUStringBuffer sBuf;
3250 0 : GetMM100UnitConverter().convertDateTime(sBuf, fDate,true);
3251 : SvXMLElementExport aDateElem( *this, XML_NAMESPACE_DC,
3252 : XML_DATE, true,
3253 0 : false );
3254 0 : Characters(sBuf.makeStringAndClear());
3255 : }
3256 : else
3257 : {
3258 : SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3259 : XML_DATE_STRING, true,
3260 0 : false );
3261 0 : Characters(OUString(aDate));
3262 : }
3263 : }
3264 : else
3265 : {
3266 : SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3267 : XML_DATE_STRING, true,
3268 0 : false );
3269 0 : Characters(OUString(aDate));
3270 0 : }
3271 : }
3272 0 : }
3273 :
3274 212 : void ScXMLExport::WriteAnnotation(ScMyCell& rMyCell)
3275 : {
3276 212 : if( rMyCell.bHasAnnotation && rMyCell.xAnnotation.is())
3277 : {
3278 :
3279 0 : if (rMyCell.xAnnotation->getIsVisible())
3280 0 : AddAttribute(XML_NAMESPACE_OFFICE, XML_DISPLAY, XML_TRUE);
3281 :
3282 0 : pCurrentCell = &rMyCell;
3283 :
3284 0 : if(rMyCell.xNoteShape.is())
3285 0 : GetShapeExport()->exportShape(rMyCell.xNoteShape, SEF_DEFAULT|SEF_EXPORT_ANNOTATION, NULL);
3286 :
3287 0 : pCurrentCell = NULL;
3288 :
3289 0 : rMyCell.xNoteShape.clear();
3290 : }
3291 212 : }
3292 :
3293 212 : void ScXMLExport::WriteDetective( const ScMyCell& rMyCell )
3294 : {
3295 212 : if( rMyCell.bHasDetectiveObj || rMyCell.bHasDetectiveOp )
3296 : {
3297 0 : const ScMyDetectiveObjVec& rObjVec = rMyCell.aDetectiveObjVec;
3298 0 : const ScMyDetectiveOpVec& rOpVec = rMyCell.aDetectiveOpVec;
3299 0 : sal_Int32 nObjCount(rObjVec.size());
3300 0 : sal_Int32 nOpCount(rOpVec.size());
3301 0 : if( nObjCount || nOpCount )
3302 : {
3303 0 : SvXMLElementExport aDetElem( *this, XML_NAMESPACE_TABLE, XML_DETECTIVE, true, true );
3304 0 : OUString sString;
3305 0 : ScMyDetectiveObjVec::const_iterator aObjItr(rObjVec.begin());
3306 0 : ScMyDetectiveObjVec::const_iterator aEndObjItr(rObjVec.end());
3307 0 : while(aObjItr != aEndObjItr)
3308 : {
3309 0 : if (aObjItr->eObjType != SC_DETOBJ_CIRCLE)
3310 : {
3311 0 : if( (aObjItr->eObjType == SC_DETOBJ_ARROW) || (aObjItr->eObjType == SC_DETOBJ_TOOTHERTAB))
3312 : {
3313 0 : ScRangeStringConverter::GetStringFromRange( sString, aObjItr->aSourceRange, pDoc, FormulaGrammar::CONV_OOO );
3314 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sString );
3315 : }
3316 0 : ScXMLConverter::GetStringFromDetObjType( sString, aObjItr->eObjType );
3317 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_DIRECTION, sString );
3318 0 : if( aObjItr->bHasError )
3319 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_CONTAINS_ERROR, XML_TRUE );
3320 : }
3321 : else
3322 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_MARKED_INVALID, XML_TRUE );
3323 0 : SvXMLElementExport aRangeElem( *this, XML_NAMESPACE_TABLE, XML_HIGHLIGHTED_RANGE, true, true );
3324 0 : ++aObjItr;
3325 0 : }
3326 0 : OUStringBuffer aBuffer;
3327 0 : ScMyDetectiveOpVec::const_iterator aOpItr(rOpVec.begin());
3328 0 : ScMyDetectiveOpVec::const_iterator aEndOpItr(rOpVec.end());
3329 0 : while(aOpItr != aEndOpItr)
3330 : {
3331 0 : OUString sOpString;
3332 0 : ScXMLConverter::GetStringFromDetOpType( sOpString, aOpItr->eOpType );
3333 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, sOpString );
3334 0 : ::sax::Converter::convertNumber( aBuffer, aOpItr->nIndex );
3335 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_INDEX, aBuffer.makeStringAndClear() );
3336 0 : SvXMLElementExport aRangeElem( *this, XML_NAMESPACE_TABLE, XML_OPERATION, true, true );
3337 0 : ++aOpItr;
3338 0 : }
3339 : }
3340 : }
3341 212 : }
3342 :
3343 212 : void ScXMLExport::SetRepeatAttribute(sal_Int32 nEqualCellCount, bool bIncProgress)
3344 : {
3345 : // nEqualCellCount is additional cells, so the attribute value is nEqualCellCount+1
3346 212 : if (nEqualCellCount > 0)
3347 : {
3348 0 : sal_Int32 nTemp(nEqualCellCount + 1);
3349 0 : OUString sOUEqualCellCount(OUString::valueOf(nTemp));
3350 0 : AddAttribute(sAttrColumnsRepeated, sOUEqualCellCount);
3351 0 : if (bIncProgress)
3352 0 : IncrementProgressBar(sal_False, nEqualCellCount);
3353 : }
3354 212 : }
3355 :
3356 0 : bool ScXMLExport::IsCellTypeEqual (const ScMyCell& aCell1, const ScMyCell& aCell2) const
3357 : {
3358 0 : return (aCell1.nType == aCell2.nType);
3359 : }
3360 :
3361 8 : bool ScXMLExport::IsEditCell(const com::sun::star::table::CellAddress& aAddress, ScMyCell* pMyCell) const
3362 : {
3363 : ScAddress aCoreAddress(static_cast<SCCOL>(aAddress.Column),
3364 : static_cast<SCROW>(aAddress.Row),
3365 8 : static_cast<SCTAB>(aAddress.Sheet));
3366 :
3367 8 : ScRefCellValue aCell;
3368 8 : aCell.assign(const_cast<ScDocument&>(*GetDocument()), aCoreAddress);
3369 :
3370 8 : if (pMyCell)
3371 8 : pMyCell->maBaseCell = aCell;
3372 :
3373 8 : return (aCell.meType == CELLTYPE_EDIT);
3374 : }
3375 :
3376 8 : bool ScXMLExport::IsEditCell(ScMyCell& rCell) const
3377 : {
3378 8 : if (rCell.bKnowWhetherIsEditCell)
3379 0 : return rCell.bIsEditCell;
3380 : else
3381 : {
3382 8 : rCell.bIsEditCell = IsEditCell(rCell.aCellAddress, &rCell);
3383 8 : rCell.bKnowWhetherIsEditCell = true;
3384 8 : return rCell.bIsEditCell;
3385 : }
3386 : }
3387 :
3388 0 : bool ScXMLExport::IsMultiLineFormulaCell(ScMyCell& rCell) const
3389 : {
3390 0 : if (!rCell.maBaseCell.isEmpty())
3391 : {
3392 0 : if (rCell.maBaseCell.meType != CELLTYPE_FORMULA)
3393 0 : return false;
3394 :
3395 0 : return rCell.maBaseCell.mpFormula->IsMultilineResult();
3396 : }
3397 :
3398 : ScAddress aAddr(static_cast<SCCOL>(rCell.aCellAddress.Column),
3399 : static_cast<SCROW>(rCell.aCellAddress.Row),
3400 0 : static_cast<SCTAB>(rCell.aCellAddress.Sheet));
3401 :
3402 0 : rCell.maBaseCell.assign(*pDoc, aAddr);
3403 0 : if (rCell.maBaseCell.meType != CELLTYPE_FORMULA)
3404 0 : return false;
3405 :
3406 0 : return rCell.maBaseCell.mpFormula->IsMultilineResult();
3407 : }
3408 :
3409 0 : bool ScXMLExport::IsCellEqual (ScMyCell& aCell1, ScMyCell& aCell2)
3410 : {
3411 0 : ScAddress aCellPos1;
3412 0 : ScUnoConversion::FillScAddress( aCellPos1, aCell1.aCellAddress );
3413 0 : ScAddress aCellPos2;
3414 0 : ScUnoConversion::FillScAddress( aCellPos2, aCell2.aCellAddress );
3415 0 : bool bIsEqual = false;
3416 0 : if( !aCell1.bIsMergedBase && !aCell2.bIsMergedBase &&
3417 0 : aCell1.bIsCovered == aCell2.bIsCovered &&
3418 0 : !aCell1.bIsMatrixBase && !aCell2.bIsMatrixBase &&
3419 0 : aCell1.bIsMatrixCovered == aCell2.bIsMatrixCovered &&
3420 0 : aCell1.bHasAnnotation == aCell2.bHasAnnotation &&
3421 0 : !aCell1.bHasShape && !aCell2.bHasShape &&
3422 0 : aCell1.bHasAreaLink == aCell2.bHasAreaLink &&
3423 0 : !aCell1.bHasDetectiveObj && !aCell2.bHasDetectiveObj)
3424 : {
3425 0 : if( (aCell1.bHasAreaLink &&
3426 0 : (aCell1.aAreaLink.GetColCount() == 1) &&
3427 0 : (aCell2.aAreaLink.GetColCount() == 1) &&
3428 0 : aCell1.aAreaLink.Compare( aCell2.aAreaLink ) ) ||
3429 0 : !aCell1.bHasAreaLink )
3430 : {
3431 0 : if (!aCell1.bHasAnnotation || (aCell1.bHasAnnotation && false/*IsAnnotationEqual(aCell1.xCell, aCell2.xCell)*/)) // no longer compareable
3432 : {
3433 0 : if ((((aCell1.nStyleIndex == aCell2.nStyleIndex) && (aCell1.bIsAutoStyle == aCell2.bIsAutoStyle)) ||
3434 0 : ((aCell1.nStyleIndex == aCell2.nStyleIndex) && (aCell1.nStyleIndex == -1))) &&
3435 0 : (aCell1.nValidationIndex == aCell2.nValidationIndex) &&
3436 0 : IsCellTypeEqual(aCell1, aCell2))
3437 : {
3438 0 : switch ( aCell1.nType )
3439 : {
3440 : case table::CellContentType_EMPTY :
3441 : {
3442 0 : bIsEqual = true;
3443 : }
3444 0 : break;
3445 : case table::CellContentType_VALUE :
3446 : {
3447 0 : if(!aCell1.bHasDoubleValue)
3448 : {
3449 0 : aCell1.fValue = pDoc->GetValue( aCellPos1 );
3450 0 : aCell1.bHasDoubleValue = true;
3451 : }
3452 0 : if (!aCell2.bHasDoubleValue)
3453 : {
3454 0 : aCell2.fValue = pDoc->GetValue( aCellPos2 );
3455 0 : aCell2.bHasDoubleValue = true;
3456 : }
3457 : // #i29101# number format may be different from column default styles,
3458 : // but can lead to different value types, so it must also be compared
3459 0 : bIsEqual = (aCell1.nNumberFormat == aCell2.nNumberFormat) &&
3460 0 : (aCell1.fValue == aCell2.fValue);
3461 : }
3462 0 : break;
3463 : case table::CellContentType_TEXT :
3464 : {
3465 0 : if (IsEditCell(aCell1) || IsEditCell(aCell2))
3466 0 : bIsEqual = false;
3467 : else
3468 : {
3469 0 : GetCellText(aCell1, aCellPos1);
3470 0 : GetCellText(aCell2, aCellPos2);
3471 0 : bIsEqual = (aCell1.sStringValue == aCell2.sStringValue) &&
3472 0 : (lcl_GetRawString(pDoc, aCellPos1) == lcl_GetRawString(pDoc, aCellPos2));
3473 : }
3474 : }
3475 0 : break;
3476 : case table::CellContentType_FORMULA :
3477 : {
3478 0 : bIsEqual = false;
3479 : }
3480 0 : break;
3481 : default :
3482 : {
3483 0 : bIsEqual = false;
3484 : }
3485 0 : break;
3486 : }
3487 : }
3488 : }
3489 : }
3490 : }
3491 0 : return bIsEqual;
3492 : }
3493 :
3494 8 : void ScXMLExport::WriteCalculationSettings(const uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc)
3495 : {
3496 8 : uno::Reference<beans::XPropertySet> xPropertySet(xSpreadDoc, uno::UNO_QUERY);
3497 8 : if (xPropertySet.is())
3498 : {
3499 8 : bool bCalcAsShown (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_CALCASSHOWN)) ));
3500 8 : bool bIgnoreCase (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_IGNORECASE)) ));
3501 8 : bool bLookUpLabels (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_LOOKUPLABELS)) ));
3502 8 : bool bMatchWholeCell (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_MATCHWHOLE)) ));
3503 8 : bool bUseRegularExpressions (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_REGEXENABLED)) ));
3504 8 : bool bIsIterationEnabled (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_ITERENABLED)) ));
3505 8 : sal_uInt16 nYear2000 (pDoc ? pDoc->GetDocOptions().GetYear2000() : 0);
3506 8 : sal_Int32 nIterationCount(100);
3507 8 : xPropertySet->getPropertyValue( OUString(SC_UNO_ITERCOUNT)) >>= nIterationCount;
3508 8 : double fIterationEpsilon = 0;
3509 8 : xPropertySet->getPropertyValue( OUString(SC_UNO_ITEREPSILON)) >>= fIterationEpsilon;
3510 8 : util::Date aNullDate;
3511 8 : xPropertySet->getPropertyValue( OUString(SC_UNO_NULLDATE)) >>= aNullDate;
3512 16 : if (bCalcAsShown || bIgnoreCase || !bLookUpLabels || !bMatchWholeCell || !bUseRegularExpressions ||
3513 14 : bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001) ||
3514 22 : aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899 || nYear2000 != 1930)
3515 : {
3516 1 : if (bIgnoreCase)
3517 1 : AddAttribute(XML_NAMESPACE_TABLE, XML_CASE_SENSITIVE, XML_FALSE);
3518 1 : if (bCalcAsShown)
3519 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_PRECISION_AS_SHOWN, XML_TRUE);
3520 1 : if (!bMatchWholeCell)
3521 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL, XML_FALSE);
3522 1 : if (!bLookUpLabels)
3523 1 : AddAttribute(XML_NAMESPACE_TABLE, XML_AUTOMATIC_FIND_LABELS, XML_FALSE);
3524 1 : if (!bUseRegularExpressions)
3525 1 : AddAttribute(XML_NAMESPACE_TABLE, XML_USE_REGULAR_EXPRESSIONS, XML_FALSE);
3526 1 : if (nYear2000 != 1930)
3527 : {
3528 0 : OUStringBuffer sBuffer;
3529 0 : ::sax::Converter::convertNumber(sBuffer, nYear2000);
3530 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NULL_YEAR, sBuffer.makeStringAndClear());
3531 : }
3532 1 : SvXMLElementExport aCalcSettings(*this, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, true, true);
3533 : {
3534 1 : if (aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899)
3535 : {
3536 0 : OUStringBuffer sDate;
3537 0 : GetMM100UnitConverter().convertDateTime(sDate, 0.0, aNullDate);
3538 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_DATE_VALUE, sDate.makeStringAndClear());
3539 0 : SvXMLElementExport aElemNullDate(*this, XML_NAMESPACE_TABLE, XML_NULL_DATE, true, true);
3540 : }
3541 1 : if (bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001))
3542 : {
3543 1 : OUStringBuffer sBuffer;
3544 1 : if (bIsIterationEnabled)
3545 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_STATUS, XML_ENABLE);
3546 1 : if (nIterationCount != 100)
3547 : {
3548 : ::sax::Converter::convertNumber(sBuffer,
3549 0 : nIterationCount);
3550 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_STEPS, sBuffer.makeStringAndClear());
3551 : }
3552 1 : if (!::rtl::math::approxEqual(fIterationEpsilon, 0.001))
3553 : {
3554 : ::sax::Converter::convertDouble(sBuffer,
3555 1 : fIterationEpsilon);
3556 1 : AddAttribute(XML_NAMESPACE_TABLE, XML_MAXIMUM_DIFFERENCE, sBuffer.makeStringAndClear());
3557 : }
3558 1 : SvXMLElementExport aElemIteration(*this, XML_NAMESPACE_TABLE, XML_ITERATION, true, true);
3559 : }
3560 1 : }
3561 : }
3562 8 : }
3563 8 : }
3564 :
3565 9 : void ScXMLExport::WriteTableSource()
3566 : {
3567 9 : uno::Reference <sheet::XSheetLinkable> xLinkable (xCurrentTable, uno::UNO_QUERY);
3568 9 : if (xLinkable.is() && GetModel().is())
3569 : {
3570 9 : sheet::SheetLinkMode nMode (xLinkable->getLinkMode());
3571 9 : if (nMode != sheet::SheetLinkMode_NONE)
3572 : {
3573 0 : OUString sLink (xLinkable->getLinkUrl());
3574 0 : uno::Reference <beans::XPropertySet> xProps (GetModel(), uno::UNO_QUERY);
3575 0 : if (xProps.is())
3576 : {
3577 0 : uno::Reference <container::XIndexAccess> xIndex(xProps->getPropertyValue(OUString(SC_UNO_SHEETLINKS)), uno::UNO_QUERY);
3578 0 : if (xIndex.is())
3579 : {
3580 0 : sal_Int32 nCount(xIndex->getCount());
3581 0 : if (nCount)
3582 : {
3583 0 : bool bFound(false);
3584 0 : uno::Reference <beans::XPropertySet> xLinkProps;
3585 0 : for (sal_Int32 i = 0; (i < nCount) && !bFound; ++i)
3586 : {
3587 0 : xLinkProps.set(xIndex->getByIndex(i), uno::UNO_QUERY);
3588 0 : if (xLinkProps.is())
3589 : {
3590 0 : OUString sNewLink;
3591 0 : if (xLinkProps->getPropertyValue(OUString(SC_UNONAME_LINKURL)) >>= sNewLink)
3592 0 : bFound = sLink.equals(sNewLink);
3593 : }
3594 : }
3595 0 : if (bFound && xLinkProps.is())
3596 : {
3597 0 : OUString sFilter;
3598 0 : OUString sFilterOptions;
3599 0 : OUString sTableName (xLinkable->getLinkSheetName());
3600 0 : sal_Int32 nRefresh(0);
3601 0 : xLinkProps->getPropertyValue(OUString(SC_UNONAME_FILTER)) >>= sFilter;
3602 0 : xLinkProps->getPropertyValue(OUString(SC_UNONAME_FILTOPT)) >>= sFilterOptions;
3603 0 : xLinkProps->getPropertyValue(OUString(SC_UNONAME_REFDELAY)) >>= nRefresh;
3604 0 : if (!sLink.isEmpty())
3605 : {
3606 0 : AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
3607 0 : AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, GetRelativeReference(sLink));
3608 0 : if (!sTableName.isEmpty())
3609 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_NAME, sTableName);
3610 0 : if (!sFilter.isEmpty())
3611 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_NAME, sFilter);
3612 0 : if (!sFilterOptions.isEmpty())
3613 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_OPTIONS, sFilterOptions);
3614 0 : if (nMode != sheet::SheetLinkMode_NORMAL)
3615 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_MODE, XML_COPY_RESULTS_ONLY);
3616 0 : if( nRefresh )
3617 : {
3618 0 : OUStringBuffer sBuffer;
3619 : ::sax::Converter::convertDuration( sBuffer,
3620 0 : (double)nRefresh / 86400 );
3621 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_REFRESH_DELAY, sBuffer.makeStringAndClear() );
3622 : }
3623 0 : SvXMLElementExport aSourceElem(*this, XML_NAMESPACE_TABLE, XML_TABLE_SOURCE, true, true);
3624 0 : }
3625 0 : }
3626 : }
3627 0 : }
3628 0 : }
3629 : }
3630 9 : }
3631 9 : }
3632 :
3633 : // core implementation
3634 9 : void ScXMLExport::WriteScenario()
3635 : {
3636 9 : if (pDoc && pDoc->IsScenario(static_cast<SCTAB>(nCurrentTable)))
3637 : {
3638 0 : OUString sComment;
3639 0 : Color aColor;
3640 : sal_uInt16 nFlags;
3641 0 : pDoc->GetScenarioData(static_cast<SCTAB>(nCurrentTable), sComment, aColor, nFlags);
3642 0 : if (!(nFlags & SC_SCENARIO_SHOWFRAME))
3643 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_BORDER, XML_FALSE);
3644 0 : OUStringBuffer aBuffer;
3645 0 : ::sax::Converter::convertColor(aBuffer, aColor.GetColor());
3646 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_BORDER_COLOR, aBuffer.makeStringAndClear());
3647 0 : if (!(nFlags & SC_SCENARIO_TWOWAY))
3648 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_COPY_BACK, XML_FALSE);
3649 0 : if (!(nFlags & SC_SCENARIO_ATTRIB))
3650 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_COPY_STYLES, XML_FALSE);
3651 0 : if (nFlags & SC_SCENARIO_VALUE)
3652 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_COPY_FORMULAS, XML_FALSE);
3653 0 : if (nFlags & SC_SCENARIO_PROTECT)
3654 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
3655 : ::sax::Converter::convertBool(aBuffer,
3656 0 : pDoc->IsActiveScenario(static_cast<SCTAB>(nCurrentTable)));
3657 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_IS_ACTIVE, aBuffer.makeStringAndClear());
3658 0 : const ScRangeList* pRangeList = pDoc->GetScenarioRanges(static_cast<SCTAB>(nCurrentTable));
3659 0 : OUString sRangeListStr;
3660 0 : ScRangeStringConverter::GetStringFromRangeList( sRangeListStr, pRangeList, pDoc, FormulaGrammar::CONV_OOO );
3661 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_SCENARIO_RANGES, sRangeListStr);
3662 0 : if (!sComment.isEmpty())
3663 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_COMMENT, sComment);
3664 0 : SvXMLElementExport aElem(*this, XML_NAMESPACE_TABLE, XML_SCENARIO, sal_True, sal_True);
3665 : }
3666 9 : }
3667 :
3668 8 : void ScXMLExport::WriteTheLabelRanges( const uno::Reference< sheet::XSpreadsheetDocument >& xSpreadDoc )
3669 : {
3670 8 : uno::Reference< beans::XPropertySet > xDocProp( xSpreadDoc, uno::UNO_QUERY );
3671 16 : if( !xDocProp.is() ) return;
3672 :
3673 8 : sal_Int32 nCount(0);
3674 16 : uno::Reference< container::XIndexAccess > xColRangesIAccess(xDocProp->getPropertyValue( OUString( SC_UNO_COLLABELRNG ) ), uno::UNO_QUERY);
3675 8 : if( xColRangesIAccess.is() )
3676 8 : nCount += xColRangesIAccess->getCount();
3677 :
3678 16 : uno::Reference< container::XIndexAccess > xRowRangesIAccess(xDocProp->getPropertyValue( OUString( SC_UNO_ROWLABELRNG ) ), uno::UNO_QUERY);
3679 8 : if( xRowRangesIAccess.is() )
3680 8 : nCount += xRowRangesIAccess->getCount();
3681 :
3682 8 : if( nCount )
3683 : {
3684 0 : SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_LABEL_RANGES, true, true );
3685 0 : WriteLabelRanges( xColRangesIAccess, true );
3686 0 : WriteLabelRanges( xRowRangesIAccess, false );
3687 8 : }
3688 : }
3689 :
3690 0 : void ScXMLExport::WriteLabelRanges( const uno::Reference< container::XIndexAccess >& xRangesIAccess, bool bColumn )
3691 : {
3692 0 : if( !xRangesIAccess.is() ) return;
3693 :
3694 0 : sal_Int32 nCount(xRangesIAccess->getCount());
3695 0 : for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
3696 : {
3697 0 : uno::Reference< sheet::XLabelRange > xRange(xRangesIAccess->getByIndex( nIndex ), uno::UNO_QUERY);
3698 0 : if( xRange.is() )
3699 : {
3700 0 : OUString sRangeStr;
3701 0 : table::CellRangeAddress aCellRange( xRange->getLabelArea() );
3702 0 : ScRangeStringConverter::GetStringFromRange( sRangeStr, aCellRange, pDoc, FormulaGrammar::CONV_OOO );
3703 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_LABEL_CELL_RANGE_ADDRESS, sRangeStr );
3704 0 : aCellRange = xRange->getDataArea();
3705 0 : ScRangeStringConverter::GetStringFromRange( sRangeStr, aCellRange, pDoc, FormulaGrammar::CONV_OOO );
3706 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_DATA_CELL_RANGE_ADDRESS, sRangeStr );
3707 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_ORIENTATION, bColumn ? XML_COLUMN : XML_ROW );
3708 0 : SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_LABEL_RANGE, true, true );
3709 : }
3710 0 : }
3711 : }
3712 :
3713 8 : void ScXMLExport::WriteNamedExpressions()
3714 : {
3715 8 : if (!pDoc)
3716 8 : return;
3717 8 : ScRangeName* pNamedRanges = pDoc->GetRangeName();
3718 8 : WriteNamedRange(pNamedRanges);
3719 : }
3720 :
3721 8 : void ScXMLExport::WriteNamedRange(ScRangeName* pRangeName)
3722 : {
3723 : //write a global or local ScRangeName
3724 8 : SvXMLElementExport aElemNEs(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSIONS, true, true);
3725 8 : for (ScRangeName::iterator it = pRangeName->begin(); it != pRangeName->end(); ++it)
3726 : {
3727 0 : AddAttribute(sAttrName, it->second->GetName());
3728 :
3729 0 : OUString sBaseCellAddress;
3730 0 : ScRangeStringConverter::GetStringFromAddress( sBaseCellAddress, it->second->GetPos(), pDoc,
3731 0 : FormulaGrammar::CONV_OOO, ' ', false, SCA_ABS_3D);
3732 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, sBaseCellAddress);
3733 :
3734 0 : String sSymbol;
3735 0 : it->second->GetSymbol(sSymbol, pDoc->GetStorageGrammar());
3736 0 : OUString sTempSymbol(sSymbol);
3737 0 : ScRange aRange;
3738 0 : if (it->second->IsReference(aRange))
3739 : {
3740 :
3741 0 : OUString sContent(sTempSymbol.copy(1, sTempSymbol.getLength() -2 ));
3742 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sContent);
3743 :
3744 0 : sal_Int32 nRangeType = it->second->GetUnoType();
3745 0 : OUStringBuffer sBufferRangeType;
3746 0 : if ((nRangeType & sheet::NamedRangeFlag::COLUMN_HEADER) == sheet::NamedRangeFlag::COLUMN_HEADER)
3747 0 : sBufferRangeType.append(GetXMLToken(XML_REPEAT_COLUMN));
3748 0 : if ((nRangeType & sheet::NamedRangeFlag::ROW_HEADER) == sheet::NamedRangeFlag::ROW_HEADER)
3749 : {
3750 0 : if (!sBufferRangeType.isEmpty())
3751 0 : sBufferRangeType.appendAscii(" ");
3752 0 : sBufferRangeType.append(GetXMLToken(XML_REPEAT_ROW));
3753 : }
3754 0 : if ((nRangeType & sheet::NamedRangeFlag::FILTER_CRITERIA) == sheet::NamedRangeFlag::FILTER_CRITERIA)
3755 : {
3756 0 : if (!sBufferRangeType.isEmpty())
3757 0 : sBufferRangeType.appendAscii(" ");
3758 0 : sBufferRangeType.append(GetXMLToken(XML_FILTER));
3759 : }
3760 0 : if ((nRangeType & sheet::NamedRangeFlag::PRINT_AREA) == sheet::NamedRangeFlag::PRINT_AREA)
3761 : {
3762 0 : if (!sBufferRangeType.isEmpty())
3763 0 : sBufferRangeType.appendAscii(" ");
3764 0 : sBufferRangeType.append(GetXMLToken(XML_PRINT_RANGE));
3765 : }
3766 0 : OUString sRangeType = sBufferRangeType.makeStringAndClear();
3767 0 : if (!sRangeType.isEmpty())
3768 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_RANGE_USABLE_AS, sRangeType);
3769 0 : SvXMLElementExport aElemNR(*this, XML_NAMESPACE_TABLE, XML_NAMED_RANGE, true, true);
3770 :
3771 : }
3772 : else
3773 : {
3774 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, sTempSymbol);
3775 0 : SvXMLElementExport aElemNE(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, true, true);
3776 : }
3777 8 : }
3778 8 : }
3779 :
3780 : namespace {
3781 :
3782 15 : OUString getCondFormatEntryType(const ScColorScaleEntry& rEntry, bool bFirst = true)
3783 : {
3784 15 : switch(rEntry.GetType())
3785 : {
3786 : case COLORSCALE_MIN:
3787 2 : return OUString("minimum");
3788 : case COLORSCALE_MAX:
3789 2 : return OUString("maximum");
3790 : case COLORSCALE_PERCENT:
3791 2 : return OUString("percent");
3792 : case COLORSCALE_PERCENTILE:
3793 3 : return OUString("percentile");
3794 : case COLORSCALE_FORMULA:
3795 2 : return OUString("formula");
3796 : case COLORSCALE_VALUE:
3797 4 : return OUString("number");
3798 : case COLORSCALE_AUTO:
3799 : // only important for data bars
3800 0 : if(bFirst)
3801 0 : return OUString("auto-minimum");
3802 : else
3803 0 : return OUString("auto-maximum");
3804 : }
3805 0 : return OUString();
3806 : }
3807 :
3808 0 : OUString getIconSetName(ScIconSetType eType)
3809 : {
3810 0 : const char* pName = NULL;
3811 0 : ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
3812 0 : for(;pMap->pName;++pMap)
3813 : {
3814 0 : if(pMap->eType == eType)
3815 : {
3816 0 : pName = pMap->pName;
3817 0 : break;
3818 : }
3819 : }
3820 : assert(pName);
3821 0 : return OUString::createFromAscii(pName);
3822 : }
3823 :
3824 0 : OUString getDateStringForType(condformat::ScCondFormatDateType eType)
3825 : {
3826 0 : switch(eType)
3827 : {
3828 : case condformat::TODAY:
3829 0 : return OUString("today");
3830 : case condformat::YESTERDAY:
3831 0 : return OUString("yesterday");
3832 : case condformat::TOMORROW:
3833 0 : return OUString("tomorrow");
3834 : case condformat::LAST7DAYS:
3835 0 : return OUString("last-7-days");
3836 : case condformat::THISWEEK:
3837 0 : return OUString("this-week");
3838 : case condformat::LASTWEEK:
3839 0 : return OUString("last-week");
3840 : case condformat::NEXTWEEK:
3841 0 : return OUString("next-week");
3842 : case condformat::THISMONTH:
3843 0 : return OUString("this-month");
3844 : case condformat::LASTMONTH:
3845 0 : return OUString("last-month");
3846 : case condformat::NEXTMONTH:
3847 0 : return OUString("next-month");
3848 : case condformat::THISYEAR:
3849 0 : return OUString("this-year");
3850 : case condformat::LASTYEAR:
3851 0 : return OUString("last-year");
3852 : case condformat::NEXTYEAR:
3853 0 : return OUString("next-year");
3854 : }
3855 :
3856 0 : return OUString();
3857 : }
3858 :
3859 : }
3860 :
3861 9 : void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
3862 : {
3863 9 : ScConditionalFormatList* pCondFormatList = pDoc->GetCondFormList(nTab);
3864 9 : if(pCondFormatList)
3865 : {
3866 9 : if(pCondFormatList && !pCondFormatList->size())
3867 15 : return;
3868 :
3869 3 : SvXMLElementExport aElementCondFormats(*this, XML_NAMESPACE_CALC_EXT, XML_CONDITIONAL_FORMATS, true, true);
3870 :
3871 3 : if(pCondFormatList)
3872 : {
3873 51 : for(ScConditionalFormatList::const_iterator itr = pCondFormatList->begin();
3874 34 : itr != pCondFormatList->end(); ++itr)
3875 : {
3876 14 : OUString sRanges;
3877 14 : const ScRangeList& rRangeList = itr->GetRange();
3878 14 : ScRangeStringConverter::GetStringFromRangeList( sRanges, &rRangeList, pDoc, formula::FormulaGrammar::CONV_ODF );
3879 14 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TARGET_RANGE_ADDRESS, sRanges);
3880 28 : SvXMLElementExport aElementCondFormat(*this, XML_NAMESPACE_CALC_EXT, XML_CONDITIONAL_FORMAT, true, true);
3881 14 : size_t nEntries = itr->size();
3882 28 : for(size_t i = 0; i < nEntries; ++i)
3883 : {
3884 14 : const ScFormatEntry* pFormatEntry = itr->GetEntry(i);
3885 14 : if(pFormatEntry->GetType()==condformat::CONDITION)
3886 : {
3887 8 : const ScCondFormatEntry* pEntry = static_cast<const ScCondFormatEntry*>(pFormatEntry);
3888 8 : OUStringBuffer aCond;
3889 8 : ScAddress aPos = pEntry->GetSrcPos();
3890 8 : switch(pEntry->GetOperation())
3891 : {
3892 : case SC_COND_EQUAL:
3893 0 : aCond.append('=');
3894 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3895 0 : break;
3896 : case SC_COND_LESS:
3897 0 : aCond.append('<');
3898 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3899 0 : break;
3900 : case SC_COND_GREATER:
3901 0 : aCond.append('>');
3902 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3903 0 : break;
3904 : case SC_COND_EQLESS:
3905 0 : aCond.append("<=");
3906 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3907 0 : break;
3908 : case SC_COND_EQGREATER:
3909 0 : aCond.append(">=");
3910 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3911 0 : break;
3912 : case SC_COND_NOTEQUAL:
3913 0 : aCond.append("!=");
3914 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3915 0 : break;
3916 : case SC_COND_BETWEEN:
3917 0 : aCond.append(OUString("between("));
3918 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3919 0 : aCond.append(',');
3920 0 : aCond.append(pEntry->GetExpression(aPos, 1, 0, formula::FormulaGrammar::GRAM_ODFF));
3921 0 : aCond.append(')');
3922 0 : break;
3923 : case SC_COND_NOTBETWEEN:
3924 0 : aCond.append(OUString("not-between("));
3925 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3926 0 : aCond.append(',');
3927 0 : aCond.append(pEntry->GetExpression(aPos, 1, 0, formula::FormulaGrammar::GRAM_ODFF));
3928 0 : aCond.append(')');
3929 0 : break;
3930 : case SC_COND_DUPLICATE:
3931 0 : aCond.append("duplicate");
3932 0 : break;
3933 : case SC_COND_NOTDUPLICATE:
3934 0 : aCond.append("unique");
3935 0 : break;
3936 : case SC_COND_DIRECT:
3937 0 : aCond.append("formula-is(");
3938 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3939 0 : aCond.append(')');
3940 0 : break;
3941 : case SC_COND_TOP10:
3942 1 : aCond.append("top-elements(");
3943 1 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3944 1 : aCond.append(")");
3945 1 : break;
3946 : case SC_COND_BOTTOM10:
3947 1 : aCond.append("bottom-elements(");
3948 1 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3949 1 : aCond.append(")");
3950 1 : break;
3951 : case SC_COND_TOP_PERCENT:
3952 1 : aCond.append("top-percent(");
3953 1 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3954 1 : aCond.append(")");
3955 1 : break;
3956 : case SC_COND_BOTTOM_PERCENT:
3957 1 : aCond.append("bottom-percent(");
3958 1 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3959 1 : aCond.append(")");
3960 1 : break;
3961 : case SC_COND_ABOVE_AVERAGE:
3962 1 : aCond.append("above-average");
3963 1 : break;
3964 : case SC_COND_BELOW_AVERAGE:
3965 1 : aCond.append("below-average");
3966 1 : break;
3967 : case SC_COND_ABOVE_EQUAL_AVERAGE:
3968 1 : aCond.append("above-equal-average");
3969 1 : break;
3970 : case SC_COND_BELOW_EQUAL_AVERAGE:
3971 1 : aCond.append("below-equal-average");
3972 1 : break;
3973 : case SC_COND_ERROR:
3974 0 : aCond.append("is-error");
3975 0 : break;
3976 : case SC_COND_NOERROR:
3977 0 : aCond.append("is-no-error");
3978 0 : break;
3979 : case SC_COND_BEGINS_WITH:
3980 0 : aCond.append("begins-with(");
3981 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3982 0 : aCond.append(")");
3983 0 : break;
3984 : case SC_COND_ENDS_WITH:
3985 0 : aCond.append("ends-with(");
3986 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3987 0 : aCond.append(")");
3988 0 : break;
3989 : case SC_COND_CONTAINS_TEXT:
3990 0 : aCond.append("contains-text(");
3991 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3992 0 : aCond.append(")");
3993 0 : break;
3994 : case SC_COND_NOT_CONTAINS_TEXT:
3995 0 : aCond.append("not-contains-text(");
3996 0 : aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
3997 0 : aCond.append(")");
3998 0 : break;
3999 : case SC_COND_NONE:
4000 0 : continue;
4001 : default:
4002 : SAL_WARN("sc", "unimplemented conditional format export");
4003 : }
4004 8 : OUString sStyle = ScStyleNameConversion::DisplayToProgrammaticName(pEntry->GetStyle(), SFX_STYLE_FAMILY_PARA);
4005 8 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_APPLY_STYLE_NAME, sStyle);
4006 8 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, aCond.makeStringAndClear());
4007 :
4008 16 : OUString sBaseAddress;
4009 8 : ScRangeStringConverter::GetStringFromAddress( sBaseAddress, aPos, pDoc,formula::FormulaGrammar::CONV_ODF );
4010 8 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_BASE_CELL_ADDRESS, sBaseAddress);
4011 16 : SvXMLElementExport aElementCondEntry(*this, XML_NAMESPACE_CALC_EXT, XML_CONDITION, true, true);
4012 : }
4013 6 : else if(pFormatEntry->GetType() == condformat::COLORSCALE)
4014 : {
4015 6 : SvXMLElementExport aElementColorScale(*this, XML_NAMESPACE_CALC_EXT, XML_COLOR_SCALE, true, true);
4016 6 : const ScColorScaleFormat& mrColorScale = static_cast<const ScColorScaleFormat&>(*pFormatEntry);
4017 63 : for(ScColorScaleFormat::const_iterator it = mrColorScale.begin();
4018 42 : it != mrColorScale.end(); ++it)
4019 : {
4020 15 : if(it->GetType() == COLORSCALE_FORMULA)
4021 : {
4022 2 : OUString sFormula = it->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
4023 2 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
4024 : }
4025 : else
4026 13 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, OUString::valueOf(it->GetValue()));
4027 :
4028 15 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*it));
4029 15 : OUStringBuffer aBuffer;
4030 15 : ::sax::Converter::convertColor(aBuffer, it->GetColor().GetColor());
4031 15 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLOR, aBuffer.makeStringAndClear());
4032 15 : SvXMLElementExport aElementColorScaleEntry(*this, XML_NAMESPACE_CALC_EXT, XML_COLOR_SCALE_ENTRY, true, true);
4033 21 : }
4034 : }
4035 0 : else if(pFormatEntry->GetType() == condformat::DATABAR)
4036 : {
4037 0 : const ScDataBarFormatData* pFormatData = static_cast<const ScDataBarFormat&>(*pFormatEntry).GetDataBarData();
4038 0 : if(!pFormatData->mbGradient)
4039 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_GRADIENT, XML_FALSE);
4040 0 : if(pFormatData->mbOnlyBar)
4041 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_SHOW_VALUE, XML_FALSE);
4042 :
4043 0 : if(pFormatData->mbNeg)
4044 : {
4045 0 : if(pFormatData->mpNegativeColor)
4046 : {
4047 0 : OUStringBuffer aBuffer;
4048 0 : ::sax::Converter::convertColor(aBuffer, pFormatData->mpNegativeColor->GetColor());
4049 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_NEGATIVE_COLOR, aBuffer.makeStringAndClear());
4050 : }
4051 : else
4052 : {
4053 0 : OUStringBuffer aBuffer;
4054 0 : ::sax::Converter::convertColor(aBuffer, Color(COL_LIGHTRED).GetColor());
4055 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_NEGATIVE_COLOR, aBuffer.makeStringAndClear());
4056 : }
4057 : }
4058 :
4059 0 : if(pFormatData->meAxisPosition != databar::AUTOMATIC)
4060 : {
4061 0 : if(pFormatData->meAxisPosition == databar::NONE)
4062 : {
4063 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_AXIS_POSITION, OUString("none"));
4064 : }
4065 : else
4066 : {
4067 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_AXIS_POSITION, OUString("middle"));
4068 : }
4069 : }
4070 :
4071 0 : OUStringBuffer aBuffer;
4072 0 : ::sax::Converter::convertColor(aBuffer, pFormatData->maPositiveColor.GetColor());
4073 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_POSITIVE_COLOR, aBuffer.makeStringAndClear());
4074 :
4075 0 : aBuffer = OUStringBuffer();
4076 0 : ::sax::Converter::convertColor(aBuffer, pFormatData->maAxisColor.GetColor());
4077 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_AXIS_COLOR, aBuffer.makeStringAndClear());
4078 0 : SvXMLElementExport aElementDataBar(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_BAR, true, true);
4079 :
4080 : {
4081 0 : if(pFormatData->mpLowerLimit->GetType() == COLORSCALE_FORMULA)
4082 : {
4083 0 : OUString sFormula = pFormatData->mpLowerLimit->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
4084 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
4085 : }
4086 : else
4087 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, OUString::valueOf(pFormatData->mpLowerLimit->GetValue()));
4088 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*pFormatData->mpLowerLimit, true));
4089 0 : SvXMLElementExport aElementDataBarEntryLower(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true);
4090 : }
4091 :
4092 : {
4093 0 : if(pFormatData->mpUpperLimit->GetType() == COLORSCALE_FORMULA)
4094 : {
4095 0 : OUString sFormula = pFormatData->mpUpperLimit->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
4096 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
4097 : }
4098 : else
4099 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, OUString::valueOf(pFormatData->mpUpperLimit->GetValue()));
4100 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*pFormatData->mpUpperLimit, false));
4101 0 : SvXMLElementExport aElementDataBarEntryUpper(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true);
4102 0 : }
4103 : }
4104 0 : else if(pFormatEntry->GetType() == condformat::ICONSET)
4105 : {
4106 0 : const ScIconSetFormat& mrIconSet = static_cast<const ScIconSetFormat&>(*pFormatEntry);
4107 0 : OUString aIconSetName = getIconSetName(mrIconSet.GetIconSetData()->eIconSetType);
4108 0 : AddAttribute( XML_NAMESPACE_CALC_EXT, XML_ICON_SET_TYPE, aIconSetName );
4109 0 : SvXMLElementExport aElementColorScale(*this, XML_NAMESPACE_CALC_EXT, XML_ICON_SET, true, true);
4110 0 : if(!mrIconSet.GetIconSetData()->mbShowValue)
4111 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_SHOW_VALUE, XML_FALSE);
4112 0 : for(ScIconSetFormat::const_iterator it = mrIconSet.begin();
4113 0 : it != mrIconSet.end(); ++it)
4114 : {
4115 0 : if(it->GetType() == COLORSCALE_FORMULA)
4116 : {
4117 0 : OUString sFormula = it->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
4118 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
4119 : }
4120 : else
4121 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, OUString::valueOf(it->GetValue()));
4122 :
4123 0 : AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*it));
4124 0 : SvXMLElementExport aElementColorScaleEntry(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true);
4125 0 : }
4126 : }
4127 0 : else if(pFormatEntry->GetType() == condformat::DATE)
4128 : {
4129 0 : const ScCondDateFormatEntry& mrDateFormat = static_cast<const ScCondDateFormatEntry&>(*pFormatEntry);
4130 0 : OUString aDateType = getDateStringForType(mrDateFormat.GetDateType());
4131 0 : OUString aStyleName = ScStyleNameConversion::DisplayToProgrammaticName(mrDateFormat.GetStyleName(), SFX_STYLE_FAMILY_PARA );
4132 0 : AddAttribute( XML_NAMESPACE_CALC_EXT, XML_STYLE, aStyleName);
4133 0 : AddAttribute( XML_NAMESPACE_CALC_EXT, XML_DATE, aDateType);
4134 0 : SvXMLElementExport aElementDateFormat(*this, XML_NAMESPACE_CALC_EXT, XML_DATE_IS, true, true);
4135 : }
4136 : }
4137 14 : }
4138 3 : }
4139 : }
4140 : }
4141 :
4142 8 : void ScXMLExport::WriteExternalRefCaches()
4143 : {
4144 8 : if (!pDoc)
4145 8 : return;
4146 :
4147 8 : ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
4148 8 : pRefMgr->resetSrcFileData(GetOrigFileName());
4149 8 : sal_uInt16 nCount = pRefMgr->getExternalFileCount();
4150 8 : for (sal_uInt16 nFileId = 0; nFileId < nCount; ++nFileId)
4151 : {
4152 0 : const OUString* pUrl = pRefMgr->getExternalFileName(nFileId);
4153 0 : if (!pUrl)
4154 0 : continue;
4155 :
4156 0 : vector<OUString> aTabNames;
4157 0 : pRefMgr->getAllCachedTableNames(nFileId, aTabNames);
4158 0 : if (aTabNames.empty())
4159 0 : continue;
4160 :
4161 0 : for (vector<OUString>::const_iterator itr = aTabNames.begin(), itrEnd = aTabNames.end();
4162 : itr != itrEnd; ++itr)
4163 : {
4164 0 : ScExternalRefCache::TableTypeRef pTable = pRefMgr->getCacheTable(nFileId, *itr, false);
4165 0 : if (!pTable.get() || !pTable->isReferenced())
4166 0 : continue;
4167 :
4168 0 : OUStringBuffer aBuf;
4169 0 : aBuf.append(sal_Unicode('\''));
4170 0 : aBuf.append(*pUrl);
4171 0 : aBuf.append(sal_Unicode('\''));
4172 0 : aBuf.append(sal_Unicode('#'));
4173 0 : aBuf.append(*itr);
4174 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, aBuf.makeStringAndClear());
4175 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_PRINT, GetXMLToken(XML_FALSE));
4176 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sExternalRefTabStyleName);
4177 0 : SvXMLElementExport aElemTable(*this, XML_NAMESPACE_TABLE, XML_TABLE, true, true);
4178 : {
4179 0 : const ScExternalRefManager::SrcFileData* pExtFileData = pRefMgr->getExternalFileData(nFileId);
4180 0 : if (pExtFileData)
4181 : {
4182 0 : OUString aRelUrl;
4183 0 : if (!pExtFileData->maRelativeName.isEmpty())
4184 0 : aRelUrl = pExtFileData->maRelativeName;
4185 : else
4186 0 : aRelUrl = GetRelativeReference(pExtFileData->maRelativeName);
4187 0 : AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
4188 0 : AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aRelUrl);
4189 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_NAME, *itr);
4190 0 : if (!pExtFileData->maFilterName.isEmpty())
4191 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_NAME, pExtFileData->maFilterName);
4192 0 : if (!pExtFileData->maFilterOptions.isEmpty())
4193 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_OPTIONS, pExtFileData->maFilterOptions);
4194 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_MODE, XML_COPY_RESULTS_ONLY);
4195 : }
4196 0 : SvXMLElementExport aElemTableSource(*this, XML_NAMESPACE_TABLE, XML_TABLE_SOURCE, true, true);
4197 : }
4198 :
4199 : // Determine maximum column count of used area, for repeated cells.
4200 0 : SCCOL nMaxColsUsed = 1; // assume that there is at least one cell somewhere..
4201 0 : vector<SCROW> aRows;
4202 0 : pTable->getAllRows(aRows);
4203 0 : for (vector<SCROW>::const_iterator itrRow = aRows.begin(), itrRowEnd = aRows.end();
4204 : itrRow != itrRowEnd; ++itrRow)
4205 : {
4206 0 : SCROW nRow = *itrRow;
4207 0 : vector<SCCOL> aCols;
4208 0 : pTable->getAllCols(nRow, aCols);
4209 0 : if (!aCols.empty())
4210 : {
4211 0 : SCCOL nCol = aCols.back();
4212 0 : if (nMaxColsUsed <= nCol)
4213 0 : nMaxColsUsed = nCol + 1;
4214 : }
4215 0 : }
4216 :
4217 : // Column definitions have to be present to make a valid file
4218 : {
4219 0 : if (nMaxColsUsed > 1)
4220 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED,
4221 0 : OUString::number(nMaxColsUsed));
4222 0 : SvXMLElementExport aElemColumn(*this, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true);
4223 : }
4224 :
4225 : // Write cache content for this table.
4226 0 : SCROW nLastRow = 0;
4227 0 : bool bFirstRow = true;
4228 0 : for (vector<SCROW>::const_iterator itrRow = aRows.begin(), itrRowEnd = aRows.end();
4229 : itrRow != itrRowEnd; ++itrRow)
4230 : {
4231 0 : SCROW nRow = *itrRow;
4232 0 : if (bFirstRow)
4233 : {
4234 0 : if (nRow > 0)
4235 : {
4236 0 : if (nRow > 1)
4237 : {
4238 0 : OUStringBuffer aVal;
4239 0 : aVal.append(nRow);
4240 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, aVal.makeStringAndClear());
4241 : }
4242 0 : SvXMLElementExport aElemRow(*this, XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true);
4243 0 : OUStringBuffer aVal;
4244 0 : aVal.append(static_cast<sal_Int32>(nMaxColsUsed));
4245 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4246 0 : SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
4247 : }
4248 : }
4249 : else
4250 : {
4251 0 : SCROW nRowGap = nRow - nLastRow;
4252 0 : if (nRowGap > 1)
4253 : {
4254 0 : if (nRowGap > 2)
4255 : {
4256 0 : OUStringBuffer aVal;
4257 0 : aVal.append(static_cast<sal_Int32>(nRowGap-1));
4258 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, aVal.makeStringAndClear());
4259 : }
4260 0 : SvXMLElementExport aElemRow(*this, XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true);
4261 0 : OUStringBuffer aVal;
4262 0 : aVal.append(static_cast<sal_Int32>(nMaxColsUsed));
4263 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4264 0 : SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
4265 : }
4266 : }
4267 0 : SvXMLElementExport aElemRow(*this, XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true);
4268 :
4269 0 : vector<SCCOL> aCols;
4270 0 : pTable->getAllCols(nRow, aCols);
4271 0 : SCCOL nLastCol = 0;
4272 0 : bool bFirstCol = true;
4273 0 : for (vector<SCCOL>::const_iterator itrCol = aCols.begin(), itrColEnd = aCols.end();
4274 : itrCol != itrColEnd; ++itrCol)
4275 : {
4276 0 : SCCOL nCol = *itrCol;
4277 0 : if (bFirstCol)
4278 : {
4279 0 : if (nCol > 0)
4280 : {
4281 0 : if (nCol > 1)
4282 : {
4283 0 : OUStringBuffer aVal;
4284 0 : aVal.append(static_cast<sal_Int32>(nCol));
4285 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4286 : }
4287 0 : SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
4288 : }
4289 : }
4290 : else
4291 : {
4292 0 : SCCOL nColGap = nCol - nLastCol;
4293 0 : if (nColGap > 1)
4294 : {
4295 0 : if (nColGap > 2)
4296 : {
4297 0 : OUStringBuffer aVal;
4298 0 : aVal.append(static_cast<sal_Int32>(nColGap-1));
4299 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4300 : }
4301 0 : SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
4302 : }
4303 : }
4304 :
4305 : // Write out this cell.
4306 0 : sal_uInt32 nNumFmt = 0;
4307 0 : ScExternalRefCache::TokenRef pToken = pTable->getCell(nCol, nRow, &nNumFmt);
4308 0 : OUString aStrVal;
4309 0 : if (pToken.get())
4310 : {
4311 0 : sal_Int32 nIndex = GetNumberFormatStyleIndex(nNumFmt);
4312 0 : if (nIndex >= 0)
4313 : {
4314 0 : const OUString aStyleName = *pCellStyles->GetStyleNameByIndex(nIndex, true);
4315 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, aStyleName);
4316 : }
4317 :
4318 0 : switch(pToken->GetType())
4319 : {
4320 : case svDouble:
4321 : {
4322 0 : AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
4323 0 : OUStringBuffer aVal;
4324 0 : aVal.append(pToken->GetDouble());
4325 0 : aStrVal = aVal.makeStringAndClear();
4326 0 : AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, aStrVal);
4327 : }
4328 0 : break;
4329 : case svString:
4330 : {
4331 0 : AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
4332 0 : aStrVal = pToken->GetString();
4333 : }
4334 0 : break;
4335 : default:
4336 : ;
4337 : }
4338 : }
4339 0 : SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
4340 0 : SvXMLElementExport aElemText(*this, XML_NAMESPACE_TEXT, XML_P, true, false);
4341 0 : Characters(aStrVal);
4342 :
4343 0 : nLastCol = nCol;
4344 0 : bFirstCol = false;
4345 0 : }
4346 0 : nLastRow = nRow;
4347 0 : bFirstRow = false;
4348 0 : }
4349 0 : }
4350 0 : }
4351 : }
4352 :
4353 : // core implementation
4354 8 : void ScXMLExport::WriteConsolidation()
4355 : {
4356 8 : if (pDoc)
4357 : {
4358 8 : const ScConsolidateParam* pCons(pDoc->GetConsolidateDlgData());
4359 8 : if( pCons )
4360 : {
4361 0 : OUString sStrData;
4362 :
4363 0 : ScXMLConverter::GetStringFromFunction( sStrData, pCons->eFunction );
4364 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_FUNCTION, sStrData );
4365 :
4366 0 : sStrData = OUString();
4367 0 : for( sal_Int32 nIndex = 0; nIndex < pCons->nDataAreaCount; ++nIndex )
4368 0 : ScRangeStringConverter::GetStringFromArea( sStrData, *pCons->ppDataAreas[ nIndex ], pDoc, FormulaGrammar::CONV_OOO, true );
4369 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_SOURCE_CELL_RANGE_ADDRESSES, sStrData );
4370 :
4371 0 : ScRangeStringConverter::GetStringFromAddress( sStrData, ScAddress( pCons->nCol, pCons->nRow, pCons->nTab ), pDoc, FormulaGrammar::CONV_OOO );
4372 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_TARGET_CELL_ADDRESS, sStrData );
4373 :
4374 0 : if( pCons->bByCol && !pCons->bByRow )
4375 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_USE_LABEL, XML_COLUMN );
4376 0 : else if( !pCons->bByCol && pCons->bByRow )
4377 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_USE_LABEL, XML_ROW );
4378 0 : else if( pCons->bByCol && pCons->bByRow )
4379 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_USE_LABEL, XML_BOTH );
4380 :
4381 0 : if( pCons->bReferenceData )
4382 0 : AddAttribute( XML_NAMESPACE_TABLE, XML_LINK_TO_SOURCE_DATA, XML_TRUE );
4383 :
4384 0 : SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_CONSOLIDATION, true, true );
4385 : }
4386 : }
4387 8 : }
4388 :
4389 34 : SvXMLAutoStylePoolP* ScXMLExport::CreateAutoStylePool()
4390 : {
4391 34 : return new ScXMLAutoStylePoolP(*this);
4392 : }
4393 :
4394 8 : XMLPageExport* ScXMLExport::CreatePageExport()
4395 : {
4396 8 : return new XMLTableMasterPageExport( *this );
4397 : }
4398 :
4399 8 : void ScXMLExport::GetChangeTrackViewSettings(uno::Sequence<beans::PropertyValue>& rProps)
4400 : {
4401 8 : ScChangeViewSettings* pViewSettings(GetDocument() ? GetDocument()->GetChangeViewSettings() : NULL);
4402 8 : if (pViewSettings)
4403 : {
4404 0 : sal_Int32 nChangePos(rProps.getLength());
4405 0 : rProps.realloc(nChangePos + 1);
4406 0 : beans::PropertyValue* pProps(rProps.getArray());
4407 0 : if (pProps)
4408 : {
4409 0 : uno::Sequence<beans::PropertyValue> aChangeProps(SC_VIEWCHANGES_COUNT);
4410 0 : beans::PropertyValue* pChangeProps(aChangeProps.getArray());
4411 0 : if (pChangeProps)
4412 : {
4413 0 : pChangeProps[SC_SHOW_CHANGES].Name = OUString("ShowChanges");
4414 0 : pChangeProps[SC_SHOW_CHANGES].Value <<= pViewSettings->ShowChanges();
4415 0 : pChangeProps[SC_SHOW_ACCEPTED_CHANGES].Name = OUString("ShowAcceptedChanges");
4416 0 : pChangeProps[SC_SHOW_ACCEPTED_CHANGES].Value <<= pViewSettings->IsShowAccepted();
4417 0 : pChangeProps[SC_SHOW_REJECTED_CHANGES].Name = OUString("ShowRejectedChanges");
4418 0 : pChangeProps[SC_SHOW_REJECTED_CHANGES].Value <<= pViewSettings->IsShowRejected();
4419 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME].Name = OUString("ShowChangesByDatetime");
4420 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME].Value <<= pViewSettings->HasDate();
4421 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_MODE].Name = OUString("ShowChangesByDatetimeMode");
4422 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_MODE].Value <<= static_cast<sal_Int16>(pViewSettings->GetTheDateMode());
4423 0 : util::DateTime aDateTime;
4424 0 : ScXMLConverter::ConvertCoreToAPIDateTime(pViewSettings->GetTheFirstDateTime(), aDateTime);
4425 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME].Name = OUString("ShowChangesByDatetimeFirstDatetime");
4426 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME].Value <<= aDateTime;
4427 0 : ScXMLConverter::ConvertCoreToAPIDateTime(pViewSettings->GetTheLastDateTime(), aDateTime);
4428 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME].Name = OUString("ShowChangesByDatetimeSecondDatetime");
4429 0 : pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME].Value <<= aDateTime;
4430 0 : pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR].Name = OUString("ShowChangesByAuthor");
4431 0 : pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR].Value <<= pViewSettings->HasAuthor();
4432 0 : pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR_NAME].Name = OUString("ShowChangesByAuthorName");
4433 0 : pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR_NAME].Value <<= OUString (pViewSettings->GetTheAuthorToShow());
4434 0 : pChangeProps[SC_SHOW_CHANGES_BY_COMMENT].Name = OUString("ShowChangesByComment");
4435 0 : pChangeProps[SC_SHOW_CHANGES_BY_COMMENT].Value <<= pViewSettings->HasComment();
4436 0 : pChangeProps[SC_SHOW_CHANGES_BY_COMMENT_TEXT].Name = OUString("ShowChangesByCommentText");
4437 0 : pChangeProps[SC_SHOW_CHANGES_BY_COMMENT_TEXT].Value <<= OUString (pViewSettings->GetTheComment());
4438 0 : pChangeProps[SC_SHOW_CHANGES_BY_RANGES].Name = OUString("ShowChangesByRanges");
4439 0 : pChangeProps[SC_SHOW_CHANGES_BY_RANGES].Value <<= pViewSettings->HasRange();
4440 0 : OUString sRangeList;
4441 0 : ScRangeStringConverter::GetStringFromRangeList(sRangeList, &(pViewSettings->GetTheRangeList()), GetDocument(), FormulaGrammar::CONV_OOO);
4442 0 : pChangeProps[SC_SHOW_CHANGES_BY_RANGES_LIST].Name = OUString("ShowChangesByRangesList");
4443 0 : pChangeProps[SC_SHOW_CHANGES_BY_RANGES_LIST].Value <<= sRangeList;
4444 :
4445 0 : pProps[nChangePos].Name = OUString("TrackedChangesViewSettings");
4446 0 : pProps[nChangePos].Value <<= aChangeProps;
4447 0 : }
4448 : }
4449 : }
4450 8 : }
4451 :
4452 8 : void ScXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>& rProps)
4453 : {
4454 8 : rProps.realloc(4);
4455 8 : beans::PropertyValue* pProps(rProps.getArray());
4456 8 : if(pProps)
4457 : {
4458 8 : if (GetModel().is())
4459 : {
4460 8 : ScModelObj* pDocObj(ScModelObj::getImplementation( GetModel() ));
4461 8 : if (pDocObj)
4462 : {
4463 8 : SfxObjectShell* pEmbeddedObj = pDocObj->GetEmbeddedObject();
4464 8 : if (pEmbeddedObj)
4465 : {
4466 8 : Rectangle aRect(pEmbeddedObj->GetVisArea());
4467 8 : sal_uInt16 i(0);
4468 8 : pProps[i].Name = OUString("VisibleAreaTop");
4469 8 : pProps[i].Value <<= static_cast<sal_Int32>(aRect.getY());
4470 8 : pProps[++i].Name = OUString("VisibleAreaLeft");
4471 8 : pProps[i].Value <<= static_cast<sal_Int32>(aRect.getX());
4472 8 : pProps[++i].Name = OUString("VisibleAreaWidth");
4473 8 : pProps[i].Value <<= static_cast<sal_Int32>(aRect.getWidth());
4474 8 : pProps[++i].Name = OUString("VisibleAreaHeight");
4475 8 : pProps[i].Value <<= static_cast<sal_Int32>(aRect.getHeight());
4476 : }
4477 : }
4478 : }
4479 : }
4480 8 : GetChangeTrackViewSettings(rProps);
4481 8 : }
4482 :
4483 :
4484 :
4485 :
4486 8 : void ScXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>& rProps)
4487 : {
4488 8 : if (GetModel().is())
4489 : {
4490 8 : uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
4491 8 : if (xMultiServiceFactory.is())
4492 : {
4493 8 : uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance("com.sun.star.comp.SpreadsheetSettings"), uno::UNO_QUERY);
4494 8 : if (xProperties.is())
4495 8 : SvXMLUnitConverter::convertPropertySet(rProps, xProperties);
4496 :
4497 8 : sal_Int32 nPropsToAdd = 0;
4498 16 : OUStringBuffer aTrackedChangesKey;
4499 8 : if (GetDocument() && GetDocument()->GetChangeTrack() && GetDocument()->GetChangeTrack()->IsProtected())
4500 : {
4501 : ::sax::Converter::encodeBase64(aTrackedChangesKey,
4502 0 : GetDocument()->GetChangeTrack()->GetProtection());
4503 0 : if (!aTrackedChangesKey.isEmpty())
4504 0 : ++nPropsToAdd;
4505 : }
4506 :
4507 8 : bool bVBACompat = false;
4508 16 : uno::Reference <container::XNameAccess> xCodeNameAccess;
4509 : OSL_ENSURE( pDoc, "ScXMLExport::GetConfigurationSettings - no ScDocument!" );
4510 8 : if( pDoc && pDoc->IsInVBAMode() )
4511 : {
4512 : // VBA compatibility mode
4513 0 : bVBACompat = true;
4514 0 : ++nPropsToAdd;
4515 : // code names
4516 0 : xCodeNameAccess = new XMLCodeNameProvider( pDoc );
4517 0 : if( xCodeNameAccess->hasElements() )
4518 0 : ++nPropsToAdd;
4519 : else
4520 0 : xCodeNameAccess.clear();
4521 : }
4522 :
4523 8 : if( nPropsToAdd > 0 )
4524 : {
4525 0 : sal_Int32 nCount(rProps.getLength());
4526 0 : rProps.realloc(nCount + nPropsToAdd);
4527 0 : if (!aTrackedChangesKey.isEmpty())
4528 : {
4529 0 : rProps[nCount].Name = OUString("TrackedChangesProtectionKey");
4530 0 : rProps[nCount].Value <<= aTrackedChangesKey.makeStringAndClear();
4531 0 : ++nCount;
4532 : }
4533 0 : if( bVBACompat )
4534 : {
4535 0 : rProps[nCount].Name = OUString("VBACompatibilityMode");
4536 0 : rProps[nCount].Value <<= bVBACompat;
4537 0 : ++nCount;
4538 : }
4539 0 : if( xCodeNameAccess.is() )
4540 : {
4541 0 : rProps[nCount].Name = OUString("ScriptConfiguration");
4542 0 : rProps[nCount].Value <<= xCodeNameAccess;
4543 0 : ++nCount;
4544 : }
4545 8 : }
4546 8 : }
4547 : }
4548 8 : }
4549 :
4550 16 : XMLShapeExport* ScXMLExport::CreateShapeExport()
4551 : {
4552 16 : return new ScXMLShapeExport(*this);
4553 : }
4554 :
4555 8 : void ScXMLExport::CreateSharedData(const sal_Int32 nTableCount)
4556 : {
4557 8 : pSharedData = new ScMySharedData(nTableCount);
4558 8 : }
4559 :
4560 420 : XMLNumberFormatAttributesExportHelper* ScXMLExport::GetNumberFormatAttributesExportHelper()
4561 : {
4562 420 : if (!pNumberFormatAttributesExportHelper)
4563 4 : pNumberFormatAttributesExportHelper = new XMLNumberFormatAttributesExportHelper(GetNumberFormatsSupplier(), *this );
4564 420 : return pNumberFormatAttributesExportHelper;
4565 : }
4566 :
4567 93 : void ScXMLExport::CollectUserDefinedNamespaces(const SfxItemPool* pPool, sal_uInt16 nAttrib)
4568 : {
4569 : const SfxPoolItem* pItem;
4570 93 : sal_uInt32 nItems(pPool->GetItemCount2( nAttrib ));
4571 93 : for( sal_uInt32 i = 0; i < nItems; ++i )
4572 : {
4573 0 : if( 0 != (pItem = pPool->GetItem2( nAttrib, i ) ) )
4574 : {
4575 0 : const SvXMLAttrContainerItem *pUnknown((const SvXMLAttrContainerItem *)pItem);
4576 0 : if( (pUnknown->GetAttrCount() > 0) )
4577 : {
4578 0 : sal_uInt16 nIdx(pUnknown->GetFirstNamespaceIndex());
4579 0 : while( USHRT_MAX != nIdx )
4580 : {
4581 0 : if( (XML_NAMESPACE_UNKNOWN_FLAG & nIdx) != 0 )
4582 : {
4583 0 : const OUString& rPrefix = pUnknown->GetPrefix( nIdx );
4584 : // Add namespace declaration for unknown attributes if
4585 : // there aren't existing ones for the prefix used by the
4586 : // attibutes
4587 0 : _GetNamespaceMap().Add( rPrefix,
4588 0 : pUnknown->GetNamespace( nIdx ),
4589 0 : XML_NAMESPACE_UNKNOWN );
4590 : }
4591 0 : nIdx = pUnknown->GetNextNamespaceIndex( nIdx );
4592 : }
4593 : }
4594 : }
4595 : }
4596 :
4597 : // #i66550# needed for 'presentation:event-listener' element for URLs in shapes
4598 93 : _GetNamespaceMap().Add(
4599 93 : GetXMLToken( XML_NP_PRESENTATION ),
4600 93 : GetXMLToken( XML_N_PRESENTATION ),
4601 93 : XML_NAMESPACE_PRESENTATION );
4602 93 : }
4603 :
4604 263 : void ScXMLExport::IncrementProgressBar(bool bEditCell, sal_Int32 nInc)
4605 : {
4606 263 : nProgressCount += nInc;
4607 263 : if (bEditCell || nProgressCount > 100)
4608 : {
4609 9 : GetProgressBarHelper()->Increment(nProgressCount);
4610 9 : nProgressCount = 0;
4611 : }
4612 263 : }
4613 :
4614 28 : sal_uInt32 ScXMLExport::exportDoc( enum XMLTokenEnum eClass )
4615 : {
4616 28 : if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES|
4617 : EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
4618 : {
4619 16 : if (GetDocument())
4620 : {
4621 : // if source doc was Excel then
4622 16 : uno::Reference< frame::XModel > xModel = GetModel();
4623 16 : if ( xModel.is() )
4624 : {
4625 16 : uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY );
4626 16 : SfxObjectShell* pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel.is() ? xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()) : 0 );
4627 16 : if ( pFoundShell && ooo::vba::isAlienExcelDoc( *pFoundShell ) )
4628 : {
4629 0 : xRowStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScFromXLSRowStylesProperties, xScPropHdlFactory);
4630 0 : xRowStylesExportPropertySetMapper = new ScXMLRowExportPropertyMapper(xRowStylesPropertySetMapper);
4631 : GetAutoStylePool()->SetFamilyPropSetMapper( XML_STYLE_FAMILY_TABLE_ROW,
4632 0 : xRowStylesExportPropertySetMapper );
4633 16 : }
4634 : }
4635 16 : CollectUserDefinedNamespaces(GetDocument()->GetPool(), ATTR_USERDEF);
4636 16 : CollectUserDefinedNamespaces(GetDocument()->GetEditPool(), EE_PARA_XMLATTRIBS);
4637 16 : CollectUserDefinedNamespaces(GetDocument()->GetEditPool(), EE_CHAR_XMLATTRIBS);
4638 16 : ScDrawLayer* pDrawLayer = GetDocument()->GetDrawLayer();
4639 16 : if (pDrawLayer)
4640 : {
4641 15 : CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), EE_PARA_XMLATTRIBS);
4642 15 : CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), EE_CHAR_XMLATTRIBS);
4643 15 : CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), SDRATTR_XMLATTRIBUTES);
4644 : }
4645 :
4646 : // sheet events use officeooo namespace
4647 24 : if( (getExportFlags() & EXPORT_CONTENT) != 0 &&
4648 8 : getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
4649 : {
4650 8 : bool bAnySheetEvents = false;
4651 8 : SCTAB nTabCount = pDoc->GetTableCount();
4652 17 : for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
4653 9 : if (pDoc->GetSheetEvents(nTab))
4654 0 : bAnySheetEvents = true;
4655 8 : if (bAnySheetEvents)
4656 0 : _GetNamespaceMap().Add(
4657 0 : GetXMLToken( XML_NP_OFFICE_EXT ),
4658 0 : GetXMLToken( XML_N_OFFICE_EXT ),
4659 0 : XML_NAMESPACE_OFFICE_EXT );
4660 16 : }
4661 : }
4662 : }
4663 28 : return SvXMLExport::exportDoc( eClass );
4664 : }
4665 :
4666 : // XExporter
4667 37 : void SAL_CALL ScXMLExport::setSourceDocument( const uno::Reference<lang::XComponent>& xComponent )
4668 : throw(lang::IllegalArgumentException, uno::RuntimeException)
4669 : {
4670 37 : SolarMutexGuard aGuard;
4671 37 : SvXMLExport::setSourceDocument( xComponent );
4672 :
4673 37 : pDoc = ScXMLConverter::GetScDocument( GetModel() );
4674 : OSL_ENSURE( pDoc, "ScXMLExport::setSourceDocument - no ScDocument!" );
4675 37 : if (!pDoc)
4676 0 : throw lang::IllegalArgumentException();
4677 :
4678 : // create ScChangeTrackingExportHelper after document is known
4679 37 : pChangeTrackingExportHelper = new ScChangeTrackingExportHelper(*this);
4680 :
4681 : // Set the document's storage grammar corresponding to the ODF version that
4682 : // is to be written.
4683 37 : SvtSaveOptions::ODFDefaultVersion meODFDefaultVersion = getDefaultVersion();
4684 37 : switch (meODFDefaultVersion)
4685 : {
4686 : // ODF 1.0 and 1.1 use GRAM_PODF, everything later or unspecified GRAM_ODFF
4687 : case SvtSaveOptions::ODFVER_010:
4688 : case SvtSaveOptions::ODFVER_011:
4689 0 : pDoc->SetStorageGrammar( formula::FormulaGrammar::GRAM_PODF);
4690 0 : break;
4691 : default:
4692 37 : pDoc->SetStorageGrammar( formula::FormulaGrammar::GRAM_ODFF);
4693 37 : }
4694 37 : }
4695 :
4696 : // XFilter
4697 28 : sal_Bool SAL_CALL ScXMLExport::filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
4698 : throw(::com::sun::star::uno::RuntimeException)
4699 : {
4700 28 : SolarMutexGuard aGuard;
4701 28 : if (pDoc)
4702 28 : pDoc->EnableIdle(false);
4703 28 : bool bReturn(SvXMLExport::filter(aDescriptor));
4704 28 : if (pDoc)
4705 28 : pDoc->EnableIdle(true);
4706 28 : return bReturn;
4707 : }
4708 :
4709 0 : void SAL_CALL ScXMLExport::cancel()
4710 : throw(::com::sun::star::uno::RuntimeException)
4711 : {
4712 0 : SolarMutexGuard aGuard;
4713 0 : if (pDoc)
4714 0 : pDoc->EnableIdle(true);
4715 0 : SvXMLExport::cancel();
4716 0 : }
4717 :
4718 : // XInitialization
4719 37 : void SAL_CALL ScXMLExport::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
4720 : throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
4721 : {
4722 37 : SolarMutexGuard aGuard;
4723 37 : SvXMLExport::initialize(aArguments);
4724 37 : }
4725 :
4726 : // XServiceInfo
4727 0 : OUString SAL_CALL ScXMLExport::getImplementationName( )
4728 : throw(::com::sun::star::uno::RuntimeException)
4729 : {
4730 0 : SolarMutexGuard aGuard;
4731 :
4732 0 : sal_uInt16 nFlags = getExportFlags();
4733 0 : if (nFlags & EXPORT_OASIS)
4734 : {
4735 0 : nFlags |= EXPORT_OASIS;
4736 0 : switch( nFlags )
4737 : {
4738 : case EXPORT_ALL:
4739 0 : return ScXMLOasisExport_getImplementationName();
4740 : case (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS):
4741 0 : return ScXMLOasisExport_Styles_getImplementationName();
4742 : case (EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS):
4743 0 : return ScXMLOasisExport_Content_getImplementationName();
4744 : case EXPORT_META:
4745 0 : return ScXMLOasisExport_Meta_getImplementationName();
4746 : case EXPORT_SETTINGS:
4747 0 : return ScXMLOasisExport_Settings_getImplementationName();
4748 : default:
4749 : // generic name for 'unknown' cases
4750 0 : return ScXMLOasisExport_getImplementationName();
4751 : }
4752 : }
4753 : else
4754 : {
4755 0 : switch( nFlags )
4756 : {
4757 : case EXPORT_ALL:
4758 0 : return ScXMLOOoExport_getImplementationName();
4759 : case (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS):
4760 0 : return ScXMLOOoExport_Styles_getImplementationName();
4761 : case (EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS):
4762 0 : return ScXMLOOoExport_Content_getImplementationName();
4763 : case EXPORT_META:
4764 0 : return ScXMLOOoExport_Meta_getImplementationName();
4765 : case EXPORT_SETTINGS:
4766 0 : return ScXMLOOoExport_Settings_getImplementationName();
4767 : default:
4768 : // generic name for 'unknown' cases
4769 0 : return ScXMLOOoExport_getImplementationName();
4770 : }
4771 0 : }
4772 : }
4773 :
4774 0 : sal_Bool SAL_CALL ScXMLExport::supportsService( const OUString& ServiceName )
4775 : throw(::com::sun::star::uno::RuntimeException)
4776 : {
4777 0 : SolarMutexGuard aGuard;
4778 0 : return SvXMLExport::supportsService( ServiceName );
4779 : }
4780 :
4781 0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL ScXMLExport::getSupportedServiceNames( )
4782 : throw(::com::sun::star::uno::RuntimeException)
4783 : {
4784 0 : SolarMutexGuard aGuard;
4785 0 : return SvXMLExport::getSupportedServiceNames();
4786 : }
4787 :
4788 : // XUnoTunnel
4789 28 : sal_Int64 SAL_CALL ScXMLExport::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
4790 : throw(::com::sun::star::uno::RuntimeException)
4791 : {
4792 28 : SolarMutexGuard aGuard;
4793 28 : return SvXMLExport::getSomething(aIdentifier);
4794 : }
4795 :
4796 6 : void ScXMLExport::DisposingModel()
4797 : {
4798 6 : SvXMLExport::DisposingModel();
4799 6 : pDoc = NULL;
4800 6 : xCurrentTable = 0;
4801 99 : }
4802 :
4803 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|