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