merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / xml / xmlexprt.cxx
blob42d38147ed32f39c58bc09ef194c29d1eb6c78fc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlexprt.cxx,v $
10 * $Revision: 1.213.94.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
36 #include <svx/eeitem.hxx>
38 #include "xmlexprt.hxx"
39 #include "XMLConverter.hxx"
40 #include "xmlstyle.hxx"
41 #include "unonames.hxx"
42 #include "document.hxx"
43 #include "olinetab.hxx"
44 #include "cellsuno.hxx"
45 #include "cell.hxx"
46 #include "rangenam.hxx"
47 #include "XMLTableMasterPageExport.hxx"
48 #include "drwlayer.hxx"
49 #include "XMLExportDataPilot.hxx"
50 #include "XMLExportDatabaseRanges.hxx"
51 #include "XMLExportDDELinks.hxx"
52 #include "XMLExportIterator.hxx"
53 #include "XMLColumnRowGroupExport.hxx"
54 #include "XMLStylesExportHelper.hxx"
55 #include "XMLChangeTrackingExportHelper.hxx"
56 #include "sheetdata.hxx"
57 #include "docoptio.hxx"
58 #include "XMLExportSharedData.hxx"
59 #include "chgviset.hxx"
60 #include "docuno.hxx"
61 #include "textuno.hxx"
62 #include "chartlis.hxx"
63 #include "unoguard.hxx"
64 #include "scitems.hxx"
65 #include "docpool.hxx"
66 #include "userdat.hxx"
67 #include "dociter.hxx"
68 #include "chgtrack.hxx"
69 #include "rangeutl.hxx"
70 #include "convuno.hxx"
71 #include "postit.hxx"
72 #include "externalrefmgr.hxx"
73 #include "editutil.hxx"
74 #include "tabprotection.hxx"
76 #include <xmloff/xmltoken.hxx>
77 #include <xmloff/xmlnmspe.hxx>
78 #include <xmloff/xmluconv.hxx>
79 #include <xmloff/nmspmap.hxx>
80 #include <xmloff/families.hxx>
81 #include <xmloff/numehelp.hxx>
82 #include <xmloff/xmluconv.hxx>
83 #include <xmloff/txtparae.hxx>
84 #include <xmloff/xmlcnitm.hxx>
85 #include <xmloff/xmlerror.hxx>
87 #include <rtl/ustring.hxx>
89 #include <tools/debug.hxx>
90 #include <rtl/math.hxx>
91 #include <svtools/zforlist.hxx>
92 #include <svx/unoshape.hxx>
93 #include <comphelper/extract.hxx>
94 #include <svx/eeitem.hxx>
95 #include <toolkit/helper/convert.hxx>
96 #include <svx/svdobj.hxx>
97 #include <svx/svdocapt.hxx>
98 #include <svx/outlobj.hxx>
99 #include <svx/svditer.hxx>
100 #include <svx/svdpage.hxx>
102 #include <comphelper/processfactory.hxx>
103 #include <com/sun/star/sheet/XUsedAreaCursor.hpp>
104 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
105 #include <com/sun/star/sheet/XAreaLinks.hpp>
106 #include <com/sun/star/sheet/XAreaLink.hpp>
107 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
108 #include <com/sun/star/table/XColumnRowRange.hpp>
109 #include <com/sun/star/sheet/XPrintAreas.hpp>
110 #include <com/sun/star/container/XNamed.hpp>
111 #include <com/sun/star/util/XProtectable.hpp>
112 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
113 #include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp>
114 #include <com/sun/star/sheet/XCellRangesQuery.hpp>
115 #include <com/sun/star/sheet/CellFlags.hpp>
116 #include <com/sun/star/util/XMergeable.hpp>
117 #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
118 #include <com/sun/star/text/XText.hpp>
119 #include <com/sun/star/sheet/XLabelRanges.hpp>
120 #include <com/sun/star/sheet/XLabelRange.hpp>
121 #include <com/sun/star/sheet/XNamedRanges.hpp>
122 #include <com/sun/star/sheet/XNamedRange.hpp>
123 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
124 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
125 #include <com/sun/star/container/XNamed.hpp>
126 #include <com/sun/star/sheet/XSheetLinkable.hpp>
127 #include <com/sun/star/form/XFormsSupplier2.hpp>
128 #include <com/sun/star/io/XActiveDataSource.hpp>
129 #include <com/sun/star/io/XSeekable.hpp>
131 #include <com/sun/star/chart2/XChartDocument.hpp>
132 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
133 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
135 #include <com/sun/star/document/XDocumentProperties.hpp>
136 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
138 #include <sfx2/objsh.hxx>
140 #include <vector>
142 //! not found in unonames.hxx
143 #define SC_STANDARDFORMAT "StandardFormat"
144 #define SC_LAYERID "LayerID"
146 #define SC_DEFAULT_TABLE_COUNT 3
147 #define SC_VIEWCHANGES_COUNT 13
148 #define SC_SHOW_CHANGES 0
149 #define SC_SHOW_ACCEPTED_CHANGES 1
150 #define SC_SHOW_REJECTED_CHANGES 2
151 #define SC_SHOW_CHANGES_BY_DATETIME 3
152 #define SC_SHOW_CHANGES_BY_DATETIME_MODE 4
153 #define SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME 5
154 #define SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME 6
155 #define SC_SHOW_CHANGES_BY_AUTHOR 7
156 #define SC_SHOW_CHANGES_BY_AUTHOR_NAME 8
157 #define SC_SHOW_CHANGES_BY_COMMENT 9
158 #define SC_SHOW_CHANGES_BY_COMMENT_TEXT 10
159 #define SC_SHOW_CHANGES_BY_RANGES 11
160 #define SC_SHOW_CHANGES_BY_RANGES_LIST 12
162 using namespace rtl;
163 using namespace formula;
164 using namespace com::sun::star;
165 using namespace xmloff::token;
166 using ::std::vector;
168 //----------------------------------------------------------------------------
170 namespace
172 OUString lcl_RangeSequenceToString(
173 const uno::Sequence< OUString > & rRanges,
174 const uno::Reference< chart2::data::XRangeXMLConversion > & xFormatConverter )
176 OUStringBuffer aResult;
177 const sal_Int32 nMaxIndex( rRanges.getLength() - 1 );
178 const sal_Unicode cSep( sal_Char(' '));
179 for( sal_Int32 i=0; i<=nMaxIndex; ++i )
181 OUString aRange( rRanges[i] );
182 if( xFormatConverter.is())
183 aRange = xFormatConverter->convertRangeToXML( aRange );
184 aResult.append( aRange );
185 if( i < nMaxIndex )
186 aResult.append( cSep );
188 return aResult.makeStringAndClear();
191 OUString lcl_GetRawString( ScDocument* pDoc, const ScAddress& rPos )
193 // return text/edit cell string content, with line feeds in edit cells
195 String aVal; // document uses tools-strings
196 if (pDoc)
198 ScBaseCell* pCell = pDoc->GetCell( rPos );
199 if (pCell)
201 CellType eType = pCell->GetCellType();
202 if ( eType == CELLTYPE_STRING )
203 static_cast<ScStringCell*>(pCell)->GetString(aVal); // string cell: content
204 else if ( eType == CELLTYPE_EDIT )
206 // edit cell: text with line breaks
207 const EditTextObject* pData = static_cast<ScEditCell*>(pCell)->GetData();
208 if (pData)
210 EditEngine& rEngine = pDoc->GetEditEngine();
211 rEngine.SetText( *pData );
212 aVal = rEngine.GetText( LINEEND_LF );
217 return aVal;
219 } // anonymous namespace
221 //----------------------------------------------------------------------------
223 OUString SAL_CALL ScXMLOOoExport_getImplementationName() throw()
225 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLExporter" ) );
228 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOOoExport_getSupportedServiceNames() throw()
230 const rtl::OUString aServiceName( ScXMLOOoExport_getImplementationName() );
231 return uno::Sequence< rtl::OUString >( &aServiceName, 1 );
234 uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_createInstance(
235 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
237 // #110680#
238 // return (cppu::OWeakObject*)new ScXMLExport(EXPORT_ALL);
239 return (cppu::OWeakObject*)new ScXMLExport( rSMgr, EXPORT_ALL );
242 OUString SAL_CALL ScXMLOOoExport_Meta_getImplementationName() throw()
244 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLMetaExporter" ) );
247 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOOoExport_Meta_getSupportedServiceNames() throw()
249 const rtl::OUString aServiceName( ScXMLOOoExport_Meta_getImplementationName() );
250 return uno::Sequence< rtl::OUString > ( &aServiceName, 1 );
253 uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Meta_createInstance(
254 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
256 // #110680#
257 // return (cppu::OWeakObject*)new ScXMLExport(EXPORT_META);
258 return (cppu::OWeakObject*)new ScXMLExport( rSMgr, EXPORT_META );
261 OUString SAL_CALL ScXMLOOoExport_Styles_getImplementationName() throw()
263 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLStylesExporter" ) );
266 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOOoExport_Styles_getSupportedServiceNames() throw()
268 const rtl::OUString aServiceName( ScXMLOOoExport_Styles_getImplementationName() );
269 return uno::Sequence< rtl::OUString > ( &aServiceName, 1 );
272 uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Styles_createInstance(
273 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
275 // #110680#
276 // return (cppu::OWeakObject*)new ScXMLExport(EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS);
277 return (cppu::OWeakObject*)new ScXMLExport( rSMgr, EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS);
280 OUString SAL_CALL ScXMLOOoExport_Content_getImplementationName() throw()
282 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLContentExporter" ) );
285 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOOoExport_Content_getSupportedServiceNames() throw()
287 const rtl::OUString aServiceName( ScXMLOOoExport_Content_getImplementationName() );
288 return uno::Sequence< rtl::OUString > ( &aServiceName, 1 );
291 uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Content_createInstance(
292 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
294 // #110680#
295 // return (cppu::OWeakObject*)new ScXMLExport(EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS);
296 return (cppu::OWeakObject*)new ScXMLExport( rSMgr, EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS);
299 OUString SAL_CALL ScXMLOOoExport_Settings_getImplementationName() throw()
301 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLSettingsExporter" ) );
304 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOOoExport_Settings_getSupportedServiceNames() throw()
306 const rtl::OUString aServiceName( ScXMLOOoExport_Settings_getImplementationName() );
307 return uno::Sequence< rtl::OUString > ( &aServiceName, 1 );
310 uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Settings_createInstance(
311 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
313 // #110680#
314 // return (cppu::OWeakObject*)new ScXMLExport(EXPORT_SETTINGS);
315 return (cppu::OWeakObject*)new ScXMLExport( rSMgr, EXPORT_SETTINGS );
318 // Oasis Filter
320 OUString SAL_CALL ScXMLOasisExport_getImplementationName() throw()
322 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLOasisExporter" ) );
325 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOasisExport_getSupportedServiceNames() throw()
327 const rtl::OUString aServiceName( ScXMLOasisExport_getImplementationName() );
328 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
329 return aSeq;
332 uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_createInstance(
333 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
335 return (cppu::OWeakObject*)new ScXMLExport(rSMgr, EXPORT_ALL|EXPORT_OASIS);
338 OUString SAL_CALL ScXMLOasisExport_Meta_getImplementationName() throw()
340 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLOasisMetaExporter" ) );
343 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOasisExport_Meta_getSupportedServiceNames() throw()
345 const rtl::OUString aServiceName( ScXMLOasisExport_Meta_getImplementationName() );
346 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
347 return aSeq;
350 uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Meta_createInstance(
351 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
353 return (cppu::OWeakObject*)new ScXMLExport(rSMgr, EXPORT_META|EXPORT_OASIS);
356 OUString SAL_CALL ScXMLOasisExport_Styles_getImplementationName() throw()
358 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLOasisStylesExporter" ) );
361 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOasisExport_Styles_getSupportedServiceNames() throw()
363 const rtl::OUString aServiceName( ScXMLOasisExport_Styles_getImplementationName() );
364 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
365 return aSeq;
368 uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Styles_createInstance(
369 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
371 return (cppu::OWeakObject*)new ScXMLExport(rSMgr, EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS|EXPORT_OASIS);
374 OUString SAL_CALL ScXMLOasisExport_Content_getImplementationName() throw()
376 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLOasisContentExporter" ) );
379 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOasisExport_Content_getSupportedServiceNames() throw()
381 const rtl::OUString aServiceName( ScXMLOasisExport_Content_getImplementationName() );
382 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
383 return aSeq;
386 uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Content_createInstance(
387 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
389 return (cppu::OWeakObject*)new ScXMLExport(rSMgr, EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS|EXPORT_OASIS);
392 OUString SAL_CALL ScXMLOasisExport_Settings_getImplementationName() throw()
394 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.XMLOasisSettingsExporter" ) );
397 uno::Sequence< rtl::OUString > SAL_CALL ScXMLOasisExport_Settings_getSupportedServiceNames() throw()
399 const rtl::OUString aServiceName( ScXMLOasisExport_Settings_getImplementationName() );
400 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
401 return aSeq;
404 uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Settings_createInstance(
405 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
407 return (cppu::OWeakObject*)new ScXMLExport(rSMgr, EXPORT_SETTINGS|EXPORT_OASIS);
409 //----------------------------------------------------------------------------
411 class ScXMLShapeExport : public XMLShapeExport
413 public:
414 ScXMLShapeExport(SvXMLExport& rExp) : XMLShapeExport(rExp) {}
415 ~ScXMLShapeExport();
417 /** is called before a shape element for the given XShape is exported */
418 virtual void onExport( const uno::Reference < drawing::XShape >& xShape );
421 ScXMLShapeExport::~ScXMLShapeExport()
425 void ScXMLShapeExport::onExport( const uno::Reference < drawing::XShape >& xShape )
427 uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
428 if( xShapeProp.is() )
430 sal_Int16 nLayerID = 0;
431 if( (xShapeProp->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_LAYERID ))) >>= nLayerID) && (nLayerID == SC_LAYER_BACK) )
432 GetExport().AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_BACKGROUND, XML_TRUE);
436 //----------------------------------------------------------------------------
438 sal_Int16 ScXMLExport::GetFieldUnit()
440 com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> xProperties(
441 comphelper::getProcessServiceFactory()->createInstance(
442 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" )) ),
443 com::sun::star::uno::UNO_QUERY);
444 if (xProperties.is())
446 sal_Int16 nFieldUnit = 0;
447 if (xProperties->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Metric"))) >>= nFieldUnit)
448 return nFieldUnit;
450 return 0;
454 // #110680#
455 ScXMLExport::ScXMLExport(
456 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
457 const sal_uInt16 nExportFlag)
458 : SvXMLExport( xServiceFactory, SvXMLUnitConverter::GetMapUnit(GetFieldUnit()), XML_SPREADSHEET, nExportFlag ),
459 pDoc(NULL),
460 nSourceStreamPos(0),
461 pNumberFormatAttributesExportHelper(NULL),
462 pSharedData(NULL),
463 pColumnStyles(NULL),
464 pRowStyles(NULL),
465 pCellStyles(NULL),
466 pRowFormatRanges(NULL),
467 aTableStyles(),
468 pGroupColumns (NULL),
469 pGroupRows (NULL),
470 pDefaults(NULL),
471 pChartListener(NULL),
472 pCurrentCell(NULL),
473 pMergedRangesContainer(NULL),
474 pValidationsContainer(NULL),
475 pCellsItr(NULL),
476 pChangeTrackingExportHelper(NULL),
477 sLayerID(RTL_CONSTASCII_USTRINGPARAM( SC_LAYERID )),
478 sCaptionShape(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.CaptionShape")),
479 nOpenRow(-1),
480 nProgressCount(0),
481 nCurrentTable(0),
482 bHasRowHeader(sal_False),
483 bRowHeaderOpen(sal_False),
484 mbShowProgress( sal_False )
486 if (getExportFlags() & EXPORT_CONTENT)
488 pGroupColumns = new ScMyOpenCloseColumnRowGroup(*this, XML_TABLE_COLUMN_GROUP);
489 pGroupRows = new ScMyOpenCloseColumnRowGroup(*this, XML_TABLE_ROW_GROUP);
490 pColumnStyles = new ScColumnStyles();
491 pRowStyles = new ScRowStyles();
492 pRowFormatRanges = new ScRowFormatRanges();
493 pMergedRangesContainer = new ScMyMergedRangesContainer();
494 pValidationsContainer = new ScMyValidationsContainer();
495 pCellsItr = new ScMyNotEmptyCellsIterator(*this);
496 pDefaults = new ScMyDefaultStyles();
498 pCellStyles = new ScFormatRangeStyles();
500 // document is not set here - create ScChangeTrackingExportHelper later
502 xScPropHdlFactory = new XMLScPropHdlFactory;
503 xCellStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScCellStylesProperties, xScPropHdlFactory);
504 xColumnStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScColumnStylesProperties, xScPropHdlFactory);
505 xRowStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScRowStylesProperties, xScPropHdlFactory);
506 xTableStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScTableStylesProperties, xScPropHdlFactory);
507 xCellStylesExportPropertySetMapper = new ScXMLCellExportPropertyMapper(xCellStylesPropertySetMapper);
508 xCellStylesExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(*this));
509 xColumnStylesExportPropertySetMapper = new ScXMLColumnExportPropertyMapper(xColumnStylesPropertySetMapper);
510 xRowStylesExportPropertySetMapper = new ScXMLRowExportPropertyMapper(xRowStylesPropertySetMapper);
511 xTableStylesExportPropertySetMapper = new ScXMLTableExportPropertyMapper(xTableStylesPropertySetMapper);
513 GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_CELL, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME)),
514 xCellStylesExportPropertySetMapper, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX)));
515 GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_COLUMN, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME)),
516 xColumnStylesExportPropertySetMapper, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX)));
517 GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_ROW, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME)),
518 xRowStylesExportPropertySetMapper, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX)));
519 GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_TABLE, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME)),
520 xTableStylesExportPropertySetMapper, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX)));
522 if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
524 // This name is reserved for the external ref cache tables. This
525 // should not conflict with user-defined styles since this name is
526 // used for a table style which is not available in the UI.
527 sExternalRefTabStyleName = rtl::OUString::createFromAscii("ta_extref");
528 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_TABLE, sExternalRefTabStyleName);
530 sAttrName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_NAME));
531 sAttrStyleName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_STYLE_NAME));
532 sAttrColumnsRepeated = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_NUMBER_COLUMNS_REPEATED));
533 sAttrFormula = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_FORMULA));
534 sAttrStringValue = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_STRING_VALUE));
535 sAttrValueType = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE_TYPE));
536 sElemCell = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_CELL));
537 sElemCoveredCell = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_COVERED_TABLE_CELL));
538 sElemCol = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_COLUMN));
539 sElemRow = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_ROW));
540 sElemTab = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE));
541 sElemP = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TEXT, GetXMLToken(XML_P));
546 ScXMLExport::~ScXMLExport()
548 if (pGroupColumns)
549 delete pGroupColumns;
550 if (pGroupRows)
551 delete pGroupRows;
552 if (pColumnStyles)
553 delete pColumnStyles;
554 if (pRowStyles)
555 delete pRowStyles;
556 if (pCellStyles)
557 delete pCellStyles;
558 if (pRowFormatRanges)
559 delete pRowFormatRanges;
560 if (pMergedRangesContainer)
561 delete pMergedRangesContainer;
562 if (pValidationsContainer)
563 delete pValidationsContainer;
564 if (pChangeTrackingExportHelper)
565 delete pChangeTrackingExportHelper;
566 if (pChartListener)
567 delete pChartListener;
568 if (pCellsItr)
569 delete pCellsItr;
570 if (pDefaults)
571 delete pDefaults;
572 if (pNumberFormatAttributesExportHelper)
573 delete pNumberFormatAttributesExportHelper;
576 void ScXMLExport::SetSourceStream( const uno::Reference<io::XInputStream>& xNewStream )
578 xSourceStream = xNewStream;
580 if ( xSourceStream.is() )
582 // make sure it's a plain UTF-8 stream as written by OOo itself
584 const sal_Char pXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
585 sal_Int32 nLen = strlen(pXmlHeader);
587 uno::Sequence<sal_Int8> aFileStart(nLen);
588 sal_Int32 nRead = xSourceStream->readBytes( aFileStart, nLen );
590 if ( nRead != nLen || rtl_compareMemory( aFileStart.getConstArray(), pXmlHeader, nLen ) != 0 )
592 // invalid - ignore stream, save normally
593 xSourceStream.clear();
595 else
597 // keep track of the bytes already read
598 nSourceStreamPos = nRead;
600 const ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetModel())->GetSheetSaveData();
601 if (pSheetData)
603 // add the loaded namespaces to the name space map
605 if ( !pSheetData->AddLoadedNamespaces( _GetNamespaceMap() ) )
607 // conflicts in the namespaces - ignore the stream, save normally
608 xSourceStream.clear();
615 sal_Int32 ScXMLExport::GetNumberFormatStyleIndex(sal_Int32 nNumFmt) const
617 NumberFormatIndexMap::const_iterator itr = aNumFmtIndexMap.find(nNumFmt);
618 if (itr == aNumFmtIndexMap.end())
619 return -1;
621 return itr->second;
624 sal_Bool ScXMLExport::HasDrawPages(uno::Reference <sheet::XSpreadsheetDocument>& xDoc)
626 uno::Reference <beans::XPropertySet> xDocProps( xDoc, uno::UNO_QUERY );
627 return (xDocProps.is() && ::cppu::any2bool( xDocProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_HASDRAWPAGES))) ));
630 void ScXMLExport::CollectSharedData(sal_Int32& nTableCount, sal_Int32& nShapesCount, const sal_Int32 nCellCount)
632 if (GetModel().is())
634 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
635 if ( xSpreadDoc.is())
637 uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
638 if ( xIndex.is() )
640 nTableCount = xIndex->getCount();
641 if (!pSharedData)
642 CreateSharedData(nTableCount);
643 pCellStyles->AddNewTable(nTableCount - 1);
644 pDoc->InitializeAllNoteCaptions( true );
645 if (HasDrawPages(xSpreadDoc))
647 rtl::OUString sCaptionPoint( RTL_CONSTASCII_USTRINGPARAM( "CaptionPoint" ));
648 for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
650 nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
651 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIndex->getByIndex(nTable), uno::UNO_QUERY);
652 if (xDrawPageSupplier.is())
654 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage());
655 ScMyDrawPage aDrawPage;
656 aDrawPage.bHasForms = sal_False;
657 aDrawPage.xDrawPage.set(xDrawPage);
658 pSharedData->AddDrawPage(aDrawPage, nTable);
659 uno::Reference<container::XIndexAccess> xShapesIndex (xDrawPage, uno::UNO_QUERY);
660 if (xShapesIndex.is())
662 sal_Int32 nShapes(xShapesIndex->getCount());
663 for (sal_Int32 nShape = 0; nShape < nShapes; ++nShape)
665 uno::Reference<drawing::XShape> xShape(xShapesIndex->getByIndex(nShape), uno::UNO_QUERY);
666 if (xShape.is())
668 uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
669 if( xShapeProp.is() )
671 sal_Int16 nLayerID = 0;
672 if( xShapeProp->getPropertyValue(sLayerID) >>= nLayerID )
674 if( (nLayerID == SC_LAYER_INTERN) || (nLayerID == SC_LAYER_HIDDEN) )
675 CollectInternalShape( xShape );
676 else
678 ++nShapesCount;
679 SvxShape* pShapeImp(SvxShape::getImplementation(xShape));
680 if (pShapeImp)
682 SdrObject *pSdrObj(pShapeImp->GetSdrObject());
683 if (pSdrObj)
685 if (ScDrawLayer::GetAnchor(pSdrObj) == SCA_CELL)
687 if (pDoc)
690 awt::Point aPoint(xShape->getPosition());
691 awt::Size aSize(xShape->getSize());
692 rtl::OUString sType(xShape->getShapeType());
693 Rectangle aRectangle(aPoint.X, aPoint.Y, aPoint.X + aSize.Width, aPoint.Y + aSize.Height);
694 if ( sType.equals(sCaptionShape) )
696 awt::Point aRelativeCaptionPoint;
697 xShapeProp->getPropertyValue( sCaptionPoint ) >>= aRelativeCaptionPoint;
698 Point aCoreRelativeCaptionPoint(aRelativeCaptionPoint.X, aRelativeCaptionPoint.Y);
699 Point aCoreAbsoluteCaptionPoint(aPoint.X, aPoint.Y);
700 aCoreAbsoluteCaptionPoint += aCoreRelativeCaptionPoint;
701 aRectangle.Union(Rectangle(aCoreAbsoluteCaptionPoint, aCoreAbsoluteCaptionPoint));
703 ScRange aRange(pDoc->GetRange(static_cast<SCTAB>(nTable), aRectangle));
704 ScMyShape aMyShape;
705 aMyShape.aAddress = aRange.aStart;
706 aMyShape.aEndAddress = aRange.aEnd;
707 aMyShape.xShape = xShape;
708 pSharedData->AddNewShape(aMyShape);
709 pSharedData->SetLastColumn(nTable, aRange.aStart.Col());
710 pSharedData->SetLastRow(nTable, aRange.aStart.Row());
713 else
714 pSharedData->AddTableShape(nTable, xShape);
729 sal_Int32 nRef(nCellCount + (2 * nTableCount) + (2 * nShapesCount));
730 GetProgressBarHelper()->SetReference(nRef);
731 GetProgressBarHelper()->SetValue(0);
734 void ScXMLExport::CollectShapesAutoStyles(const sal_Int32 nTableCount)
736 // #i84077# To avoid compiler warnings about uninitialized aShapeItr,
737 // it's initialized using this dummy list. The iterator contains shapes
738 // from all sheets, so it can't be declared inside the nTable loop where
739 // it is used.
740 ScMyShapeList aDummyInitList;
742 pSharedData->SortShapesContainer();
743 pSharedData->SortNoteShapes();
744 const ScMyShapeList* pShapeList(NULL);
745 ScMyShapeList::const_iterator aShapeItr = aDummyInitList.end();
746 if (pSharedData->GetShapesContainer())
748 pShapeList = pSharedData->GetShapesContainer()->GetShapes();
749 aShapeItr = pShapeList->begin();
751 if (pSharedData->HasDrawPage())
753 for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
755 uno::Reference<drawing::XDrawPage> xDrawPage(pSharedData->GetDrawPage(nTable));
756 uno::Reference<drawing::XShapes> xShapes (xDrawPage, uno::UNO_QUERY);
758 if (xShapes.is())
760 GetShapeExport()->seekShapes(xShapes);
761 uno::Reference< form::XFormsSupplier2 > xFormsSupplier( xDrawPage, uno::UNO_QUERY );
762 if( xFormsSupplier.is() && xFormsSupplier->hasForms() )
764 GetFormExport()->examineForms(xDrawPage);
765 pSharedData->SetDrawPageHasForms(nTable, sal_True);
767 ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
768 if (pTableShapes)
770 ScMyTableXShapes::iterator aItr((*pTableShapes)[nTable].begin());
771 ScMyTableXShapes::iterator aEndItr((*pTableShapes)[nTable].end());
772 while (aItr != aEndItr)
774 GetShapeExport()->collectShapeAutoStyles(*aItr);
775 IncrementProgressBar(sal_False);
776 ++aItr;
779 if (pShapeList)
781 ScMyShapeList::const_iterator aEndItr(pShapeList->end());
782 while (aShapeItr != aEndItr && (static_cast<sal_Int32>(aShapeItr->aAddress.Tab()) == nTable))
784 GetShapeExport()->collectShapeAutoStyles(aShapeItr->xShape);
785 IncrementProgressBar(sal_False);
786 ++aShapeItr;
789 const ScMyNoteShapeList* pNoteShapes = NULL;
790 ScMyNoteShapeList::const_iterator aNoteShapeItr;
791 ScMyNoteShapeList::const_iterator aNoteShapeEndItr;
792 if (pSharedData->GetNoteShapes())
794 pNoteShapes = pSharedData->GetNoteShapes()->GetNotes();
795 if (pNoteShapes)
797 aNoteShapeItr = pNoteShapes->begin();
798 aNoteShapeEndItr = pNoteShapes->end();
801 if (pNoteShapes)
803 while (aNoteShapeItr != aNoteShapeEndItr)
805 if (static_cast<sal_Int32>(aNoteShapeItr->aPos.Tab()) == nTable)
806 GetShapeExport()->collectShapeAutoStyles(aNoteShapeItr->xShape);
807 ++aNoteShapeItr;
813 pSharedData->SortNoteShapes(); // sort twice, because some more shapes are added
816 void ScXMLExport::_ExportMeta()
818 sal_Int32 nCellCount(pDoc ? pDoc->GetCellCount() : 0);
819 sal_Int32 nTableCount(0);
820 sal_Int32 nShapesCount(0);
821 GetAutoStylePool()->ClearEntries();
822 CollectSharedData(nTableCount, nShapesCount, nCellCount);
824 uno::Sequence<beans::NamedValue> stats(3);
825 stats[0] = beans::NamedValue(::rtl::OUString::createFromAscii("TableCount"),
826 uno::makeAny(nTableCount));
827 stats[1] = beans::NamedValue(::rtl::OUString::createFromAscii("CellCount"),
828 uno::makeAny(nCellCount));
829 stats[2] = beans::NamedValue(::rtl::OUString::createFromAscii("ObjectCount"),
830 uno::makeAny(nShapesCount));
832 // update document statistics at the model
833 uno::Reference<document::XDocumentPropertiesSupplier> xPropSup(GetModel(),
834 uno::UNO_QUERY_THROW);
835 uno::Reference<document::XDocumentProperties> xDocProps(
836 xPropSup->getDocumentProperties());
837 if (xDocProps.is()) {
838 xDocProps->setDocumentStatistics(stats);
841 // export document properties
842 SvXMLExport::_ExportMeta();
845 void ScXMLExport::_ExportFontDecls()
847 GetFontAutoStylePool(); // make sure the pool is created
848 SvXMLExport::_ExportFontDecls();
851 table::CellRangeAddress ScXMLExport::GetEndAddress(const uno::Reference<sheet::XSpreadsheet>& xTable, const sal_Int32 /* nTable */)
853 table::CellRangeAddress aCellAddress;
854 uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursor());
855 uno::Reference<sheet::XUsedAreaCursor> xUsedArea (xCursor, uno::UNO_QUERY);
856 uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
857 if (xUsedArea.is() && xCellAddress.is())
859 xUsedArea->gotoEndOfUsedArea(sal_True);
860 aCellAddress = xCellAddress->getRangeAddress();
862 return aCellAddress;
865 void ScXMLExport::GetAreaLinks( uno::Reference< sheet::XSpreadsheetDocument>& xSpreadDoc,
866 ScMyAreaLinksContainer& rAreaLinks )
868 uno::Reference< beans::XPropertySet > xPropSet( xSpreadDoc, uno::UNO_QUERY );
869 if( !xPropSet.is() ) return;
871 uno::Reference< container::XIndexAccess > xLinksIAccess( xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_AREALINKS ) ) ), uno::UNO_QUERY);
872 if( xLinksIAccess.is() )
874 const OUString sFilter( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FILTER ) );
875 const OUString sFilterOpt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FILTOPT ) );
876 const OUString sURL( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_LINKURL ) );
877 const OUString sRefresh( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_REFDELAY ) );
879 sal_Int32 nCount(xLinksIAccess->getCount());
880 for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
882 uno::Reference< sheet::XAreaLink > xAreaLink(xLinksIAccess->getByIndex( nIndex ), uno::UNO_QUERY);
883 if( xAreaLink.is() )
885 ScMyAreaLink aAreaLink;
886 aAreaLink.aDestRange = xAreaLink->getDestArea();
887 aAreaLink.sSourceStr = xAreaLink->getSourceArea();
888 uno::Reference< beans::XPropertySet > xLinkProp( xAreaLink, uno::UNO_QUERY );
889 if( xLinkProp.is() )
891 xLinkProp->getPropertyValue( sFilter ) >>= aAreaLink.sFilter;
892 xLinkProp->getPropertyValue( sFilterOpt ) >>= aAreaLink.sFilterOptions;
893 xLinkProp->getPropertyValue( sURL ) >>= aAreaLink.sURL;
894 xLinkProp->getPropertyValue( sRefresh ) >>= aAreaLink.nRefresh;
896 rAreaLinks.AddNewAreaLink( aAreaLink );
900 rAreaLinks.Sort();
903 // core implementation
904 void ScXMLExport::GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp )
906 if (pDoc)
908 ScDetOpList* pOpList(pDoc->GetDetOpList());
909 if( pOpList )
911 sal_uInt32 nCount(pOpList->Count());
912 for( sal_uInt32 nIndex = 0; nIndex < nCount; ++nIndex )
914 ScDetOpData* pDetData(pOpList->GetObject( static_cast<USHORT>(nIndex) ));
915 if( pDetData )
917 const ScAddress& rDetPos = pDetData->GetPos();
918 SCTAB nTab = rDetPos.Tab();
919 if ( nTab < pDoc->GetTableCount() )
921 rDetOp.AddOperation( pDetData->GetOperation(), rDetPos, nIndex );
923 // #123981# cells with detective operations are written even if empty
924 pSharedData->SetLastColumn( nTab, rDetPos.Col() );
925 pSharedData->SetLastRow( nTab, rDetPos.Row() );
929 rDetOp.Sort();
934 void ScXMLExport::WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex,
935 const sal_Int32 nIndex, const sal_Bool bIsAutoStyle, const sal_Bool bIsVisible)
937 CheckAttrList();
938 AddAttribute(sAttrStyleName, *pColumnStyles->GetStyleNameByIndex(nStyleIndex));
939 if (!bIsVisible)
940 AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
941 if (nRepeatColumns > 1)
943 OUString sOUEndCol(OUString::valueOf(static_cast <sal_Int32> (nRepeatColumns)));
944 AddAttribute(sAttrColumnsRepeated, sOUEndCol);
946 if (nIndex != -1)
947 AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
948 SvXMLElementExport aElemC(*this, sElemCol, sal_True, sal_True);
951 void ScXMLExport::WriteColumn(const sal_Int32 nColumn, const sal_Int32 nRepeatColumns,
952 const sal_Int32 nStyleIndex, const sal_Bool bIsVisible)
954 sal_Int32 nRepeat(1);
955 sal_Int32 nPrevIndex((*pDefaults->GetColDefaults())[nColumn].nIndex);
956 sal_Bool bPrevAutoStyle((*pDefaults->GetColDefaults())[nColumn].bIsAutoStyle);
957 for (sal_Int32 i = nColumn + 1; i < nColumn + nRepeatColumns; ++i)
959 if (((*pDefaults->GetColDefaults())[i].nIndex != nPrevIndex) ||
960 ((*pDefaults->GetColDefaults())[i].bIsAutoStyle != bPrevAutoStyle))
962 WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
963 nPrevIndex = (*pDefaults->GetColDefaults())[i].nIndex;
964 bPrevAutoStyle = (*pDefaults->GetColDefaults())[i].bIsAutoStyle;
965 nRepeat = 1;
967 else
968 ++nRepeat;
970 WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
973 void ScXMLExport::OpenHeaderColumn()
975 StartElement( XML_NAMESPACE_TABLE, XML_TABLE_HEADER_COLUMNS, sal_True );
978 void ScXMLExport::CloseHeaderColumn()
980 EndElement(XML_NAMESPACE_TABLE, XML_TABLE_HEADER_COLUMNS, sal_True);
983 void ScXMLExport::ExportColumns(const sal_Int32 nTable, const table::CellRangeAddress& aColumnHeaderRange, const sal_Bool bHasColumnHeader)
985 sal_Int32 nColsRepeated (1);
986 rtl::OUString sParent;
987 sal_Int32 nIndex;
988 sal_Int32 nPrevColumn(0);
989 sal_Bool bPrevIsVisible (sal_True);
990 sal_Bool bWasHeader (sal_False);
991 sal_Bool bIsHeader (sal_False);
992 sal_Bool bIsClosed (sal_True);
993 sal_Bool bIsFirst (sal_False);
994 sal_Int32 nPrevIndex (-1);
995 sal_Int32 nColumn;
996 for (nColumn = 0; nColumn <= pSharedData->GetLastColumn(nTable); ++nColumn)
998 CheckAttrList();
999 sal_Bool bIsVisible(sal_True);
1000 nIndex = pColumnStyles->GetStyleNameIndex(nTable, nColumn, bIsVisible);
1002 bIsHeader = bHasColumnHeader && (aColumnHeaderRange.StartColumn <= nColumn) && (nColumn <= aColumnHeaderRange.EndColumn);
1003 if (bIsHeader != bWasHeader)
1005 if (bIsHeader)
1007 bIsFirst = sal_False;
1008 if (nColumn > 0)
1010 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
1011 if (pGroupColumns->IsGroupEnd(nColumn - 1))
1012 pGroupColumns->CloseGroups(nColumn - 1);
1014 bPrevIsVisible = bIsVisible;
1015 nPrevIndex = nIndex;
1016 nPrevColumn = nColumn;
1017 nColsRepeated = 1;
1018 bIsFirst = sal_True;
1019 if(pGroupColumns->IsGroupStart(nColumn))
1020 pGroupColumns->OpenGroups(nColumn);
1021 OpenHeaderColumn();
1022 bWasHeader = sal_True;
1023 bIsClosed = sal_False;
1025 else
1027 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
1028 CloseHeaderColumn();
1029 if (pGroupColumns->IsGroupEnd(nColumn - 1))
1030 pGroupColumns->CloseGroups(nColumn - 1);
1031 if(pGroupColumns->IsGroupStart(nColumn))
1032 pGroupColumns->OpenGroups(nColumn);
1033 bPrevIsVisible = bIsVisible;
1034 nPrevIndex = nIndex;
1035 nPrevColumn = nColumn;
1036 nColsRepeated = 1;
1037 bWasHeader = sal_False;
1038 bIsClosed = sal_True;
1041 else if (nColumn == 0)
1043 if (pGroupColumns->IsGroupStart(nColumn))
1044 pGroupColumns->OpenGroups(nColumn);
1045 bPrevIsVisible = bIsVisible;
1046 nPrevIndex = nIndex;
1047 bIsFirst = sal_True;
1049 else if ((bIsVisible == bPrevIsVisible) && (nIndex == nPrevIndex) &&
1050 !pGroupColumns->IsGroupStart(nColumn) && !pGroupColumns->IsGroupEnd(nColumn - 1))
1051 ++nColsRepeated;
1052 else
1054 bIsFirst = sal_False;
1055 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
1056 if (pGroupColumns->IsGroupEnd(nColumn - 1))
1058 if (bIsHeader)
1059 CloseHeaderColumn();
1060 pGroupColumns->CloseGroups(nColumn - 1);
1061 if (bIsHeader)
1062 OpenHeaderColumn();
1064 if (pGroupColumns->IsGroupStart(nColumn))
1066 if (bIsHeader)
1067 CloseHeaderColumn();
1068 pGroupColumns->OpenGroups(nColumn);
1069 if (bIsHeader)
1070 OpenHeaderColumn();
1072 bPrevIsVisible = bIsVisible;
1073 nPrevIndex = nIndex;
1074 nPrevColumn = nColumn;
1075 nColsRepeated = 1;
1078 //if (nColsRepeated > 1 || bIsFirst)
1079 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
1080 if (!bIsClosed)
1081 CloseHeaderColumn();
1082 if (pGroupColumns->IsGroupEnd(nColumn - 1))
1083 pGroupColumns->CloseGroups(nColumn - 1);
1086 void ScXMLExport::ExportExternalRefCacheStyles()
1088 sal_Int32 nEntryIndex = GetCellStylesPropertySetMapper()->FindEntryIndex(
1089 "NumberFormat", XML_NAMESPACE_STYLE, OUString::createFromAscii("data-style-name"));
1091 if (nEntryIndex < 0)
1092 // No entry index for the number format is found.
1093 return;
1095 ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
1096 if (!pRefMgr->hasExternalData())
1097 // No external reference data cached.
1098 return;
1100 // Export each unique number format used in the external ref cache.
1101 vector<sal_uInt32> aNumFmts;
1102 pRefMgr->getAllCachedNumberFormats(aNumFmts);
1103 const OUString aDefaultStyle = OUString::createFromAscii("Default").intern();
1104 for (vector<sal_uInt32>::const_iterator itr = aNumFmts.begin(), itrEnd = aNumFmts.end();
1105 itr != itrEnd; ++itr)
1107 sal_Int32 nNumFmt = static_cast<sal_Int32>(*itr);
1109 addDataStyle(nNumFmt);
1111 uno::Any aVal;
1112 aVal <<= nNumFmt;
1113 vector<XMLPropertyState> aProps;
1114 aProps.push_back(XMLPropertyState(nEntryIndex, aVal));
1115 aVal <<= aDefaultStyle;
1116 aProps.push_back(XMLPropertyState(nEntryIndex, aVal));
1118 OUString aName;
1119 sal_Int32 nIndex;
1120 if (GetAutoStylePool()->Add(aName, XML_STYLE_FAMILY_TABLE_CELL, aDefaultStyle, aProps))
1122 OUString* pTemp(new OUString(aName));
1123 if (!pCellStyles->AddStyleName(pTemp, nIndex, true))
1124 delete pTemp;
1126 else
1128 sal_Bool bIsAuto;
1129 nIndex = pCellStyles->GetIndexOfStyleName(
1130 aName, OUString::createFromAscii(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX), bIsAuto);
1133 // store the number format to index mapping for later use.
1134 aNumFmtIndexMap.insert(NumberFormatIndexMap::value_type(nNumFmt, nIndex));
1138 void ScXMLExport::WriteRowContent()
1140 ScMyRowFormatRange aRange;
1141 sal_Int32 nIndex(-1);
1142 #ifndef PRODUCT
1143 sal_Int32 nPrevCol(0);
1144 #endif
1145 sal_Int32 nCols(0);
1146 sal_Int32 nPrevValidationIndex(-1);
1147 sal_Bool bIsAutoStyle(sal_True);
1148 sal_Bool bIsFirst(sal_True);
1149 while (pRowFormatRanges->GetNext(aRange))
1151 #ifndef PRODUCT
1152 DBG_ASSERT(bIsFirst || (!bIsFirst && (nPrevCol + nCols == aRange.nStartColumn)), "here are some columns missing");
1153 #endif
1154 if (bIsFirst)
1156 nIndex = aRange.nIndex;
1157 nPrevValidationIndex = aRange.nValidationIndex;
1158 bIsAutoStyle = aRange.bIsAutoStyle;
1159 nCols = aRange.nRepeatColumns;
1160 bIsFirst = sal_False;
1161 #ifndef PRODUCT
1162 nPrevCol = aRange.nStartColumn;
1163 #endif
1165 else
1167 if (((aRange.nIndex == nIndex && aRange.bIsAutoStyle == bIsAutoStyle) ||
1168 (aRange.nIndex == nIndex && nIndex == -1)) &&
1169 nPrevValidationIndex == aRange.nValidationIndex)
1170 nCols += aRange.nRepeatColumns;
1171 else
1173 if (nIndex != -1)
1174 AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
1175 if (nPrevValidationIndex > -1)
1176 AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
1177 if (nCols > 1)
1179 rtl::OUStringBuffer aBuf;
1180 GetMM100UnitConverter().convertNumber(aBuf, nCols);
1181 AddAttribute(sAttrColumnsRepeated, aBuf.makeStringAndClear());
1183 SvXMLElementExport aElemC(*this, sElemCell, sal_True, sal_True);
1184 nIndex = aRange.nIndex;
1185 bIsAutoStyle = aRange.bIsAutoStyle;
1186 nCols = aRange.nRepeatColumns;
1187 nPrevValidationIndex = aRange.nValidationIndex;
1188 #ifndef PRODUCT
1189 nPrevCol = aRange.nStartColumn;
1190 #endif
1194 if (!bIsFirst)
1196 table::CellAddress aCellAddress;
1197 if (nIndex != -1)
1198 AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
1199 if (nPrevValidationIndex > -1)
1200 AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
1201 if (nCols > 1)
1203 rtl::OUStringBuffer aBuf;
1204 GetMM100UnitConverter().convertNumber(aBuf, nCols);
1205 AddAttribute(sAttrColumnsRepeated, aBuf.makeStringAndClear());
1207 SvXMLElementExport aElemC(*this, sElemCell, sal_True, sal_True);
1211 void ScXMLExport::WriteRowStartTag(sal_Int32 nRow, const sal_Int32 nIndex,
1212 const sal_Int8 nFlag, const sal_Int32 nEqualRows)
1214 AddAttribute(sAttrStyleName, *pRowStyles->GetStyleNameByIndex(nIndex));
1215 if (nFlag)
1216 if (nFlag & CR_HIDDEN)
1218 if (nFlag & CR_FILTERED)
1219 AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_FILTER);
1220 else
1221 AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
1223 if (nEqualRows > 1)
1225 rtl::OUStringBuffer aBuf;
1226 GetMM100UnitConverter().convertNumber(aBuf, nEqualRows);
1227 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, aBuf.makeStringAndClear());
1230 const ScMyDefaultStyleList& rRowDefaults = *pDefaults->GetRowDefaults();
1231 if ( nRow >= sal::static_int_cast<sal_Int32>( rRowDefaults.size() ) )
1233 // #123981# used to happen with detective operations - if there are more cases, use the last row's style
1234 DBG_ERRORFILE("WriteRowStartTag: not enough defaults");
1235 nRow = rRowDefaults.size() - 1;
1237 sal_Int32 nCellStyleIndex(rRowDefaults[nRow].nIndex);
1238 if (nCellStyleIndex != -1)
1239 AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME,
1240 *pCellStyles->GetStyleNameByIndex(nCellStyleIndex,
1241 (*pDefaults->GetRowDefaults())[nRow].bIsAutoStyle));
1242 StartElement( sElemRow, sal_True);
1245 void ScXMLExport::OpenHeaderRows()
1247 StartElement( XML_NAMESPACE_TABLE, XML_TABLE_HEADER_ROWS, sal_True);
1248 bRowHeaderOpen = sal_True;
1251 void ScXMLExport::CloseHeaderRows()
1253 EndElement(XML_NAMESPACE_TABLE, XML_TABLE_HEADER_ROWS, sal_True);
1256 void ScXMLExport::OpenNewRow(const sal_Int32 nIndex, const sal_Int8 nFlag, const sal_Int32 nStartRow, const sal_Int32 nEqualRows)
1258 nOpenRow = nStartRow;
1259 if (pGroupRows->IsGroupStart(nStartRow))
1261 if (bHasRowHeader && bRowHeaderOpen)
1262 CloseHeaderRows();
1263 pGroupRows->OpenGroups(nStartRow);
1264 if (bHasRowHeader && bRowHeaderOpen)
1265 OpenHeaderRows();
1267 if (bHasRowHeader && !bRowHeaderOpen && nStartRow >= aRowHeaderRange.StartRow && nStartRow <= aRowHeaderRange.EndRow)
1269 if (nStartRow == aRowHeaderRange.StartRow)
1270 OpenHeaderRows();
1271 sal_Int32 nEquals;
1272 if (aRowHeaderRange.EndRow < nStartRow + nEqualRows - 1)
1273 nEquals = aRowHeaderRange.EndRow - nStartRow + 1;
1274 else
1275 nEquals = nEqualRows;
1276 WriteRowStartTag(nStartRow, nIndex, nFlag, nEquals);
1277 nOpenRow = nStartRow + nEquals - 1;
1278 if (nEquals < nEqualRows)
1280 CloseRow(nStartRow + nEquals - 1);
1281 WriteRowStartTag(nStartRow, nIndex, nFlag, nEqualRows - nEquals);
1282 nOpenRow = nStartRow + nEqualRows - 1;
1285 else
1286 WriteRowStartTag(nStartRow, nIndex, nFlag, nEqualRows);
1289 void ScXMLExport::OpenAndCloseRow(const sal_Int32 nIndex, const sal_Int8 nFlag,
1290 const sal_Int32 nStartRow, const sal_Int32 nEqualRows)
1292 OpenNewRow(nIndex, nFlag, nStartRow, nEqualRows);
1293 WriteRowContent();
1294 CloseRow(nStartRow + nEqualRows - 1);
1295 pRowFormatRanges->Clear();
1298 void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow)
1300 if (nRepeatRow > 1)
1302 sal_Int32 nPrevIndex(0), nIndex;
1303 sal_Int8 nPrevFlag(0);
1304 sal_Int8 nFlag(0);
1305 sal_Int32 nEqualRows(1);
1306 sal_Int32 nEndRow(nStartRow + nRepeatRow);
1307 sal_Int32 nRow;
1308 for (nRow = nStartRow; nRow < nEndRow; ++nRow)
1310 if (nRow == nStartRow)
1312 nPrevIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
1313 if (pDoc)
1314 nPrevFlag = (pDoc->GetRowFlags(static_cast<SCROW>(nRow), static_cast<SCTAB>(nTable))) & (CR_HIDDEN | CR_FILTERED);
1316 else
1318 nIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
1319 if (pDoc)
1320 nFlag = (pDoc->GetRowFlags(static_cast<SCROW>(nRow), static_cast<SCTAB>(nTable))) & (CR_HIDDEN | CR_FILTERED);
1321 if (nIndex == nPrevIndex && nFlag == nPrevFlag &&
1322 !(bHasRowHeader && ((nRow == aRowHeaderRange.StartRow) || (nRow - 1 == aRowHeaderRange.EndRow))) &&
1323 !(pGroupRows->IsGroupStart(nRow)) &&
1324 !(pGroupRows->IsGroupEnd(nRow - 1)))
1325 ++nEqualRows;
1326 else
1328 if (nRow < nEndRow)
1330 ScRowFormatRanges* pTempRowFormatRanges = new ScRowFormatRanges(pRowFormatRanges);
1331 OpenAndCloseRow(nPrevIndex, nPrevFlag, nRow - nEqualRows, nEqualRows);
1332 delete pRowFormatRanges;
1333 pRowFormatRanges = pTempRowFormatRanges;
1335 else
1336 OpenAndCloseRow(nPrevIndex, nPrevFlag, nRow - nEqualRows, nEqualRows);
1337 nEqualRows = 1;
1338 nPrevIndex = nIndex;
1339 nPrevFlag = nFlag;
1343 OpenNewRow(nPrevIndex, nPrevFlag, nRow - nEqualRows, nEqualRows);
1345 else
1347 sal_Int32 nIndex = pRowStyles->GetStyleNameIndex(nTable, nStartRow);
1348 sal_Int8 nFlag(0);
1349 if (pDoc)
1350 nFlag = (pDoc->GetRowFlags(static_cast<SCROW>(nStartRow), static_cast<SCTAB>(nTable))) & (CR_HIDDEN | CR_FILTERED);
1351 OpenNewRow(nIndex, nFlag, nStartRow, 1);
1353 nOpenRow = nStartRow + nRepeatRow - 1;
1356 void ScXMLExport::CloseRow(const sal_Int32 nRow)
1358 if (nOpenRow > -1)
1360 EndElement(sElemRow, sal_True);
1361 if (bHasRowHeader && nRow == aRowHeaderRange.EndRow)
1363 CloseHeaderRows();
1364 bRowHeaderOpen = sal_False;
1366 if (pGroupRows->IsGroupEnd(nRow))
1368 if (bHasRowHeader && bRowHeaderOpen)
1369 CloseHeaderRows();
1370 pGroupRows->CloseGroups(nRow);
1371 if (bHasRowHeader && bRowHeaderOpen)
1372 OpenHeaderRows();
1375 nOpenRow = -1;
1378 void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32 nStartRow,
1379 const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet)
1381 pRowFormatRanges->Clear();
1382 if (nStartRow == nEndRow)
1384 pCellStyles->GetFormatRanges(nStartCol, nEndCol, nStartRow, nSheet, pRowFormatRanges);
1385 if (nOpenRow == - 1)
1386 OpenRow(nSheet, nStartRow, 1);
1387 WriteRowContent();
1388 pRowFormatRanges->Clear();
1390 else
1392 if (nOpenRow > -1)
1394 pCellStyles->GetFormatRanges(nStartCol, pSharedData->GetLastColumn(nSheet), nStartRow, nSheet, pRowFormatRanges);
1395 WriteRowContent();
1396 CloseRow(nStartRow);
1397 sal_Int32 nRows(1);
1398 sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
1399 while (nRows < nTotalRows)
1401 pRowFormatRanges->Clear();
1402 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1403 sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
1404 DBG_ASSERT(nMaxRows, "something wents wrong");
1405 if (nMaxRows >= nTotalRows - nRows)
1407 OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows);
1408 nRows += nTotalRows - nRows;
1410 else
1412 OpenRow(nSheet, nStartRow + nRows, nMaxRows);
1413 nRows += nMaxRows;
1415 if (!pRowFormatRanges->GetSize())
1416 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1417 WriteRowContent();
1418 CloseRow(nStartRow + nRows - 1);
1420 if (nTotalRows == 1)
1421 CloseRow(nStartRow);
1422 OpenRow(nSheet, nEndRow, 1);
1423 pRowFormatRanges->Clear();
1424 pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
1425 WriteRowContent();
1427 else
1429 sal_Int32 nRows(0);
1430 sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
1431 while (nRows < nTotalRows)
1433 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1434 sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
1435 if (nMaxRows >= nTotalRows - nRows)
1437 OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows);
1438 nRows += nTotalRows - nRows;
1440 else
1442 OpenRow(nSheet, nStartRow + nRows, nMaxRows);
1443 nRows += nMaxRows;
1445 if (!pRowFormatRanges->GetSize())
1446 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
1447 WriteRowContent();
1448 CloseRow(nStartRow + nRows - 1);
1450 OpenRow(nSheet, nEndRow, 1);
1451 pRowFormatRanges->Clear();
1452 pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
1453 WriteRowContent();
1458 void ScXMLExport::GetColumnRowHeader(sal_Bool& rHasColumnHeader, table::CellRangeAddress& rColumnHeaderRange,
1459 sal_Bool& rHasRowHeader, table::CellRangeAddress& rRowHeaderRange,
1460 rtl::OUString& rPrintRanges) const
1462 uno::Reference <sheet::XPrintAreas> xPrintAreas (xCurrentTable, uno::UNO_QUERY);
1463 if (xPrintAreas.is())
1465 rHasRowHeader = xPrintAreas->getPrintTitleRows();
1466 rHasColumnHeader = xPrintAreas->getPrintTitleColumns();
1467 rRowHeaderRange = xPrintAreas->getTitleRows();
1468 rColumnHeaderRange = xPrintAreas->getTitleColumns();
1469 uno::Sequence< table::CellRangeAddress > aRangeList( xPrintAreas->getPrintAreas() );
1470 ScRangeStringConverter::GetStringFromRangeList( rPrintRanges, aRangeList, pDoc, FormulaGrammar::CONV_OOO );
1474 void ScXMLExport::FillFieldGroup(ScOutlineArray* pFields, ScMyOpenCloseColumnRowGroup* pGroups)
1476 sal_Int32 nDepth(pFields->GetDepth());
1477 for(sal_Int32 i = 0; i < nDepth; ++i)
1479 sal_Int32 nFields = pFields->GetCount(static_cast<USHORT>(i));
1480 for (sal_Int32 j = 0; j < nFields; ++j)
1482 ScMyColumnRowGroup aGroup;
1483 ScOutlineEntry* pEntry(pFields->GetEntry(static_cast<USHORT>(i), static_cast<USHORT>(j)));
1484 aGroup.nField = pEntry->GetStart();
1485 aGroup.nLevel = static_cast<sal_Int16>(i);
1486 aGroup.bDisplay = !(pEntry->IsHidden());
1487 pGroups->AddGroup(aGroup, pEntry->GetEnd());
1490 if (nDepth)
1491 pGroups->Sort();
1494 void ScXMLExport::FillColumnRowGroups()
1496 if (pDoc)
1498 ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable( static_cast<SCTAB>(nCurrentTable), sal_False );
1499 if(pOutlineTable)
1501 ScOutlineArray* pCols(pOutlineTable->GetColArray());
1502 ScOutlineArray* pRows(pOutlineTable->GetRowArray());
1503 if (pCols)
1504 FillFieldGroup(pCols, pGroupColumns);
1505 if (pRows)
1506 FillFieldGroup(pRows, pGroupRows);
1507 pSharedData->SetLastColumn(nCurrentTable, pGroupColumns->GetLast());
1508 pSharedData->SetLastRow(nCurrentTable, pGroupRows->GetLast());
1513 void ScXMLExport::SetBodyAttributes()
1515 if (pDoc && pDoc->IsDocProtected())
1517 AddAttribute(XML_NAMESPACE_TABLE, XML_STRUCTURE_PROTECTED, XML_TRUE);
1518 rtl::OUStringBuffer aBuffer;
1519 uno::Sequence<sal_Int8> aPassHash;
1520 ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
1521 const ScDocProtection* p = pDoc->GetDocProtection();
1522 if (p)
1524 if (p->hasPasswordHash(PASSHASH_SHA1))
1526 aPassHash = p->getPasswordHash(PASSHASH_SHA1);
1527 eHashUsed = PASSHASH_SHA1;
1529 else if (p->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
1531 aPassHash = p->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
1532 eHashUsed = PASSHASH_XL;
1535 SvXMLUnitConverter::encodeBase64(aBuffer, aPassHash);
1536 if (aBuffer.getLength())
1538 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
1539 if (eHashUsed == PASSHASH_XL)
1541 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
1542 ScPassHashHelper::getHashURI(PASSHASH_XL));
1543 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
1544 ScPassHashHelper::getHashURI(PASSHASH_SHA1));
1546 else if (eHashUsed == PASSHASH_SHA1)
1547 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
1548 ScPassHashHelper::getHashURI(PASSHASH_SHA1));
1553 static bool lcl_CopyStreamElement( const uno::Reference< io::XInputStream >& xInput,
1554 const uno::Reference< io::XOutputStream >& xOutput,
1555 sal_Int32 nCount )
1557 const sal_Int32 nBufSize = 16*1024;
1558 uno::Sequence<sal_Int8> aSequence(nBufSize);
1560 sal_Int32 nRemaining = nCount;
1561 bool bFirst = true;
1563 while ( nRemaining > 0 )
1565 sal_Int32 nRead = xInput->readBytes( aSequence, std::min( nRemaining, nBufSize ) );
1566 if (bFirst)
1568 // safety check: Make sure the copied part actually points to the start of an element
1569 if ( nRead < 1 || aSequence[0] != static_cast<sal_Int8>('<') )
1571 return false; // abort and set an error
1573 bFirst = false;
1575 if (nRead == nRemaining)
1577 // safety check: Make sure the copied part also ends at the end of an element
1578 if ( aSequence[nRead-1] != static_cast<sal_Int8>('>') )
1580 return false; // abort and set an error
1584 if ( nRead == nBufSize )
1586 xOutput->writeBytes( aSequence );
1587 nRemaining -= nRead;
1589 else
1591 if ( nRead > 0 )
1593 uno::Sequence<sal_Int8> aTempBuf( aSequence.getConstArray(), nRead );
1594 xOutput->writeBytes( aTempBuf );
1596 nRemaining = 0;
1599 return true; // successful
1602 void ScXMLExport::CopySourceStream( sal_Int32 nStartOffset, sal_Int32 nEndOffset, sal_Int32& rNewStart, sal_Int32& rNewEnd )
1604 uno::Reference<xml::sax::XDocumentHandler> xHandler = GetDocHandler();
1605 uno::Reference<io::XActiveDataSource> xDestSource( xHandler, uno::UNO_QUERY );
1606 if ( xDestSource.is() )
1608 uno::Reference<io::XOutputStream> xDestStream = xDestSource->getOutputStream();
1609 uno::Reference<io::XSeekable> xDestSeek( xDestStream, uno::UNO_QUERY );
1610 if ( xDestSeek.is() )
1612 // temporary: set same stream again to clear buffer
1613 xDestSource->setOutputStream( xDestStream );
1615 if ( getExportFlags() & EXPORT_PRETTY )
1617 ByteString aOutStr("\n ");
1618 uno::Sequence<sal_Int8> aOutSeq( (sal_Int8*)aOutStr.GetBuffer(), aOutStr.Len() );
1619 xDestStream->writeBytes( aOutSeq );
1622 rNewStart = (sal_Int32)xDestSeek->getPosition();
1624 if ( nStartOffset > nSourceStreamPos )
1625 xSourceStream->skipBytes( nStartOffset - nSourceStreamPos );
1627 if ( !lcl_CopyStreamElement( xSourceStream, xDestStream, nEndOffset - nStartOffset ) )
1629 // If copying went wrong, set an error.
1630 // ScXMLImportWrapper then resets all stream flags, so the next save attempt will use normal saving.
1632 uno::Sequence<OUString> aEmptySeq;
1633 SetError(XMLERROR_CANCEL|XMLERROR_FLAG_SEVERE, aEmptySeq);
1635 nSourceStreamPos = nEndOffset;
1637 rNewEnd = (sal_Int32)xDestSeek->getPosition();
1642 void ScXMLExport::_ExportContent()
1644 nCurrentTable = 0;
1645 if (!pSharedData)
1647 sal_Int32 nTableCount(0);
1648 sal_Int32 nShapesCount(0);
1649 sal_Int32 nCellCount(pDoc ? pDoc->GetCellCount() : 0);
1650 CollectSharedData(nTableCount, nShapesCount, nCellCount);
1651 DBG_ERROR("no shared data setted");
1653 ScXMLExportDatabaseRanges aExportDatabaseRanges(*this);
1654 if (!GetModel().is())
1655 return;
1657 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
1658 if ( !xSpreadDoc.is() )
1659 return;
1661 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(xSpreadDoc)->GetSheetSaveData();
1662 if (pSheetData)
1663 pSheetData->ResetSaveEntries();
1665 uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
1666 if ( xIndex.is() )
1668 //_GetNamespaceMap().ClearQNamesCache();
1669 pChangeTrackingExportHelper->CollectAndWriteChanges();
1670 WriteCalculationSettings(xSpreadDoc);
1671 sal_Int32 nTableCount(xIndex->getCount());
1672 ScMyAreaLinksContainer aAreaLinks;
1673 GetAreaLinks( xSpreadDoc, aAreaLinks );
1674 ScMyEmptyDatabaseRangesContainer aEmptyRanges(aExportDatabaseRanges.GetEmptyDatabaseRanges());
1675 ScMyDetectiveOpContainer aDetectiveOpContainer;
1676 GetDetectiveOpList( aDetectiveOpContainer );
1678 pCellStyles->Sort();
1679 pMergedRangesContainer->Sort();
1680 pSharedData->GetDetectiveObjContainer()->Sort();
1682 pCellsItr->Clear();
1683 pCellsItr->SetShapes( pSharedData->GetShapesContainer() );
1684 pCellsItr->SetNoteShapes( pSharedData->GetNoteShapes() );
1685 pCellsItr->SetMergedRanges( pMergedRangesContainer );
1686 pCellsItr->SetAreaLinks( &aAreaLinks );
1687 pCellsItr->SetEmptyDatabaseRanges( &aEmptyRanges );
1688 pCellsItr->SetDetectiveObj( pSharedData->GetDetectiveObjContainer() );
1689 pCellsItr->SetDetectiveOp( &aDetectiveOpContainer );
1691 if (nTableCount > 0)
1692 pValidationsContainer->WriteValidations(*this);
1693 WriteTheLabelRanges( xSpreadDoc );
1694 for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable)
1696 sal_Int32 nStartOffset = -1;
1697 sal_Int32 nEndOffset = -1;
1698 if (pSheetData && pDoc && pDoc->IsStreamValid((SCTAB)nTable))
1699 pSheetData->GetStreamPos( nTable, nStartOffset, nEndOffset );
1701 if ( nStartOffset >= 0 && nEndOffset >= 0 && xSourceStream.is() )
1703 sal_Int32 nNewStart = -1;
1704 sal_Int32 nNewEnd = -1;
1705 CopySourceStream( nStartOffset, nEndOffset, nNewStart, nNewEnd );
1707 // store position of copied sheet in output
1708 pSheetData->AddSavePos( nTable, nNewStart, nNewEnd );
1710 // skip iterator entries for this sheet
1711 pCellsItr->SkipTable(static_cast<SCTAB>(nTable));
1713 else
1715 //! indent after rebasing to m52
1717 uno::Reference<sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
1718 if (xTable.is())
1720 xCurrentTable.set(xTable);
1721 xCurrentTableCellRange.set(xTable, uno::UNO_QUERY);
1722 uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
1723 if ( xName.is() )
1725 nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
1726 rtl::OUString sOUTableName(xName->getName());
1727 AddAttribute(sAttrName, sOUTableName);
1728 AddAttribute(sAttrStyleName, aTableStyles[nTable]);
1729 uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
1730 ScTableProtection* pProtect = NULL;
1731 if (xProtectable.is() && xProtectable->isProtected())
1733 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
1734 if (pDoc)
1736 pProtect = pDoc->GetTabProtection(static_cast<SCTAB>(nTable));
1737 if (pProtect)
1739 rtl::OUStringBuffer aBuffer;
1740 ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
1741 if (pProtect->hasPasswordHash(PASSHASH_SHA1))
1743 SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_SHA1));
1744 eHashUsed = PASSHASH_SHA1;
1746 else if (pProtect->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
1748 // Double-hash this by SHA1 on top of the legacy xls hash.
1749 uno::Sequence<sal_Int8> aHash = pProtect->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
1750 SvXMLUnitConverter::encodeBase64(aBuffer, aHash);
1751 eHashUsed = PASSHASH_XL;
1753 if (aBuffer.getLength())
1755 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
1756 if (eHashUsed == PASSHASH_XL)
1758 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
1759 ScPassHashHelper::getHashURI(PASSHASH_XL));
1760 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
1761 ScPassHashHelper::getHashURI(PASSHASH_SHA1));
1763 else if (eHashUsed == PASSHASH_SHA1)
1764 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
1765 ScPassHashHelper::getHashURI(PASSHASH_SHA1));
1771 rtl::OUString sPrintRanges;
1772 table::CellRangeAddress aColumnHeaderRange;
1773 sal_Bool bHasColumnHeader;
1774 GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
1775 if( sPrintRanges.getLength() )
1776 AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT_RANGES, sPrintRanges );
1777 else if (!pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
1778 AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT, XML_FALSE);
1779 SvXMLElementExport aElemT(*this, sElemTab, sal_True, sal_True);
1781 if (pProtect && pProtect->isProtected())
1783 if (pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS))
1784 AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_PROTECTED_CELLS, XML_TRUE);
1785 if (pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS))
1786 AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_UNPROTECTED_CELLS, XML_TRUE);
1788 rtl::OUString aElemName = GetNamespaceMap().GetQNameByKey(
1789 XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_PROTECTION));
1791 SvXMLElementExport aElemProtected(*this, aElemName, true, true);
1794 CheckAttrList();
1795 WriteTableSource();
1796 WriteScenario();
1797 uno::Reference<drawing::XDrawPage> xDrawPage;
1798 if (pSharedData->HasForm(nTable, xDrawPage) && xDrawPage.is())
1800 ::xmloff::OOfficeFormsExport aForms(*this);
1801 GetFormExport()->exportForms( xDrawPage );
1802 sal_Bool bRet(GetFormExport()->seekPage( xDrawPage ));
1803 DBG_ASSERT( bRet, "OFormLayerXMLExport::seekPage failed!" );
1804 (void)bRet; // avoid warning in product version
1806 if (pSharedData->HasDrawPage())
1808 GetShapeExport()->seekShapes(uno::Reference<drawing::XShapes>(pSharedData->GetDrawPage(nTable), uno::UNO_QUERY));
1809 WriteTableShapes();
1811 table::CellRangeAddress aRange(GetEndAddress(xTable, nTable));
1812 pSharedData->SetLastColumn(nTable, aRange.EndColumn);
1813 pSharedData->SetLastRow(nTable, aRange.EndRow);
1814 pCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
1815 pGroupColumns->NewTable();
1816 pGroupRows->NewTable();
1817 FillColumnRowGroups();
1818 if (bHasColumnHeader)
1819 pSharedData->SetLastColumn(nTable, aColumnHeaderRange.EndColumn);
1820 bRowHeaderOpen = sal_False;
1821 if (bHasRowHeader)
1822 pSharedData->SetLastRow(nTable, aRowHeaderRange.EndRow);
1823 pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
1824 pSharedData->GetLastColumn(nTable), pCellStyles, pDoc);
1825 pRowFormatRanges->SetRowDefaults(pDefaults->GetRowDefaults());
1826 pRowFormatRanges->SetColDefaults(pDefaults->GetColDefaults());
1827 pCellStyles->SetRowDefaults(pDefaults->GetRowDefaults());
1828 pCellStyles->SetColDefaults(pDefaults->GetColDefaults());
1829 ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
1830 sal_Bool bIsFirst(sal_True);
1831 sal_Int32 nEqualCells(0);
1832 ScMyCell aCell;
1833 ScMyCell aPrevCell;
1834 while(pCellsItr->GetNext(aCell, pCellStyles))
1836 if (bIsFirst)
1838 ExportFormatRanges(0, 0, aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
1839 aPrevCell = aCell;
1840 bIsFirst = sal_False;
1842 else
1844 if ((aPrevCell.aCellAddress.Row == aCell.aCellAddress.Row) &&
1845 (aPrevCell.aCellAddress.Column + nEqualCells + 1 == aCell.aCellAddress.Column))
1847 if(IsCellEqual(aPrevCell, aCell))
1848 ++nEqualCells;
1849 else
1851 SetRepeatAttribute(nEqualCells);
1852 WriteCell(aPrevCell);
1853 nEqualCells = 0;
1854 aPrevCell = aCell;
1857 else
1859 SetRepeatAttribute(nEqualCells);
1860 WriteCell(aPrevCell);
1861 ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
1862 aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
1863 nEqualCells = 0;
1864 aPrevCell = aCell;
1868 if (!bIsFirst)
1870 SetRepeatAttribute(nEqualCells);
1871 WriteCell(aPrevCell);
1872 ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
1873 pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
1875 else
1876 ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
1877 CloseRow(pSharedData->GetLastRow(nTable));
1878 nEqualCells = 0;
1883 IncrementProgressBar(sal_False);
1886 WriteExternalRefCaches();
1887 WriteNamedExpressions(xSpreadDoc);
1888 aExportDatabaseRanges.WriteDatabaseRanges(xSpreadDoc);
1889 ScXMLExportDataPilot aExportDataPilot(*this);
1890 aExportDataPilot.WriteDataPilots(xSpreadDoc);
1891 WriteConsolidation();
1892 ScXMLExportDDELinks aExportDDELinks(*this);
1893 aExportDDELinks.WriteDDELinks(xSpreadDoc);
1894 IncrementProgressBar(sal_True, 0);
1895 GetProgressBarHelper()->SetValue(GetProgressBarHelper()->GetReference());
1898 void ScXMLExport::_ExportStyles( sal_Bool bUsed )
1900 if (!pSharedData)
1902 sal_Int32 nTableCount(0);
1903 sal_Int32 nShapesCount(0);
1904 sal_Int32 nCellCount(pDoc ? pDoc->GetCellCount() : 0);
1905 CollectSharedData(nTableCount, nShapesCount, nCellCount);
1906 //DBG_ERROR("no shared data setted");
1908 ScXMLStyleExport aStylesExp(*this, rtl::OUString(), GetAutoStylePool().get());
1909 if (GetModel().is())
1911 uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
1912 if (xMultiServiceFactory.is())
1914 uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.Defaults"))), uno::UNO_QUERY);
1915 if (xProperties.is())
1916 aStylesExp.exportDefaultStyle(xProperties, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME)), xCellStylesExportPropertySetMapper);
1917 if (pSharedData->HasShapes())
1919 GetShapeExport()->ExportGraphicDefaults();
1920 /* xInterface = xMultiServiceFactory->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Defaults")));
1921 uno::Reference <beans::XPropertySet> xDrawProperties(xInterface, uno::UNO_QUERY);
1922 if (xDrawProperties.is())
1923 aStylesExp.exportDefaultStyle(xDrawProperties, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)), GetShapeExport()->CreateShapePropMapper(*this));*/
1926 uno::Reference <style::XStyleFamiliesSupplier> xStyleFamiliesSupplier (GetModel(), uno::UNO_QUERY);
1927 if (xStyleFamiliesSupplier.is())
1929 uno::Reference <container::XNameAccess> xStylesFamilies(xStyleFamiliesSupplier->getStyleFamilies());
1930 if (xStylesFamilies.is())
1932 uno::Reference <container::XIndexAccess> xCellStyles(xStylesFamilies->getByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CellStyles"))), uno::UNO_QUERY);
1933 if (xCellStyles.is())
1935 sal_Int32 nCount(xCellStyles->getCount());
1936 rtl::OUString sNumberFormat(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_NUMFMT));
1937 for (sal_Int32 i = 0; i < nCount; ++i)
1939 uno::Reference <beans::XPropertySet> xCellProperties(xCellStyles->getByIndex(i), uno::UNO_QUERY);
1940 if (xCellProperties.is())
1942 sal_Int32 nNumberFormat = 0;
1943 if (xCellProperties->getPropertyValue(sNumberFormat) >>= nNumberFormat)
1944 addDataStyle(nNumberFormat);
1951 exportDataStyles();
1953 aStylesExp.exportStyleFamily(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CellStyles")),
1954 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME)), xCellStylesExportPropertySetMapper, FALSE, XML_STYLE_FAMILY_TABLE_CELL);
1956 SvXMLExport::_ExportStyles(bUsed);
1959 void ScXMLExport::AddStyleFromCells(const uno::Reference<beans::XPropertySet>& xProperties,
1960 const uno::Reference<sheet::XSpreadsheet>& xTable,
1961 sal_Int32 nTable, const rtl::OUString* pOldName)
1963 //! pass xCellRanges instead
1964 uno::Reference<sheet::XSheetCellRanges> xCellRanges( xProperties, uno::UNO_QUERY );
1966 rtl::OUString SC_SCELLPREFIX(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX));
1967 rtl::OUString SC_NUMBERFORMAT(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_NUMFMT));
1969 rtl::OUString sStyleName;
1970 sal_Int32 nNumberFormat(-1);
1971 sal_Int32 nValidationIndex(-1);
1972 std::vector< XMLPropertyState > xPropStates(xCellStylesExportPropertySetMapper->Filter( xProperties ));
1973 std::vector< XMLPropertyState >::iterator aItr(xPropStates.begin());
1974 std::vector< XMLPropertyState >::iterator aEndItr(xPropStates.end());
1975 sal_Int32 nCount(0);
1976 while (aItr != aEndItr)
1978 if (aItr->mnIndex != -1)
1980 switch (xCellStylesPropertySetMapper->GetEntryContextId(aItr->mnIndex))
1982 case CTF_SC_VALIDATION :
1984 pValidationsContainer->AddValidation(aItr->maValue, nValidationIndex);
1985 // this is not very slow, because it is most the last property or
1986 // if it is not the last property it is the property before the last property,
1987 // so in the worst case only one property has to be copied, but in the best case no
1988 // property has to be copied
1989 aItr = xPropStates.erase(aItr);
1990 aEndItr = xPropStates.end(); // #120346# old aEndItr is invalidated!
1992 break;
1993 case CTF_SC_CELLSTYLE :
1995 aItr->maValue >>= sStyleName;
1996 aItr->mnIndex = -1;
1997 ++aItr;
1998 ++nCount;
2000 break;
2001 case CTF_SC_NUMBERFORMAT :
2003 if (aItr->maValue >>= nNumberFormat)
2004 addDataStyle(nNumberFormat);
2005 ++aItr;
2006 ++nCount;
2008 break;
2009 default:
2011 ++aItr;
2012 ++nCount;
2014 break;
2017 else
2019 ++aItr;
2020 ++nCount;
2023 if (nCount == 1) // this is the CellStyle and should be removed if alone
2024 xPropStates.clear();
2025 if (nNumberFormat == -1)
2026 xProperties->getPropertyValue(SC_NUMBERFORMAT) >>= nNumberFormat;
2027 if (sStyleName.getLength())
2029 if (xPropStates.size())
2031 sal_Int32 nIndex;
2032 if (pOldName)
2034 if (GetAutoStylePool()->AddNamed(*pOldName, XML_STYLE_FAMILY_TABLE_CELL, sStyleName, xPropStates))
2036 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_CELL, *pOldName);
2037 // add to pCellStyles, so the name is found for normal sheets
2038 rtl::OUString* pTemp(new rtl::OUString(*pOldName));
2039 if (!pCellStyles->AddStyleName(pTemp, nIndex))
2040 delete pTemp;
2043 else
2045 rtl::OUString sName;
2046 sal_Bool bIsAutoStyle(sal_True);
2047 if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_CELL, sStyleName, xPropStates))
2049 rtl::OUString* pTemp(new rtl::OUString(sName));
2050 if (!pCellStyles->AddStyleName(pTemp, nIndex))
2051 delete pTemp;
2053 else
2054 nIndex = pCellStyles->GetIndexOfStyleName(sName, SC_SCELLPREFIX, bIsAutoStyle);
2056 uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
2057 table::CellRangeAddress* pAddresses(aAddresses.getArray());
2058 sal_Bool bGetMerge(sal_True);
2059 for (sal_Int32 i = 0; i < aAddresses.getLength(); ++i, ++pAddresses)
2061 pSharedData->SetLastColumn(nTable, pAddresses->EndColumn);
2062 pSharedData->SetLastRow(nTable, pAddresses->EndRow);
2063 pCellStyles->AddRangeStyleName(*pAddresses, nIndex, bIsAutoStyle, nValidationIndex, nNumberFormat);
2064 if (bGetMerge)
2065 bGetMerge = GetMerged(pAddresses, xTable);
2069 else
2071 rtl::OUString* pTemp(new rtl::OUString(EncodeStyleName(sStyleName)));
2072 sal_Int32 nIndex(0);
2073 if (!pCellStyles->AddStyleName(pTemp, nIndex, sal_False))
2075 delete pTemp;
2076 pTemp = NULL;
2078 if ( !pOldName )
2080 uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
2081 table::CellRangeAddress* pAddresses(aAddresses.getArray());
2082 sal_Bool bGetMerge(sal_True);
2083 for (sal_Int32 i = 0; i < aAddresses.getLength(); ++i, ++pAddresses)
2085 if (bGetMerge)
2086 bGetMerge = GetMerged(pAddresses, xTable);
2087 pCellStyles->AddRangeStyleName(*pAddresses, nIndex, sal_False, nValidationIndex, nNumberFormat);
2088 if (!sStyleName.equalsAsciiL("Default", 7) || nValidationIndex != -1)
2090 pSharedData->SetLastColumn(nTable, pAddresses->EndColumn);
2091 pSharedData->SetLastRow(nTable, pAddresses->EndRow);
2099 void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>& xColumnProperties,
2100 const rtl::OUString* pOldName, sal_Int32& rIndex, sal_Bool& rIsVisible)
2102 rtl::OUString SC_SCOLUMNPREFIX(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX));
2104 std::vector<XMLPropertyState> xPropStates(xColumnStylesExportPropertySetMapper->Filter(xColumnProperties));
2105 if(xPropStates.size())
2107 std::vector< XMLPropertyState >::iterator aItr(xPropStates.begin());
2108 std::vector< XMLPropertyState >::iterator aEndItr(xPropStates.end());
2109 while (aItr != aEndItr)
2111 if (xColumnStylesPropertySetMapper->GetEntryContextId(aItr->mnIndex) == CTF_SC_ISVISIBLE)
2113 aItr->maValue >>= rIsVisible;
2114 break;
2116 ++aItr;
2119 rtl::OUString sParent;
2120 if (pOldName)
2122 if (GetAutoStylePool()->AddNamed(*pOldName, XML_STYLE_FAMILY_TABLE_COLUMN, sParent, xPropStates))
2124 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_COLUMN, *pOldName);
2125 // add to pColumnStyles, so the name is found for normal sheets
2126 rtl::OUString* pTemp(new rtl::OUString(*pOldName));
2127 rIndex = pColumnStyles->AddStyleName(pTemp);
2130 else
2132 rtl::OUString sName;
2133 if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_COLUMN, sParent, xPropStates))
2135 rtl::OUString* pTemp(new rtl::OUString(sName));
2136 rIndex = pColumnStyles->AddStyleName(pTemp);
2138 else
2139 rIndex = pColumnStyles->GetIndexOfStyleName(sName, SC_SCOLUMNPREFIX);
2144 void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRowProperties,
2145 const rtl::OUString* pOldName, sal_Int32& rIndex)
2147 rtl::OUString SC_SROWPREFIX(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX));
2149 std::vector<XMLPropertyState> xPropStates(xRowStylesExportPropertySetMapper->Filter(xRowProperties));
2150 if(xPropStates.size())
2152 rtl::OUString sParent;
2153 if (pOldName)
2155 if (GetAutoStylePool()->AddNamed(*pOldName, XML_STYLE_FAMILY_TABLE_ROW, sParent, xPropStates))
2157 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_ROW, *pOldName);
2158 // add to pRowStyles, so the name is found for normal sheets
2159 rtl::OUString* pTemp(new rtl::OUString(*pOldName));
2160 rIndex = pRowStyles->AddStyleName(pTemp);
2163 else
2165 rtl::OUString sName;
2166 if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_ROW, sParent, xPropStates))
2168 rtl::OUString* pTemp(new rtl::OUString(sName));
2169 rIndex = pRowStyles->AddStyleName(pTemp);
2171 else
2172 rIndex = pRowStyles->GetIndexOfStyleName(sName, SC_SROWPREFIX);
2177 uno::Any lcl_GetEnumerated( uno::Reference<container::XEnumerationAccess> xEnumAccess, sal_Int32 nIndex )
2179 uno::Any aRet;
2180 uno::Reference<container::XEnumeration> xEnum( xEnumAccess->createEnumeration() );
2183 sal_Int32 nSkip = nIndex;
2184 while ( nSkip > 0 )
2186 (void) xEnum->nextElement();
2187 --nSkip;
2189 aRet = xEnum->nextElement();
2191 catch (container::NoSuchElementException&)
2193 // leave aRet empty
2195 return aRet;
2198 void ScXMLExport::_ExportAutoStyles()
2200 if (GetModel().is())
2202 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
2203 if ( xSpreadDoc.is() )
2205 uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
2206 if ( xIndex.is() )
2208 if (getExportFlags() & EXPORT_CONTENT)
2210 // re-create automatic styles with old names from stored data
2211 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(xSpreadDoc)->GetSheetSaveData();
2212 if (pSheetData && pDoc)
2214 // formulas have to be calculated now, to detect changed results
2215 // (during normal save, they will be calculated anyway)
2216 SCTAB nTabCount = pDoc->GetTableCount();
2217 for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
2218 if (pDoc->IsStreamValid(nTab))
2220 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab );
2221 ScBaseCell* pCell = aIter.GetFirst();
2222 while (pCell)
2224 if (pCell->GetCellType() == CELLTYPE_FORMULA)
2225 static_cast<ScFormulaCell*>(pCell)->IsValue(); // interpret if dirty
2226 pCell = aIter.GetNext();
2230 // stored cell styles
2231 const std::vector<ScCellStyleEntry>& rCellEntries = pSheetData->GetCellStyles();
2232 std::vector<ScCellStyleEntry>::const_iterator aCellIter = rCellEntries.begin();
2233 std::vector<ScCellStyleEntry>::const_iterator aCellEnd = rCellEntries.end();
2234 while (aCellIter != aCellEnd)
2236 ScAddress aPos = aCellIter->maCellPos;
2237 sal_Int32 nTable = aPos.Tab();
2238 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2239 if (bCopySheet)
2241 uno::Reference <sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2242 uno::Reference <beans::XPropertySet> xProperties(
2243 xTable->getCellByPosition( aPos.Col(), aPos.Row() ), uno::UNO_QUERY );
2245 AddStyleFromCells(xProperties, xTable, nTable, &aCellIter->maName);
2247 ++aCellIter;
2250 // stored column styles
2251 const std::vector<ScCellStyleEntry>& rColumnEntries = pSheetData->GetColumnStyles();
2252 std::vector<ScCellStyleEntry>::const_iterator aColumnIter = rColumnEntries.begin();
2253 std::vector<ScCellStyleEntry>::const_iterator aColumnEnd = rColumnEntries.end();
2254 while (aColumnIter != aColumnEnd)
2256 ScAddress aPos = aColumnIter->maCellPos;
2257 sal_Int32 nTable = aPos.Tab();
2258 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2259 if (bCopySheet)
2261 uno::Reference<table::XColumnRowRange> xColumnRowRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2262 uno::Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns());
2263 uno::Reference<beans::XPropertySet> xColumnProperties(xTableColumns->getByIndex( aPos.Col() ), uno::UNO_QUERY);
2265 sal_Int32 nIndex(-1);
2266 sal_Bool bIsVisible(sal_True);
2267 AddStyleFromColumn( xColumnProperties, &aColumnIter->maName, nIndex, bIsVisible );
2269 ++aColumnIter;
2272 // stored row styles
2273 const std::vector<ScCellStyleEntry>& rRowEntries = pSheetData->GetRowStyles();
2274 std::vector<ScCellStyleEntry>::const_iterator aRowIter = rRowEntries.begin();
2275 std::vector<ScCellStyleEntry>::const_iterator aRowEnd = rRowEntries.end();
2276 while (aRowIter != aRowEnd)
2278 ScAddress aPos = aRowIter->maCellPos;
2279 sal_Int32 nTable = aPos.Tab();
2280 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2281 if (bCopySheet)
2283 uno::Reference<table::XColumnRowRange> xColumnRowRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2284 uno::Reference<table::XTableRows> xTableRows(xColumnRowRange->getRows());
2285 uno::Reference<beans::XPropertySet> xRowProperties(xTableRows->getByIndex( aPos.Row() ), uno::UNO_QUERY);
2287 sal_Int32 nIndex(-1);
2288 AddStyleFromRow( xRowProperties, &aRowIter->maName, nIndex );
2290 ++aRowIter;
2293 // stored table styles
2294 const std::vector<ScCellStyleEntry>& rTableEntries = pSheetData->GetTableStyles();
2295 std::vector<ScCellStyleEntry>::const_iterator aTableIter = rTableEntries.begin();
2296 std::vector<ScCellStyleEntry>::const_iterator aTableEnd = rTableEntries.end();
2297 while (aTableIter != aTableEnd)
2299 ScAddress aPos = aTableIter->maCellPos;
2300 sal_Int32 nTable = aPos.Tab();
2301 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2302 if (bCopySheet)
2304 //! separate method AddStyleFromTable needed?
2305 uno::Reference<beans::XPropertySet> xTableProperties(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2306 if (xTableProperties.is())
2308 std::vector<XMLPropertyState> xPropStates(xTableStylesExportPropertySetMapper->Filter(xTableProperties));
2309 rtl::OUString sParent;
2310 rtl::OUString sName( aTableIter->maName );
2311 GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TABLE_TABLE, sParent, xPropStates);
2312 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_TABLE, sName);
2315 ++aTableIter;
2318 // stored styles for notes
2320 UniReference<SvXMLExportPropertyMapper> xShapeMapper = XMLShapeExport::CreateShapePropMapper( *this );
2321 GetShapeExport(); // make sure the graphics styles family is added
2323 const std::vector<ScNoteStyleEntry>& rNoteEntries = pSheetData->GetNoteStyles();
2324 std::vector<ScNoteStyleEntry>::const_iterator aNoteIter = rNoteEntries.begin();
2325 std::vector<ScNoteStyleEntry>::const_iterator aNoteEnd = rNoteEntries.end();
2326 while (aNoteIter != aNoteEnd)
2328 ScAddress aPos = aNoteIter->maCellPos;
2329 sal_Int32 nTable = aPos.Tab();
2330 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2331 if (bCopySheet)
2333 //! separate method AddStyleFromNote needed?
2335 ScPostIt* pNote = pDoc->GetNote( aPos );
2336 DBG_ASSERT( pNote, "note not found" );
2337 if (pNote)
2339 SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2340 // all uno shapes are created anyway in CollectSharedData
2341 uno::Reference<beans::XPropertySet> xShapeProperties( pDrawObj->getUnoShape(), uno::UNO_QUERY );
2342 if (xShapeProperties.is())
2344 if ( aNoteIter->maStyleName.getLength() )
2346 std::vector<XMLPropertyState> xPropStates(xShapeMapper->Filter(xShapeProperties));
2347 rtl::OUString sParent;
2348 rtl::OUString sName( aNoteIter->maStyleName );
2349 GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_SD_GRAPHICS_ID, sParent, xPropStates);
2350 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_SD_GRAPHICS_ID, sName);
2352 if ( aNoteIter->maTextStyle.getLength() )
2354 std::vector<XMLPropertyState> xPropStates(
2355 GetTextParagraphExport()->GetParagraphPropertyMapper()->Filter(xShapeProperties));
2356 rtl::OUString sParent;
2357 rtl::OUString sName( aNoteIter->maTextStyle );
2358 GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_PARAGRAPH, sParent, xPropStates);
2359 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_PARAGRAPH, sName);
2364 ++aNoteIter;
2367 // note paragraph styles
2369 //UniReference<SvXMLExportPropertyMapper> xParaPropMapper = XMLTextParagraphExport::CreateParaExtPropMapper( *this );
2370 UniReference<SvXMLExportPropertyMapper> xParaPropMapper = GetTextParagraphExport()->GetParagraphPropertyMapper();
2372 const std::vector<ScTextStyleEntry>& rNoteParaEntries = pSheetData->GetNoteParaStyles();
2373 std::vector<ScTextStyleEntry>::const_iterator aNoteParaIter = rNoteParaEntries.begin();
2374 std::vector<ScTextStyleEntry>::const_iterator aNoteParaEnd = rNoteParaEntries.end();
2375 while (aNoteParaIter != aNoteParaEnd)
2377 ScAddress aPos = aNoteParaIter->maCellPos;
2378 sal_Int32 nTable = aPos.Tab();
2379 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2380 if (bCopySheet)
2382 ScPostIt* pNote = pDoc->GetNote( aPos );
2383 DBG_ASSERT( pNote, "note not found" );
2384 if (pNote)
2386 SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2387 uno::Reference<container::XEnumerationAccess> xCellText(pDrawObj->getUnoShape(), uno::UNO_QUERY);
2388 uno::Reference<beans::XPropertySet> xParaProp(
2389 lcl_GetEnumerated( xCellText, aNoteParaIter->maSelection.nStartPara ), uno::UNO_QUERY );
2390 if ( xParaProp.is() )
2392 std::vector<XMLPropertyState> xPropStates(xParaPropMapper->Filter(xParaProp));
2393 rtl::OUString sParent;
2394 rtl::OUString sName( aNoteParaIter->maName );
2395 GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_PARAGRAPH, sParent, xPropStates);
2396 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_PARAGRAPH, sName);
2400 ++aNoteParaIter;
2403 // note text styles
2405 UniReference<SvXMLExportPropertyMapper> xTextPropMapper = XMLTextParagraphExport::CreateCharExtPropMapper( *this );
2407 const std::vector<ScTextStyleEntry>& rNoteTextEntries = pSheetData->GetNoteTextStyles();
2408 std::vector<ScTextStyleEntry>::const_iterator aNoteTextIter = rNoteTextEntries.begin();
2409 std::vector<ScTextStyleEntry>::const_iterator aNoteTextEnd = rNoteTextEntries.end();
2410 while (aNoteTextIter != aNoteTextEnd)
2412 ScAddress aPos = aNoteTextIter->maCellPos;
2413 sal_Int32 nTable = aPos.Tab();
2414 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2415 if (bCopySheet)
2417 ScPostIt* pNote = pDoc->GetNote( aPos );
2418 DBG_ASSERT( pNote, "note not found" );
2419 if (pNote)
2421 SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2422 uno::Reference<text::XSimpleText> xCellText(pDrawObj->getUnoShape(), uno::UNO_QUERY);
2423 uno::Reference<beans::XPropertySet> xCursorProp(xCellText->createTextCursor(), uno::UNO_QUERY);
2424 ScDrawTextCursor* pCursor = ScDrawTextCursor::getImplementation( xCursorProp );
2425 if (pCursor)
2427 pCursor->SetSelection( aNoteTextIter->maSelection );
2429 std::vector<XMLPropertyState> xPropStates(xTextPropMapper->Filter(xCursorProp));
2430 rtl::OUString sParent;
2431 rtl::OUString sName( aNoteTextIter->maName );
2432 GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_TEXT, sParent, xPropStates);
2433 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_TEXT, sName);
2437 ++aNoteTextIter;
2440 // stored text styles
2442 //UniReference<SvXMLExportPropertyMapper> xTextPropMapper = XMLTextParagraphExport::CreateCharExtPropMapper( *this );
2444 const std::vector<ScTextStyleEntry>& rTextEntries = pSheetData->GetTextStyles();
2445 std::vector<ScTextStyleEntry>::const_iterator aTextIter = rTextEntries.begin();
2446 std::vector<ScTextStyleEntry>::const_iterator aTextEnd = rTextEntries.end();
2447 while (aTextIter != aTextEnd)
2449 ScAddress aPos = aTextIter->maCellPos;
2450 sal_Int32 nTable = aPos.Tab();
2451 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2452 if (bCopySheet)
2454 //! separate method AddStyleFromText needed?
2455 //! cache sheet object
2457 uno::Reference<table::XCellRange> xCellRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2458 uno::Reference<text::XSimpleText> xCellText(xCellRange->getCellByPosition(aPos.Col(), aPos.Row()), uno::UNO_QUERY);
2459 uno::Reference<beans::XPropertySet> xCursorProp(xCellText->createTextCursor(), uno::UNO_QUERY);
2460 ScCellTextCursor* pCursor = ScCellTextCursor::getImplementation( xCursorProp );
2461 if (pCursor)
2463 pCursor->SetSelection( aTextIter->maSelection );
2465 std::vector<XMLPropertyState> xPropStates(xTextPropMapper->Filter(xCursorProp));
2466 rtl::OUString sParent;
2467 rtl::OUString sName( aTextIter->maName );
2468 GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_TEXT, sParent, xPropStates);
2469 GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_TEXT, sName);
2472 ++aTextIter;
2476 ExportExternalRefCacheStyles();
2478 if (!pSharedData)
2480 sal_Int32 nTableCount(0);
2481 sal_Int32 nShapesCount(0);
2482 sal_Int32 nCellCount(pDoc ? pDoc->GetCellCount() : 0);
2483 CollectSharedData(nTableCount, nShapesCount, nCellCount);
2484 //DBG_ERROR("no shared data setted");
2486 sal_Int32 nTableCount(xIndex->getCount());
2487 pCellStyles->AddNewTable(nTableCount - 1);
2488 CollectShapesAutoStyles(nTableCount);
2489 for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable)
2491 bool bUseStream = pSheetData && pDoc && pDoc->IsStreamValid((SCTAB)nTable) &&
2492 pSheetData->HasStreamPos(nTable) && xSourceStream.is();
2494 uno::Reference <sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2495 if (xTable.is())
2497 // table styles array must be complete, including copied tables - Add should find the stored style
2498 uno::Reference<beans::XPropertySet> xTableProperties(xTable, uno::UNO_QUERY);
2499 if (xTableProperties.is())
2501 std::vector<XMLPropertyState> xPropStates(xTableStylesExportPropertySetMapper->Filter(xTableProperties));
2502 if(xPropStates.size())
2504 rtl::OUString sParent;
2505 rtl::OUString sName;
2506 GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_TABLE, sParent, xPropStates);
2507 aTableStyles.push_back(sName);
2511 // collect other auto-styles only for non-copied sheets
2512 if (xTable.is() && !bUseStream)
2514 uno::Reference<sheet::XUniqueCellFormatRangesSupplier> xCellFormatRanges ( xTable, uno::UNO_QUERY );
2515 if ( xCellFormatRanges.is() )
2517 uno::Reference<container::XIndexAccess> xFormatRangesIndex(xCellFormatRanges->getUniqueCellFormatRanges());
2518 if (xFormatRangesIndex.is())
2520 sal_Int32 nFormatRangesCount(xFormatRangesIndex->getCount());
2521 GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nFormatRangesCount);
2522 for (sal_Int32 nFormatRange = 0; nFormatRange < nFormatRangesCount; ++nFormatRange)
2524 uno::Reference< sheet::XSheetCellRanges> xCellRanges(xFormatRangesIndex->getByIndex(nFormatRange), uno::UNO_QUERY);
2525 if (xCellRanges.is())
2527 uno::Reference <beans::XPropertySet> xProperties (xCellRanges, uno::UNO_QUERY);
2528 if (xProperties.is())
2530 AddStyleFromCells(xProperties, xTable, nTable, NULL);
2531 IncrementProgressBar(sal_False);
2537 uno::Reference<table::XColumnRowRange> xColumnRowRange (xTable, uno::UNO_QUERY);
2538 if (xColumnRowRange.is())
2540 if (pDoc)
2542 pDoc->SyncColRowFlags();
2543 uno::Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns());
2544 if (xTableColumns.is())
2546 sal_Int32 nColumns(pDoc->GetLastChangedCol(sal::static_int_cast<SCTAB>(nTable)));
2547 pSharedData->SetLastColumn(nTable, nColumns);
2548 table::CellRangeAddress aCellAddress(GetEndAddress(xTable, nTable));
2549 if (aCellAddress.EndColumn > nColumns)
2551 ++nColumns;
2552 pColumnStyles->AddNewTable(nTable, aCellAddress.EndColumn);
2554 // else if (nColumns < MAXCOL)
2555 // pColumnStyles->AddNewTable(nTable, ++nColumns);
2556 else
2557 pColumnStyles->AddNewTable(nTable, nColumns);
2558 sal_Int32 nColumn = 0;
2559 while (/*nColumn <= nColumns && */nColumn <= MAXCOL)
2561 sal_Int32 nIndex(-1);
2562 sal_Bool bIsVisible(sal_True);
2563 uno::Reference <beans::XPropertySet> xColumnProperties(xTableColumns->getByIndex(nColumn), uno::UNO_QUERY);
2564 if (xColumnProperties.is())
2566 AddStyleFromColumn( xColumnProperties, NULL, nIndex, bIsVisible );
2567 //if(xPropStates.size())
2568 pColumnStyles->AddFieldStyleName(nTable, nColumn, nIndex, bIsVisible);
2570 sal_Int32 nOld(nColumn);
2571 nColumn = pDoc->GetNextDifferentChangedCol(sal::static_int_cast<SCTAB>(nTable), static_cast<SCCOL>(nColumn));
2572 for (sal_Int32 i = nOld + 1; i < nColumn; ++i)
2573 pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
2575 if (aCellAddress.EndColumn > nColumns)
2577 sal_Bool bIsVisible(sal_True);
2578 sal_Int32 nIndex(pColumnStyles->GetStyleNameIndex(nTable, nColumns, bIsVisible));
2579 for (sal_Int32 i = nColumns + 1; i <= aCellAddress.EndColumn; ++i)
2580 pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
2583 uno::Reference<table::XTableRows> xTableRows(xColumnRowRange->getRows());
2584 if (xTableRows.is())
2586 sal_Int32 nRows(pDoc->GetLastChangedRow(sal::static_int_cast<SCTAB>(nTable)));
2587 pSharedData->SetLastRow(nTable, nRows);
2588 table::CellRangeAddress aCellAddress(GetEndAddress(xTable, nTable));
2589 if (aCellAddress.EndRow > nRows)
2591 ++nRows;
2592 pRowStyles->AddNewTable(nTable, aCellAddress.EndRow);
2594 // else if (nRows < MAXROW)
2595 // pRowStyles->AddNewTable(nTable, ++nRows);
2596 else
2597 pRowStyles->AddNewTable(nTable, nRows);
2598 sal_Int32 nRow = 0;
2599 while (nRow <= nRows && nRow <= MAXROW)
2601 sal_Int32 nIndex = 0;
2602 uno::Reference <beans::XPropertySet> xRowProperties(xTableRows->getByIndex(nRow), uno::UNO_QUERY);
2603 if(xRowProperties.is())
2605 AddStyleFromRow( xRowProperties, NULL, nIndex );
2606 //if(xPropStates.size())
2607 pRowStyles->AddFieldStyleName(nTable, nRow, nIndex);
2609 sal_Int32 nOld(nRow);
2610 nRow = pDoc->GetNextDifferentChangedRow(sal::static_int_cast<SCTAB>(nTable), static_cast<SCROW>(nRow), false);
2611 for (sal_Int32 i = nOld + 1; i < nRow; ++i)
2612 pRowStyles->AddFieldStyleName(nTable, i, nIndex);
2614 if (aCellAddress.EndRow > nRows)
2616 sal_Int32 nIndex(pRowStyles->GetStyleNameIndex(nTable, nRows));
2617 for (sal_Int32 i = nRows + 1; i <= aCellAddress.EndRow; ++i)
2618 pRowStyles->AddFieldStyleName(nTable, i, nIndex);
2623 uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery (xTable, uno::UNO_QUERY);
2624 if (xCellRangesQuery.is())
2626 uno::Reference<sheet::XSheetCellRanges> xSheetCellRanges(xCellRangesQuery->queryContentCells(sheet::CellFlags::FORMATTED));
2627 uno::Reference<sheet::XSheetOperation> xSheetOperation(xSheetCellRanges, uno::UNO_QUERY);
2628 if (xSheetCellRanges.is() && xSheetOperation.is())
2630 sal_uInt32 nCount(sal_uInt32(xSheetOperation->computeFunction(sheet::GeneralFunction_COUNT)));
2631 uno::Reference<container::XEnumerationAccess> xCellsAccess(xSheetCellRanges->getCells());
2632 if (xCellsAccess.is())
2634 GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nCount);
2635 uno::Reference<container::XEnumeration> xCells(xCellsAccess->createEnumeration());
2636 if (xCells.is())
2638 sal_uInt32 nCount2(0);
2639 while (xCells->hasMoreElements())
2641 uno::Reference<text::XText> xText(xCells->nextElement(), uno::UNO_QUERY);
2642 if (xText.is())
2643 GetTextParagraphExport()->collectTextAutoStyles(xText, sal_False, sal_False);
2644 ++nCount2;
2645 IncrementProgressBar(sal_False);
2647 if(nCount2 > nCount)
2648 GetProgressBarHelper()->SetReference(GetProgressBarHelper()->GetReference() + nCount2 - nCount);
2654 IncrementProgressBar(sal_False);
2656 pChangeTrackingExportHelper->CollectAutoStyles();
2658 GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_COLUMN,
2659 GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2660 GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_ROW,
2661 GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2662 GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_TABLE,
2663 GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2664 exportAutoDataStyles();
2665 GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_CELL,
2666 GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
2668 GetShapeExport()->exportAutoStyles();
2669 GetFormExport()->exportAutoStyles( );
2672 // Special table style for the external ref cache tables.
2673 AddAttribute(XML_NAMESPACE_STYLE, XML_NAME, sExternalRefTabStyleName);
2674 AddAttribute(XML_NAMESPACE_STYLE, XML_FAMILY, XML_TABLE);
2675 SvXMLElementExport aElemStyle(*this, XML_NAMESPACE_STYLE, XML_STYLE, sal_True, sal_True);
2676 AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_FALSE);
2677 SvXMLElementExport aElemStyleTabProps(*this, XML_NAMESPACE_STYLE, XML_TABLE_PROPERTIES, sal_True, sal_True);
2680 if (getExportFlags() & EXPORT_MASTERSTYLES)
2682 GetPageExport()->collectAutoStyles(sal_True);
2683 GetPageExport()->exportAutoStyles();
2686 // #i30251#; only write Text Styles once
2688 if ((getExportFlags() & EXPORT_CONTENT) || (getExportFlags() & EXPORT_MASTERSTYLES))
2689 GetTextParagraphExport()->exportTextAutoStyles();
2695 void ScXMLExport::_ExportMasterStyles()
2697 GetPageExport()->exportMasterStyles( sal_True );
2700 void ScXMLExport::CollectInternalShape( uno::Reference< drawing::XShape > xShape )
2702 // detective objects and notes
2703 if( SvxShape* pShapeImp = SvxShape::getImplementation( xShape ) )
2705 if( SdrObject* pObject = pShapeImp->GetSdrObject() )
2707 // collect note caption objects from all layers (internal or hidden)
2708 if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, static_cast< SCTAB >( nCurrentTable ) ) )
2710 pSharedData->AddNoteObj( xShape, pCaptData->maStart );
2712 // #i60851# When the file is saved while editing a new note,
2713 // the cell is still empty -> last column/row must be updated
2714 DBG_ASSERT( pCaptData->maStart.Tab() == nCurrentTable, "invalid table in object data" );
2715 pSharedData->SetLastColumn( nCurrentTable, pCaptData->maStart.Col() );
2716 pSharedData->SetLastRow( nCurrentTable, pCaptData->maStart.Row() );
2718 // other objects from internal layer only (detective)
2719 else if( pObject->GetLayer() == SC_LAYER_INTERN )
2721 ScDetectiveFunc aDetFunc( pDoc, static_cast<SCTAB>(nCurrentTable) );
2722 ScAddress aPosition;
2723 ScRange aSourceRange;
2724 sal_Bool bRedLine;
2725 ScDetectiveObjType eObjType = aDetFunc.GetDetectiveObjectType(
2726 pObject, nCurrentTable, aPosition, aSourceRange, bRedLine );
2727 pSharedData->GetDetectiveObjContainer()->AddObject( eObjType, static_cast<SCTAB>(nCurrentTable), aPosition, aSourceRange, bRedLine );
2733 //UNUSED2008-05 sal_Bool ScXMLExport::GetMerge (const uno::Reference <sheet::XSpreadsheet>& xTable,
2734 //UNUSED2008-05 const sal_Int32 nCol, const sal_Int32 nRow,
2735 //UNUSED2008-05 table::CellRangeAddress& aCellAddress)
2736 //UNUSED2008-05 {
2737 //UNUSED2008-05 uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xTable->getCellRangeByPosition(nCol, nRow, nCol, nRow), uno::UNO_QUERY);
2738 //UNUSED2008-05 if (xSheetCellRange.is())
2739 //UNUSED2008-05 {
2740 //UNUSED2008-05 uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursorByRange(xSheetCellRange));
2741 //UNUSED2008-05 if (xCursor.is())
2742 //UNUSED2008-05 {
2743 //UNUSED2008-05 uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
2744 //UNUSED2008-05 xCursor->collapseToMergedArea();
2745 //UNUSED2008-05 aCellAddress = xCellAddress->getRangeAddress();
2746 //UNUSED2008-05 return sal_True;
2747 //UNUSED2008-05 }
2748 //UNUSED2008-05 }
2749 //UNUSED2008-05 return sal_False;
2750 //UNUSED2008-05 }
2752 sal_Bool ScXMLExport::GetMerged (const table::CellRangeAddress* pCellAddress,
2753 const uno::Reference <sheet::XSpreadsheet>& xTable)
2755 sal_Bool bReady(sal_False);
2756 sal_Int32 nRow(pCellAddress->StartRow);
2757 sal_Int32 nCol(pCellAddress->StartColumn);
2758 sal_Int32 nEndRow(pCellAddress->EndRow);
2759 sal_Int32 nEndCol(pCellAddress->EndColumn);
2760 sal_Bool bRowInc(nEndRow > nRow);
2761 while(!bReady && nRow <= nEndRow && nCol <= nEndCol)
2763 uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xTable->getCellRangeByPosition(nCol, nRow, nCol, nRow), uno::UNO_QUERY);
2764 if (xSheetCellRange.is())
2766 uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursorByRange(xSheetCellRange));
2767 if(xCursor.is())
2769 uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
2770 xCursor->collapseToMergedArea();
2771 table::CellRangeAddress aCellAddress2(xCellAddress->getRangeAddress());
2772 if ((aCellAddress2.EndRow > nRow ||
2773 aCellAddress2.EndColumn > nCol) &&
2774 aCellAddress2.StartRow == nRow &&
2775 aCellAddress2.StartColumn == nCol)
2777 pMergedRangesContainer->AddRange(aCellAddress2);
2778 pSharedData->SetLastColumn(aCellAddress2.Sheet, aCellAddress2.EndColumn);
2779 pSharedData->SetLastRow(aCellAddress2.Sheet, aCellAddress2.EndRow);
2781 else
2782 bReady = sal_True;
2785 if (!bReady)
2787 if (bRowInc)
2788 ++nRow;
2789 else
2790 ++nCol;
2793 DBG_ASSERT(!(!bReady && nEndRow > nRow && nEndCol > nCol), "should not be possible");
2794 return !bReady;
2797 //UNUSED2008-05 sal_Bool ScXMLExport::IsMatrix (const uno::Reference <table::XCellRange>& xCellRange,
2798 //UNUSED2008-05 const uno::Reference <sheet::XSpreadsheet>& xTable,
2799 //UNUSED2008-05 const sal_Int32 nCol, const sal_Int32 nRow,
2800 //UNUSED2008-05 table::CellRangeAddress& aCellAddress, sal_Bool& bIsFirst) const
2801 //UNUSED2008-05 {
2802 //UNUSED2008-05 bIsFirst = sal_False;
2803 //UNUSED2008-05 uno::Reference <sheet::XArrayFormulaRange> xArrayFormulaRange (xCellRange->getCellRangeByPosition(nCol,nRow,nCol,nRow), uno::UNO_QUERY);
2804 //UNUSED2008-05 if (xArrayFormulaRange.is())
2805 //UNUSED2008-05 {
2806 //UNUSED2008-05 rtl::OUString sArrayFormula(xArrayFormulaRange->getArrayFormula());
2807 //UNUSED2008-05 if (sArrayFormula.getLength())
2808 //UNUSED2008-05 {
2809 //UNUSED2008-05 uno::Reference<sheet::XSheetCellRange> xMatrixSheetCellRange (xArrayFormulaRange, uno::UNO_QUERY);
2810 //UNUSED2008-05 if (xMatrixSheetCellRange.is())
2811 //UNUSED2008-05 {
2812 //UNUSED2008-05 uno::Reference<sheet::XSheetCellCursor> xMatrixSheetCursor(xTable->createCursorByRange(xMatrixSheetCellRange));
2813 //UNUSED2008-05 if (xMatrixSheetCursor.is())
2814 //UNUSED2008-05 {
2815 //UNUSED2008-05 xMatrixSheetCursor->collapseToCurrentArray();
2816 //UNUSED2008-05 uno::Reference<sheet::XCellRangeAddressable> xMatrixCellAddress (xMatrixSheetCursor, uno::UNO_QUERY);
2817 //UNUSED2008-05 if (xMatrixCellAddress.is())
2818 //UNUSED2008-05 {
2819 //UNUSED2008-05 aCellAddress = xMatrixCellAddress->getRangeAddress();
2820 //UNUSED2008-05 if ((aCellAddress.StartColumn == nCol && aCellAddress.StartRow == nRow) &&
2821 //UNUSED2008-05 (aCellAddress.EndColumn > nCol || aCellAddress.EndRow > nRow))
2822 //UNUSED2008-05 {
2823 //UNUSED2008-05 bIsFirst = sal_True;
2824 //UNUSED2008-05 return sal_True;
2825 //UNUSED2008-05 }
2826 //UNUSED2008-05 else if (aCellAddress.StartColumn != nCol || aCellAddress.StartRow != nRow ||
2827 //UNUSED2008-05 aCellAddress.EndColumn != nCol || aCellAddress.EndRow != nRow)
2828 //UNUSED2008-05 return sal_True;
2829 //UNUSED2008-05 else
2830 //UNUSED2008-05 {
2831 //UNUSED2008-05 bIsFirst = sal_True;
2832 //UNUSED2008-05 return sal_True;
2833 //UNUSED2008-05 }
2834 //UNUSED2008-05 }
2835 //UNUSED2008-05 }
2836 //UNUSED2008-05 }
2837 //UNUSED2008-05 }
2838 //UNUSED2008-05 }
2839 //UNUSED2008-05 return sal_False;
2840 //UNUSED2008-05 }
2842 sal_Bool ScXMLExport::IsMatrix (const ScAddress& aCell,
2843 table::CellRangeAddress& aCellAddress, sal_Bool& bIsFirst) const
2845 bIsFirst = sal_False;
2847 ScRange aMatrixRange;
2849 if (pDoc && pDoc->GetMatrixFormulaRange(aCell, aMatrixRange))
2851 ScUnoConversion::FillApiRange( aCellAddress, aMatrixRange );
2852 if ((aCellAddress.StartColumn == aCell.Col() && aCellAddress.StartRow == aCell.Row()) &&
2853 (aCellAddress.EndColumn > aCell.Col() || aCellAddress.EndRow > aCell.Row()))
2855 bIsFirst = sal_True;
2856 return sal_True;
2858 else if (aCellAddress.StartColumn != aCell.Col() || aCellAddress.StartRow != aCell.Row() ||
2859 aCellAddress.EndColumn != aCell.Col() || aCellAddress.EndRow != aCell.Row())
2860 return sal_True;
2861 else
2863 bIsFirst = sal_True;
2864 return sal_True;
2868 return sal_False;
2870 /* uno::Reference <sheet::XArrayFormulaRange> xArrayFormulaRange (xCell, uno::UNO_QUERY);
2871 if (xArrayFormulaRange.is())
2873 rtl::OUString sArrayFormula(xArrayFormulaRange->getArrayFormula());
2874 if (sArrayFormula.getLength())
2876 uno::Reference<sheet::XSheetCellRange> xMatrixSheetCellRange (xCell, uno::UNO_QUERY);
2877 if (xMatrixSheetCellRange.is())
2879 uno::Reference<sheet::XSheetCellCursor> xMatrixSheetCursor(xTable->createCursorByRange(xMatrixSheetCellRange));
2880 if (xMatrixSheetCursor.is())
2882 xMatrixSheetCursor->collapseToCurrentArray();
2883 uno::Reference<sheet::XCellRangeAddressable> xMatrixCellAddress (xMatrixSheetCursor, uno::UNO_QUERY);
2884 if (xMatrixCellAddress.is())
2886 aCellAddress = xMatrixCellAddress->getRangeAddress();
2887 if ((aCellAddress.StartColumn == nCol && aCellAddress.StartRow == nRow) &&
2888 (aCellAddress.EndColumn > nCol || aCellAddress.EndRow > nRow))
2890 bIsFirst = sal_True;
2891 return sal_True;
2893 else if (aCellAddress.StartColumn != nCol || aCellAddress.StartRow != nRow ||
2894 aCellAddress.EndColumn != nCol || aCellAddress.EndRow != nRow)
2895 return sal_True;
2896 else
2898 bIsFirst = sal_True;
2899 return sal_True;
2906 return sal_False;*/
2909 sal_Bool ScXMLExport::GetCellText (ScMyCell& rMyCell, const ScAddress& aPos) const
2911 if (rMyCell.bHasStringValue)
2912 return sal_True;
2913 else
2915 /* if (!rMyCell.bHasXText)
2917 rMyCell.xText.set(xCurrentTableCellRange->getCellByPosition(rMyCell.aCellAddress.Column, rMyCell.aCellAddress.Row), uno::UNO_QUERY);
2918 rMyCell.bHasXText = sal_True;
2920 // if (rMyCell.xText.is())
2921 // {
2922 rMyCell.sStringValue = ScCellObj::GetOutputString_Impl(pDoc, aPos);
2923 rMyCell.bHasStringValue = sal_True;
2924 return sal_True;
2925 // }
2929 void ScXMLExport::WriteCell (ScMyCell& aCell)
2931 ScAddress aCellPos;
2932 ScUnoConversion::FillScAddress( aCellPos, aCell.aCellAddress );
2933 if (aCell.nStyleIndex != -1)
2934 AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(aCell.nStyleIndex, aCell.bIsAutoStyle));
2935 if (aCell.nValidationIndex > -1)
2936 AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(aCell.nValidationIndex));
2937 sal_Bool bIsMatrix(aCell.bIsMatrixBase || aCell.bIsMatrixCovered);
2938 sal_Bool bIsFirstMatrixCell(aCell.bIsMatrixBase);
2939 if (bIsFirstMatrixCell)
2941 sal_Int32 nColumns(aCell.aMatrixRange.EndColumn - aCell.aMatrixRange.StartColumn + 1);
2942 sal_Int32 nRows(aCell.aMatrixRange.EndRow - aCell.aMatrixRange.StartRow + 1);
2943 rtl::OUStringBuffer sColumns;
2944 rtl::OUStringBuffer sRows;
2945 SvXMLUnitConverter::convertNumber(sColumns, nColumns);
2946 SvXMLUnitConverter::convertNumber(sRows, nRows);
2947 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_MATRIX_COLUMNS_SPANNED, sColumns.makeStringAndClear());
2948 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_MATRIX_ROWS_SPANNED, sRows.makeStringAndClear());
2950 sal_Bool bIsEmpty(sal_False);
2951 switch (aCell.nType)
2953 case table::CellContentType_EMPTY :
2955 bIsEmpty = sal_True;
2957 break;
2958 case table::CellContentType_VALUE :
2960 if (!aCell.bHasDoubleValue)
2962 aCell.fValue = pDoc->GetValue( aCellPos );
2963 aCell.bHasDoubleValue = sal_True;
2965 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2966 aCell.nNumberFormat, aCell.fValue);
2968 break;
2969 case table::CellContentType_TEXT :
2971 if (GetCellText(aCell, aCellPos))
2973 rtl::OUString sFormula(lcl_GetRawString(pDoc, aCellPos));
2974 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
2975 sFormula, aCell.sStringValue, sal_True, sal_True);
2978 break;
2979 case table::CellContentType_FORMULA :
2981 ScBaseCell* pBaseCell = pDoc ? pDoc->GetCell(aCellPos) : NULL;
2982 if (pBaseCell && pBaseCell->GetCellType() == CELLTYPE_FORMULA)
2984 rtl::OUStringBuffer sFormula;
2985 ScFormulaCell* pFormulaCell((ScFormulaCell*) pBaseCell);
2986 if (!bIsMatrix || (bIsMatrix && bIsFirstMatrixCell))
2988 const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
2989 sal_uInt16 nNamespacePrefix = (eGrammar == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
2990 pFormulaCell->GetFormula(sFormula, eGrammar);
2991 rtl::OUString sOUFormula(sFormula.makeStringAndClear());
2992 if (!bIsMatrix)
2994 AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sOUFormula, sal_False ));
2996 else
2998 AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sOUFormula.copy(1, sOUFormula.getLength() - 2), sal_False ));
3001 if (pFormulaCell->IsValue())
3003 sal_Bool bIsStandard;
3004 rtl::OUString sCurrency;
3005 GetNumberFormatAttributesExportHelper()->GetCellType(aCell.nNumberFormat, sCurrency, bIsStandard);
3006 if (bIsStandard)
3008 if (pDoc)
3009 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
3010 pFormulaCell->GetStandardFormat(*pDoc->GetFormatTable(), 0),
3011 pDoc->GetValue( aCellPos ));
3013 else
3014 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
3015 aCell.nNumberFormat, pDoc->GetValue( aCellPos ));
3017 else
3019 if (GetCellText(aCell, aCellPos))
3020 if (aCell.sStringValue.getLength())
3022 AddAttribute(sAttrValueType, XML_STRING);
3023 AddAttribute(sAttrStringValue, aCell.sStringValue);
3028 break;
3029 default:
3031 // added to avoid warnings
3034 rtl::OUString* pCellString(&sElemCell);
3035 if (aCell.bIsCovered)
3037 pCellString = &sElemCoveredCell;
3039 else
3041 if (aCell.bIsMergedBase)
3043 sal_Int32 nColumns(aCell.aMergeRange.EndColumn - aCell.aMergeRange.StartColumn + 1);
3044 sal_Int32 nRows(aCell.aMergeRange.EndRow - aCell.aMergeRange.StartRow + 1);
3045 rtl::OUStringBuffer sColumns;
3046 rtl::OUStringBuffer sRows;
3047 SvXMLUnitConverter::convertNumber(sColumns, nColumns);
3048 SvXMLUnitConverter::convertNumber(sRows, nRows);
3049 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED, sColumns.makeStringAndClear());
3050 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED, sRows.makeStringAndClear());
3053 SvXMLElementExport aElemC(*this, *pCellString, sal_True, sal_True);
3054 CheckAttrList();
3055 WriteAreaLink(aCell);
3056 WriteAnnotation(aCell);
3057 WriteDetective(aCell);
3059 sal_Bool bEditCell = sal_False;
3061 if (!bIsEmpty)
3063 if ((aCell.nType == table::CellContentType_TEXT && IsEditCell(aCell)) ||
3064 (aCell.nType == table::CellContentType_FORMULA && IsMultiLineFormulaCell(aCell)))
3066 bEditCell = sal_True;
3067 uno::Reference<text::XText> xText(xCurrentTableCellRange->getCellByPosition(aCell.aCellAddress.Column, aCell.aCellAddress.Row), uno::UNO_QUERY);
3068 if ( xText.is())
3069 GetTextParagraphExport()->exportText(xText, sal_False, sal_False);
3071 else
3073 SvXMLElementExport aElemP(*this, sElemP, sal_True, sal_False);
3074 sal_Bool bPrevCharWasSpace(sal_True);
3075 if (GetCellText(aCell, aCellPos))
3076 GetTextParagraphExport()->exportText(aCell.sStringValue, bPrevCharWasSpace);
3079 WriteShapes(aCell);
3080 if (!bIsEmpty)
3081 IncrementProgressBar(bEditCell);
3084 void ScXMLExport::ExportShape(const uno::Reference < drawing::XShape >& xShape, awt::Point* pPoint)
3086 uno::Reference < beans::XPropertySet > xShapeProps ( xShape, uno::UNO_QUERY );
3087 //BM sal_Bool bMemChart(sal_False); // das muss man jetzt umbenennen :-)
3088 bool bIsChart( false );
3089 rtl::OUString sPropCLSID (RTL_CONSTASCII_USTRINGPARAM("CLSID"));
3090 rtl::OUString sPropModel (RTL_CONSTASCII_USTRINGPARAM("Model"));
3091 rtl::OUString sPersistName (RTL_CONSTASCII_USTRINGPARAM("PersistName"));
3092 if (xShapeProps.is())
3094 sal_Int32 nZOrder = 0;
3095 if (xShapeProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ZOrder"))) >>= nZOrder)
3097 rtl::OUStringBuffer sBuffer;
3098 GetMM100UnitConverter().convertNumber(sBuffer, nZOrder);
3099 AddAttribute(XML_NAMESPACE_DRAW, XML_ZINDEX, sBuffer.makeStringAndClear());
3101 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xShapeProps->getPropertySetInfo();
3102 if( xPropSetInfo->hasPropertyByName( sPropCLSID ) )
3104 rtl::OUString sCLSID;
3105 if (xShapeProps->getPropertyValue( sPropCLSID ) >>= sCLSID)
3107 if ( sCLSID.equalsIgnoreAsciiCase(GetChartExport()->getChartCLSID()) )
3109 // we have a chart
3110 uno::Reference< frame::XModel > xChartModel;
3111 if( ( xShapeProps->getPropertyValue( sPropModel ) >>= xChartModel ) &&
3112 xChartModel.is())
3114 uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
3115 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartModel, uno::UNO_QUERY );
3116 if( xChartDoc.is() && xReceiver.is() &&
3117 ! xChartDoc->hasInternalDataProvider())
3119 // we have a chart that gets its data from Calc
3120 bIsChart = true;
3121 uno::Sequence< ::rtl::OUString > aRepresentations(
3122 xReceiver->getUsedRangeRepresentations());
3123 SvXMLAttributeList* pAttrList = 0;
3124 if(aRepresentations.getLength())
3126 // add the ranges used by the chart to the shape
3127 // element to be able to start listening after
3128 // load (when the chart is not yet loaded)
3129 uno::Reference< chart2::data::XRangeXMLConversion > xRangeConverter( xChartDoc->getDataProvider(), uno::UNO_QUERY );
3130 ::rtl::OUString sRanges( lcl_RangeSequenceToString( aRepresentations, xRangeConverter ));
3131 pAttrList = new SvXMLAttributeList();
3132 pAttrList->AddAttribute(
3133 GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken(XML_NOTIFY_ON_UPDATE_OF_RANGES) ), sRanges );
3135 GetShapeExport()->exportShape(xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList);
3139 //BM rtl::OUString sOUName;
3140 //BM xShapeProps->getPropertyValue(sPersistName) >>= sOUName;
3141 //BM String sName(sOUName);
3142 //BM if (!pChartListener)
3143 //BM {
3144 //BM String aEmptyString;
3145 //BM ScRange aRange;
3146 //BM pChartListener = new ScChartListener ( aEmptyString, GetDocument(), aRange );
3147 //BM }
3148 //BM if(pChartListener)
3149 //BM {
3150 //BM USHORT nIndex(0);
3151 //BM pChartListener->SetString( sName );
3152 //BM if ( GetDocument() && GetDocument()->GetChartListenerCollection()->Search( pChartListener, nIndex ) )
3153 //BM {
3154 //BM const ScRangeListRef& rRangeListRef(((ScChartListener*)
3155 //BM (GetDocument()->GetChartListenerCollection()->
3156 //BM At( nIndex )))->GetRangeList());
3157 //BM if (rRangeListRef.Is())
3158 //BM {
3159 //BM bMemChart = sal_True;
3160 //BM rtl::OUString sRanges;
3161 //BM ScRangeStringConverter::GetStringFromRangeList(sRanges, rRangeListRef, GetDocument());
3162 //BM SvXMLAttributeList* pAttrList = NULL;
3163 //BM if (sRanges.getLength())
3164 //BM {
3165 //BM pAttrList = new SvXMLAttributeList();
3166 //BM pAttrList->AddAttribute(
3167 //BM GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken(XML_NOTIFY_ON_UPDATE_OF_RANGES) ), sRanges );
3168 //BM }
3169 //BM GetShapeExport()->exportShape(xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList);
3170 //BM }
3171 //BM }
3172 //BM else
3173 //BM {
3174 //BM bMemChart = sal_True;
3175 //BM SvXMLAttributeList* pAttrList = new SvXMLAttributeList();
3176 //BM pAttrList->AddAttribute(
3177 //BM GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken(XML_NOTIFY_ON_UPDATE_OF_RANGES) ), rtl::OUString() );
3178 //BM GetShapeExport()->exportShape(xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList);
3179 //BM }
3180 //BM }
3182 /* SchMemChart* pMemChart = pDoc->FindChartData(sName);
3183 if (pMemChart && pMemChart->GetSeriesAddresses().getLength())
3185 bMemChart = sal_True;
3186 rtl::OUString sRanges(pMemChart->getXMLStringForChartRange());
3187 if (sRanges.getLength())
3188 AddAttribute(XML_NAMESPACE_DRAW, XML_NOTIFY_ON_UPDATE_OF_RANGES, sRanges);
3189 GetShapeExport()->exportShape(xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint);
3195 if (!bIsChart)
3197 // #i66550 HLINK_FOR_SHAPES
3198 rtl::OUString sHlink;
3199 uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
3200 if ( xProps.is() )
3201 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_HYPERLINK ) ) ) >>= sHlink;
3203 std::auto_ptr< SvXMLElementExport > pDrawA;
3204 // enlose shapes with <draw:a> element only if sHlink contains something
3205 if ( sHlink.getLength() > 0 )
3207 // need to get delete the attributes that are pre-loaded
3208 // for the shape export ( otherwise they will become
3209 // attributes of the draw:a element ) This *shouldn't*
3210 // affect performance adversely as there are only a
3211 // couple of attributes involved
3212 uno::Reference< xml::sax::XAttributeList > xSaveAttribs( new SvXMLAttributeList( GetAttrList() ) );
3213 ClearAttrList();
3214 // Add Hlink
3215 AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
3216 AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sHlink);
3217 pDrawA.reset( new SvXMLElementExport( *this, XML_NAMESPACE_DRAW, XML_A, sal_False, sal_False ) );
3218 // Attribute list has been cleared by previous operation
3219 // re-add pre-loaded attributes
3220 AddAttributeList( xSaveAttribs );
3222 GetShapeExport()->exportShape(xShape, SEF_DEFAULT, pPoint);
3224 IncrementProgressBar(sal_False);
3227 void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
3229 if( rMyCell.bHasShape && !rMyCell.aShapeList.empty() && pDoc )
3231 awt::Point aPoint;
3232 Rectangle aRec = pDoc->GetMMRect(static_cast<SCCOL>(rMyCell.aCellAddress.Column), static_cast<SCROW>(rMyCell.aCellAddress.Row),
3233 static_cast<SCCOL>(rMyCell.aCellAddress.Column), static_cast<SCROW>(rMyCell.aCellAddress.Row), static_cast<SCTAB>(rMyCell.aCellAddress.Sheet));
3234 BOOL bNegativePage(pDoc->IsNegativePage(rMyCell.aCellAddress.Sheet));
3235 if (bNegativePage)
3236 aPoint.X = aRec.Right();
3237 else
3238 aPoint.X = aRec.Left();
3239 aPoint.Y = aRec.Top();
3240 ScMyShapeList::const_iterator aItr = rMyCell.aShapeList.begin();
3241 ScMyShapeList::const_iterator aEndItr(rMyCell.aShapeList.end());
3242 while (aItr != aEndItr)
3244 if (aItr->xShape.is())
3246 if (bNegativePage)
3247 aPoint.X = 2 * aItr->xShape->getPosition().X + aItr->xShape->getSize().Width - aPoint.X;
3248 if ( !aItr->xShape->getShapeType().equals(sCaptionShape) )
3250 awt::Point aEndPoint;
3251 Rectangle aEndRec(pDoc->GetMMRect(aItr->aEndAddress.Col(), aItr->aEndAddress.Row(),
3252 aItr->aEndAddress.Col(), aItr->aEndAddress.Row(), aItr->aEndAddress.Tab()));
3253 rtl::OUString sEndAddress;
3254 ScRangeStringConverter::GetStringFromAddress(sEndAddress, aItr->aEndAddress, pDoc, FormulaGrammar::CONV_OOO);
3255 AddAttribute(XML_NAMESPACE_TABLE, XML_END_CELL_ADDRESS, sEndAddress);
3256 if (bNegativePage)
3257 aEndPoint.X = -aEndRec.Right();
3258 else
3259 aEndPoint.X = aEndRec.Left();
3260 aEndPoint.Y = aEndRec.Top();
3261 awt::Point aStartPoint(aItr->xShape->getPosition());
3262 awt::Size aSize(aItr->xShape->getSize());
3263 sal_Int32 nEndX;
3264 if (bNegativePage)
3265 nEndX = -aStartPoint.X - aEndPoint.X;
3266 else
3267 nEndX = aStartPoint.X + aSize.Width - aEndPoint.X;
3268 sal_Int32 nEndY(aStartPoint.Y + aSize.Height - aEndPoint.Y);
3269 rtl::OUStringBuffer sBuffer;
3270 GetMM100UnitConverter().convertMeasure(sBuffer, nEndX);
3271 AddAttribute(XML_NAMESPACE_TABLE, XML_END_X, sBuffer.makeStringAndClear());
3272 GetMM100UnitConverter().convertMeasure(sBuffer, nEndY);
3273 AddAttribute(XML_NAMESPACE_TABLE, XML_END_Y, sBuffer.makeStringAndClear());
3275 ExportShape(aItr->xShape, &aPoint);
3277 ++aItr;
3282 void ScXMLExport::WriteTableShapes()
3284 ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
3285 if (pTableShapes && !(*pTableShapes)[nCurrentTable].empty())
3287 DBG_ASSERT(pTableShapes->size() > static_cast<size_t>(nCurrentTable), "wrong Table");
3288 SvXMLElementExport aShapesElem(*this, XML_NAMESPACE_TABLE, XML_SHAPES, sal_True, sal_False);
3289 ScMyTableXShapes::iterator aItr((*pTableShapes)[nCurrentTable].begin());
3290 ScMyTableXShapes::iterator aEndItr((*pTableShapes)[nCurrentTable].end());
3291 while (aItr != aEndItr)
3293 if (aItr->is())
3295 if (pDoc->IsNegativePage(static_cast<SCTAB>(nCurrentTable)))
3297 awt::Point aPoint((*aItr)->getPosition());
3298 awt::Size aSize((*aItr)->getSize());
3299 aPoint.X += aPoint.X + aSize.Width;
3300 aPoint.Y = 0;
3301 ExportShape(*aItr, &aPoint);
3303 else
3304 ExportShape(*aItr, NULL);
3306 aItr = (*pTableShapes)[nCurrentTable].erase(aItr);
3311 void ScXMLExport::WriteAreaLink( const ScMyCell& rMyCell )
3313 if( rMyCell.bHasAreaLink )
3315 const ScMyAreaLink& rAreaLink = rMyCell.aAreaLink;
3316 AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, rAreaLink.sSourceStr );
3317 AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetRelativeReference(rAreaLink.sURL) );
3318 AddAttribute( XML_NAMESPACE_TABLE, XML_FILTER_NAME, rAreaLink.sFilter );
3319 if( rAreaLink.sFilterOptions.getLength() )
3320 AddAttribute( XML_NAMESPACE_TABLE, XML_FILTER_OPTIONS, rAreaLink.sFilterOptions );
3321 OUStringBuffer sValue;
3322 SvXMLUnitConverter::convertNumber( sValue, rAreaLink.GetColCount() );
3323 AddAttribute( XML_NAMESPACE_TABLE, XML_LAST_COLUMN_SPANNED, sValue.makeStringAndClear() );
3324 SvXMLUnitConverter::convertNumber( sValue, rAreaLink.GetRowCount() );
3325 AddAttribute( XML_NAMESPACE_TABLE, XML_LAST_ROW_SPANNED, sValue.makeStringAndClear() );
3326 if( rAreaLink.nRefresh )
3328 SvXMLUnitConverter::convertTime( sValue, (double)rAreaLink.nRefresh / 86400 );
3329 AddAttribute( XML_NAMESPACE_TABLE, XML_REFRESH_DELAY, sValue.makeStringAndClear() );
3331 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_CELL_RANGE_SOURCE, sal_True, sal_True );
3335 void ScXMLExport::exportAnnotationMeta( const uno::Reference < drawing::XShape >& xShape)
3337 if (pCurrentCell && pCurrentCell->xNoteShape.is() && pCurrentCell->xNoteShape.get() == xShape.get() && pCurrentCell->xAnnotation.is())
3339 rtl::OUString sAuthor(pCurrentCell->xAnnotation->getAuthor());
3340 if (sAuthor.getLength())
3342 SvXMLElementExport aCreatorElem( *this, XML_NAMESPACE_DC,
3343 XML_CREATOR, sal_True,
3344 sal_False );
3345 Characters(sAuthor);
3348 String aDate(pCurrentCell->xAnnotation->getDate());
3349 if (pDoc)
3351 SvNumberFormatter* pNumForm = pDoc->GetFormatTable();
3352 double fDate;
3353 sal_uInt32 nfIndex = pNumForm->GetFormatIndex(NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
3354 if (pNumForm->IsNumberFormat(aDate, nfIndex, fDate))
3356 rtl::OUStringBuffer sBuf;
3357 GetMM100UnitConverter().convertDateTime(sBuf, fDate,sal_True);
3358 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_DC,
3359 XML_DATE, sal_True,
3360 sal_False );
3361 Characters(sBuf.makeStringAndClear());
3363 else
3365 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3366 XML_DATE_STRING, sal_True,
3367 sal_False );
3368 Characters(rtl::OUString(aDate));
3371 else
3373 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3374 XML_DATE_STRING, sal_True,
3375 sal_False );
3376 Characters(rtl::OUString(aDate));
3381 void ScXMLExport::WriteAnnotation(ScMyCell& rMyCell)
3383 if( rMyCell.bHasAnnotation && rMyCell.xAnnotation.is())
3385 /* rtl::OUString sAuthor(rMyCell.xAnnotation->getAuthor());
3386 if (sAuthor.getLength())
3388 SvXMLElementExport aCreatorElem( *this, XML_NAMESPACE_DC,
3389 XML_CREATOR, sal_True,
3390 sal_False );
3391 rtl::OUString sAuthor(sAuthor);
3392 Characters(sAuthor);
3395 String aDate(rMyCell.xAnnotation->getDate());
3396 if (pDoc)
3398 SvNumberFormatter* pNumForm(pDoc->GetFormatTable());
3399 double fDate;
3400 sal_uInt32 nfIndex = pNumForm->GetFormatIndex(NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
3401 if (pNumForm->IsNumberFormat(aDate, nfIndex, fDate))
3403 rtl::OUStringBuffer sBuf;
3404 GetMM100UnitConverter().convertDateTime(sBuf, fDate);
3405 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_DC,
3406 XML_DATE, sal_True,
3407 sal_False );
3408 Characters(sBuf.makeStringAndClear());
3410 else
3412 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3413 XML_DATE_STRING, sal_True,
3414 sal_False );
3415 Characters(rtl::OUString(aDate));
3418 else
3420 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3421 XML_DATE_STRING, sal_True,
3422 sal_False );
3423 Characters(rtl::OUString(aDate));
3426 if (rMyCell.xAnnotation->getIsVisible())
3427 AddAttribute(XML_NAMESPACE_OFFICE, XML_DISPLAY, XML_TRUE);
3429 pCurrentCell = &rMyCell;
3431 if(rMyCell.xNoteShape.is())
3432 GetShapeExport()->exportShape(rMyCell.xNoteShape, SEF_DEFAULT|SEF_EXPORT_ANNOTATION, NULL);
3434 pCurrentCell = NULL;
3436 rMyCell.xNoteShape.clear();
3440 void ScXMLExport::WriteDetective( const ScMyCell& rMyCell )
3442 if( rMyCell.bHasDetectiveObj || rMyCell.bHasDetectiveOp )
3444 const ScMyDetectiveObjVec& rObjVec = rMyCell.aDetectiveObjVec;
3445 const ScMyDetectiveOpVec& rOpVec = rMyCell.aDetectiveOpVec;
3446 sal_Int32 nObjCount(rObjVec.size());
3447 sal_Int32 nOpCount(rOpVec.size());
3448 if( nObjCount || nOpCount )
3450 SvXMLElementExport aDetElem( *this, XML_NAMESPACE_TABLE, XML_DETECTIVE, sal_True, sal_True );
3451 OUString sString;
3452 ScMyDetectiveObjVec::const_iterator aObjItr(rObjVec.begin());
3453 ScMyDetectiveObjVec::const_iterator aEndObjItr(rObjVec.end());
3454 while(aObjItr != aEndObjItr)
3456 if (aObjItr->eObjType != SC_DETOBJ_CIRCLE)
3458 if( (aObjItr->eObjType == SC_DETOBJ_ARROW) || (aObjItr->eObjType == SC_DETOBJ_TOOTHERTAB))
3460 ScRangeStringConverter::GetStringFromRange( sString, aObjItr->aSourceRange, pDoc, FormulaGrammar::CONV_OOO );
3461 AddAttribute( XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sString );
3463 ScXMLConverter::GetStringFromDetObjType( sString, aObjItr->eObjType );
3464 AddAttribute( XML_NAMESPACE_TABLE, XML_DIRECTION, sString );
3465 if( aObjItr->bHasError )
3466 AddAttribute( XML_NAMESPACE_TABLE, XML_CONTAINS_ERROR, XML_TRUE );
3468 else
3469 AddAttribute( XML_NAMESPACE_TABLE, XML_MARKED_INVALID, XML_TRUE );
3470 SvXMLElementExport aRangeElem( *this, XML_NAMESPACE_TABLE, XML_HIGHLIGHTED_RANGE, sal_True, sal_True );
3471 ++aObjItr;
3473 OUStringBuffer aBuffer;
3474 ScMyDetectiveOpVec::const_iterator aOpItr(rOpVec.begin());
3475 ScMyDetectiveOpVec::const_iterator aEndOpItr(rOpVec.end());
3476 while(aOpItr != aEndOpItr)
3478 OUString sOpString;
3479 ScXMLConverter::GetStringFromDetOpType( sOpString, aOpItr->eOpType );
3480 AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, sOpString );
3481 SvXMLUnitConverter::convertNumber( aBuffer, aOpItr->nIndex );
3482 AddAttribute( XML_NAMESPACE_TABLE, XML_INDEX, aBuffer.makeStringAndClear() );
3483 SvXMLElementExport aRangeElem( *this, XML_NAMESPACE_TABLE, XML_OPERATION, sal_True, sal_True );
3484 ++aOpItr;
3490 void ScXMLExport::SetRepeatAttribute (const sal_Int32 nEqualCellCount)
3492 if (nEqualCellCount > 0)
3494 sal_Int32 nTemp(nEqualCellCount + 1);
3495 OUString sOUEqualCellCount(OUString::valueOf(nTemp));
3496 AddAttribute(sAttrColumnsRepeated, sOUEqualCellCount);
3497 IncrementProgressBar(sal_False, nEqualCellCount);
3501 sal_Bool ScXMLExport::IsCellTypeEqual (const ScMyCell& aCell1, const ScMyCell& aCell2) const
3503 return (aCell1.nType == aCell2.nType);
3506 sal_Bool ScXMLExport::IsEditCell(const com::sun::star::table::CellAddress& aAddress, ScMyCell* pMyCell) const
3508 ScAddress aCoreAddress(static_cast<SCCOL>(aAddress.Column),
3509 static_cast<SCROW>(aAddress.Row),
3510 static_cast<SCTAB>(aAddress.Sheet));
3511 ScBaseCell* pBaseCell = GetDocument() ? GetDocument()->GetCell(aCoreAddress) : NULL;
3512 if (pMyCell)
3513 pMyCell->pBaseCell = pBaseCell;
3515 if (pBaseCell)
3516 return (pBaseCell->GetCellType() == CELLTYPE_EDIT);
3517 return sal_False;
3520 //UNUSED2008-05 sal_Bool ScXMLExport::IsEditCell(const com::sun::star::uno::Reference <com::sun::star::table::XCell>& xCell) const
3521 //UNUSED2008-05 {
3522 //UNUSED2008-05 uno::Reference<sheet::XCellAddressable> xAddressable (xCell, uno::UNO_QUERY);
3523 //UNUSED2008-05 if ( xAddressable.is() )
3524 //UNUSED2008-05 return IsEditCell(xAddressable->getCellAddress());
3525 //UNUSED2008-05 return sal_False;
3526 //UNUSED2008-05 }
3528 sal_Bool ScXMLExport::IsEditCell(ScMyCell& rCell) const
3530 if (rCell.bKnowWhetherIsEditCell)
3531 return rCell.bIsEditCell;
3532 else
3534 rCell.bIsEditCell = IsEditCell(rCell.aCellAddress, &rCell);
3535 rCell.bKnowWhetherIsEditCell = sal_True;
3536 return rCell.bIsEditCell;
3540 sal_Bool ScXMLExport::IsMultiLineFormulaCell(ScMyCell& rCell) const
3542 if (rCell.pBaseCell)
3544 if (rCell.pBaseCell->GetCellType() != CELLTYPE_FORMULA)
3545 return false;
3547 return static_cast<ScFormulaCell*>(rCell.pBaseCell)->IsMultilineResult();
3550 ScAddress aAddr(static_cast<SCCOL>(rCell.aCellAddress.Column),
3551 static_cast<SCROW>(rCell.aCellAddress.Row),
3552 static_cast<SCTAB>(rCell.aCellAddress.Sheet));
3553 ScBaseCell* pBaseCell = pDoc ? pDoc->GetCell(aAddr) : NULL;
3554 if (!pBaseCell)
3555 return false;
3557 rCell.pBaseCell = pBaseCell;
3558 if (rCell.pBaseCell->GetCellType() != CELLTYPE_FORMULA)
3559 return false;
3561 return static_cast<ScFormulaCell*>(rCell.pBaseCell)->IsMultilineResult();
3564 //UNUSED2008-05 sal_Bool ScXMLExport::IsAnnotationEqual(const uno::Reference<table::XCell>& /* xCell1 */,
3565 //UNUSED2008-05 const uno::Reference<table::XCell>& /* xCell2 */)
3566 //UNUSED2008-05 {
3567 //UNUSED2008-05 // no longer compareable, because the position and size and other attributes can also differ
3568 //UNUSED2008-05
3569 //UNUSED2008-05 /* uno::Reference<sheet::XSheetAnnotationAnchor> xSheetAnnotationAnchor1(xCell1, uno::UNO_QUERY);
3570 //UNUSED2008-05 uno::Reference<sheet::XSheetAnnotationAnchor> xSheetAnnotationAnchor2(xCell2, uno::UNO_QUERY);
3571 //UNUSED2008-05 if (xSheetAnnotationAnchor1.is() && xSheetAnnotationAnchor2.is())
3572 //UNUSED2008-05 {
3573 //UNUSED2008-05 uno::Reference <sheet::XSheetAnnotation> xSheetAnnotation1(xSheetAnnotationAnchor1->getAnnotation());
3574 //UNUSED2008-05 uno::Reference <sheet::XSheetAnnotation> xSheetAnnotation2(xSheetAnnotationAnchor2->getAnnotation());
3575 //UNUSED2008-05 uno::Reference<text::XSimpleText> xSimpleText1(xSheetAnnotation1, uno::UNO_QUERY);
3576 //UNUSED2008-05 uno::Reference<text::XSimpleText> xSimpleText2(xSheetAnnotation2, uno::UNO_QUERY);
3577 //UNUSED2008-05 if (xSheetAnnotation1.is() && xSimpleText1.is() &&
3578 //UNUSED2008-05 xSheetAnnotation2.is() && xSimpleText2.is())
3579 //UNUSED2008-05 {
3580 //UNUSED2008-05 rtl::OUString sText1(xSimpleText1->getString());
3581 //UNUSED2008-05 rtl::OUString sText2(xSimpleText2->getString());
3582 //UNUSED2008-05 sal_Int32 nLength1(sText1.getLength());
3583 //UNUSED2008-05 sal_Int32 nLength2(sText2.getLength());
3584 //UNUSED2008-05 if (nLength1 && nLength2)
3585 //UNUSED2008-05 if (sText1 == sText2 &&
3586 //UNUSED2008-05 xSheetAnnotation1->getAuthor() == xSheetAnnotation2->getAuthor() &&
3587 //UNUSED2008-05 xSheetAnnotation1->getDate() == xSheetAnnotation2->getDate() &&
3588 //UNUSED2008-05 xSheetAnnotation1->getIsVisible() == xSheetAnnotation2->getIsVisible())
3589 //UNUSED2008-05 return sal_True;
3590 //UNUSED2008-05 else
3591 //UNUSED2008-05 return sal_False;
3592 //UNUSED2008-05 else
3593 //UNUSED2008-05 if (nLength1 || nLength2)
3594 //UNUSED2008-05 return sal_False;
3595 //UNUSED2008-05 else
3596 //UNUSED2008-05 return sal_True;
3597 //UNUSED2008-05 }
3598 //UNUSED2008-05 }*/
3599 //UNUSED2008-05 return sal_False;
3600 //UNUSED2008-05 }
3602 sal_Bool ScXMLExport::IsCellEqual (ScMyCell& aCell1, ScMyCell& aCell2)
3604 ScAddress aCellPos1;
3605 ScUnoConversion::FillScAddress( aCellPos1, aCell1.aCellAddress );
3606 ScAddress aCellPos2;
3607 ScUnoConversion::FillScAddress( aCellPos2, aCell2.aCellAddress );
3608 sal_Bool bIsEqual = sal_False;
3609 if( !aCell1.bIsMergedBase && !aCell2.bIsMergedBase &&
3610 aCell1.bIsCovered == aCell2.bIsCovered &&
3611 !aCell1.bIsMatrixBase && !aCell2.bIsMatrixBase &&
3612 aCell1.bIsMatrixCovered == aCell2.bIsMatrixCovered &&
3613 aCell1.bHasAnnotation == aCell2.bHasAnnotation &&
3614 !aCell1.bHasShape && !aCell2.bHasShape &&
3615 aCell1.bHasAreaLink == aCell2.bHasAreaLink &&
3616 !aCell1.bHasDetectiveObj && !aCell2.bHasDetectiveObj)
3618 if( (aCell1.bHasAreaLink &&
3619 (aCell1.aAreaLink.GetColCount() == 1) &&
3620 (aCell2.aAreaLink.GetColCount() == 1) &&
3621 aCell1.aAreaLink.Compare( aCell2.aAreaLink ) ) ||
3622 !aCell1.bHasAreaLink )
3624 if (!aCell1.bHasAnnotation || (aCell1.bHasAnnotation && sal_False/*IsAnnotationEqual(aCell1.xCell, aCell2.xCell)*/)) // no longer compareable
3626 if (((aCell1.nStyleIndex == aCell2.nStyleIndex) && ((aCell1.bIsAutoStyle == aCell2.bIsAutoStyle) ||
3627 (aCell1.nStyleIndex == aCell2.nStyleIndex)) && (aCell1.nStyleIndex == -1)) &&
3628 (aCell1.nValidationIndex == aCell2.nValidationIndex) &&
3629 IsCellTypeEqual(aCell1, aCell2))
3631 switch ( aCell1.nType )
3633 case table::CellContentType_EMPTY :
3635 bIsEqual = sal_True;
3637 break;
3638 case table::CellContentType_VALUE :
3640 if(!aCell1.bHasDoubleValue)
3642 aCell1.fValue = pDoc->GetValue( aCellPos1 );
3643 aCell1.bHasDoubleValue = sal_True;
3645 if (!aCell2.bHasDoubleValue)
3647 aCell2.fValue = pDoc->GetValue( aCellPos2 );
3648 aCell2.bHasDoubleValue = sal_True;
3650 // #i29101# number format may be different from column default styles,
3651 // but can lead to different value types, so it must also be compared
3652 bIsEqual = (aCell1.nNumberFormat == aCell2.nNumberFormat) &&
3653 (aCell1.fValue == aCell2.fValue);
3655 break;
3656 case table::CellContentType_TEXT :
3658 if (IsEditCell(aCell1) || IsEditCell(aCell2))
3659 bIsEqual = sal_False;
3660 else
3662 if (GetCellText(aCell1, aCellPos1) && GetCellText(aCell2, aCellPos2))
3664 bIsEqual = (aCell1.sStringValue == aCell2.sStringValue) &&
3665 (lcl_GetRawString(pDoc, aCellPos1) == lcl_GetRawString(pDoc, aCellPos2));
3667 else
3668 bIsEqual = sal_False;
3671 break;
3672 case table::CellContentType_FORMULA :
3674 bIsEqual = sal_False;
3676 break;
3677 default :
3679 bIsEqual = sal_False;
3681 break;
3687 return bIsEqual;
3690 void ScXMLExport::WriteCalculationSettings(const uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc)
3692 uno::Reference<beans::XPropertySet> xPropertySet(xSpreadDoc, uno::UNO_QUERY);
3693 if (xPropertySet.is())
3695 sal_Bool bCalcAsShown (::cppu::any2bool( xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_CALCASSHOWN))) ));
3696 sal_Bool bIgnoreCase (::cppu::any2bool( xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_IGNORECASE))) ));
3697 sal_Bool bLookUpLabels (::cppu::any2bool( xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_LOOKUPLABELS))) ));
3698 sal_Bool bMatchWholeCell (::cppu::any2bool( xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_MATCHWHOLE))) ));
3699 sal_Bool bUseRegularExpressions (::cppu::any2bool( xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_REGEXENABLED))) ));
3700 sal_Bool bIsIterationEnabled (::cppu::any2bool( xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITERENABLED))) ));
3701 sal_uInt16 nYear2000 (pDoc ? pDoc->GetDocOptions().GetYear2000() : 0);
3702 sal_Int32 nIterationCount(100);
3703 xPropertySet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITERCOUNT))) >>= nIterationCount;
3704 double fIterationEpsilon = 0;
3705 xPropertySet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITEREPSILON))) >>= fIterationEpsilon;
3706 util::Date aNullDate;
3707 xPropertySet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_NULLDATE))) >>= aNullDate;
3708 if (bCalcAsShown || bIgnoreCase || !bLookUpLabels || !bMatchWholeCell || !bUseRegularExpressions ||
3709 bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001) ||
3710 aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899 || nYear2000 != 1930)
3712 if (bIgnoreCase)
3713 AddAttribute(XML_NAMESPACE_TABLE, XML_CASE_SENSITIVE, XML_FALSE);
3714 if (bCalcAsShown)
3715 AddAttribute(XML_NAMESPACE_TABLE, XML_PRECISION_AS_SHOWN, XML_TRUE);
3716 if (!bMatchWholeCell)
3717 AddAttribute(XML_NAMESPACE_TABLE, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL, XML_FALSE);
3718 if (!bLookUpLabels)
3719 AddAttribute(XML_NAMESPACE_TABLE, XML_AUTOMATIC_FIND_LABELS, XML_FALSE);
3720 if (!bUseRegularExpressions)
3721 AddAttribute(XML_NAMESPACE_TABLE, XML_USE_REGULAR_EXPRESSIONS, XML_FALSE);
3722 if (nYear2000 != 1930)
3724 rtl::OUStringBuffer sBuffer;
3725 GetMM100UnitConverter().convertNumber(sBuffer, nYear2000);
3726 AddAttribute(XML_NAMESPACE_TABLE, XML_NULL_YEAR, sBuffer.makeStringAndClear());
3728 SvXMLElementExport aCalcSettings(*this, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, sal_True, sal_True);
3730 if (aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899)
3732 rtl::OUStringBuffer sDate;
3733 GetMM100UnitConverter().convertDateTime(sDate, 0.0, aNullDate);
3734 AddAttribute(XML_NAMESPACE_TABLE, XML_DATE_VALUE, sDate.makeStringAndClear());
3735 SvXMLElementExport aElemNullDate(*this, XML_NAMESPACE_TABLE, XML_NULL_DATE, sal_True, sal_True);
3737 if (bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001))
3739 rtl::OUStringBuffer sBuffer;
3740 if (bIsIterationEnabled)
3741 AddAttribute(XML_NAMESPACE_TABLE, XML_STATUS, XML_ENABLE);
3742 if (nIterationCount != 100)
3744 GetMM100UnitConverter().convertNumber(sBuffer, nIterationCount);
3745 AddAttribute(XML_NAMESPACE_TABLE, XML_STEPS, sBuffer.makeStringAndClear());
3747 if (!::rtl::math::approxEqual(fIterationEpsilon, 0.001))
3749 GetMM100UnitConverter().convertDouble(sBuffer, fIterationEpsilon);
3750 AddAttribute(XML_NAMESPACE_TABLE, XML_MAXIMUM_DIFFERENCE, sBuffer.makeStringAndClear());
3752 SvXMLElementExport aElemIteration(*this, XML_NAMESPACE_TABLE, XML_ITERATION, sal_True, sal_True);
3759 void ScXMLExport::WriteTableSource()
3761 uno::Reference <sheet::XSheetLinkable> xLinkable (xCurrentTable, uno::UNO_QUERY);
3762 if (xLinkable.is() && GetModel().is())
3764 sheet::SheetLinkMode nMode (xLinkable->getLinkMode());
3765 if (nMode != sheet::SheetLinkMode_NONE)
3767 rtl::OUString sLink (xLinkable->getLinkUrl());
3768 uno::Reference <beans::XPropertySet> xProps (GetModel(), uno::UNO_QUERY);
3769 if (xProps.is())
3771 uno::Reference <container::XIndexAccess> xIndex(xProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHEETLINKS))), uno::UNO_QUERY);
3772 if (xIndex.is())
3774 sal_Int32 nCount(xIndex->getCount());
3775 if (nCount)
3777 sal_Bool bFound(sal_False);
3778 uno::Reference <beans::XPropertySet> xLinkProps;
3779 for (sal_Int32 i = 0; (i < nCount) && !bFound; ++i)
3781 xLinkProps.set(xIndex->getByIndex(i), uno::UNO_QUERY);
3782 if (xLinkProps.is())
3784 rtl::OUString sNewLink;
3785 if (xLinkProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_LINKURL))) >>= sNewLink)
3786 bFound = sLink.equals(sNewLink);
3789 if (bFound && xLinkProps.is())
3791 rtl::OUString sFilter;
3792 rtl::OUString sFilterOptions;
3793 rtl::OUString sTableName (xLinkable->getLinkSheetName());
3794 sal_Int32 nRefresh(0);
3795 xLinkProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FILTER))) >>= sFilter;
3796 xLinkProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FILTOPT))) >>= sFilterOptions;
3797 xLinkProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_REFDELAY))) >>= nRefresh;
3798 if (sLink.getLength())
3800 AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, GetRelativeReference(sLink));
3801 if (sTableName.getLength())
3802 AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_NAME, sTableName);
3803 if (sFilter.getLength())
3804 AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_NAME, sFilter);
3805 if (sFilterOptions.getLength())
3806 AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_OPTIONS, sFilterOptions);
3807 if (nMode != sheet::SheetLinkMode_NORMAL)
3808 AddAttribute(XML_NAMESPACE_TABLE, XML_MODE, XML_COPY_RESULTS_ONLY);
3809 if( nRefresh )
3811 rtl::OUStringBuffer sBuffer;
3812 SvXMLUnitConverter::convertTime( sBuffer, (double)nRefresh / 86400 );
3813 AddAttribute( XML_NAMESPACE_TABLE, XML_REFRESH_DELAY, sBuffer.makeStringAndClear() );
3815 SvXMLElementExport aSourceElem(*this, XML_NAMESPACE_TABLE, XML_TABLE_SOURCE, sal_True, sal_True);
3825 // core implementation
3826 void ScXMLExport::WriteScenario()
3828 if (pDoc && pDoc->IsScenario(static_cast<SCTAB>(nCurrentTable)))
3830 String sComment;
3831 Color aColor;
3832 sal_uInt16 nFlags;
3833 pDoc->GetScenarioData(static_cast<SCTAB>(nCurrentTable), sComment, aColor, nFlags);
3834 if (!(nFlags & SC_SCENARIO_SHOWFRAME))
3835 AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_BORDER, XML_FALSE);
3836 rtl::OUStringBuffer aBuffer;
3837 SvXMLUnitConverter::convertColor(aBuffer, aColor);
3838 AddAttribute(XML_NAMESPACE_TABLE, XML_BORDER_COLOR, aBuffer.makeStringAndClear());
3839 if (!(nFlags & SC_SCENARIO_TWOWAY))
3840 AddAttribute(XML_NAMESPACE_TABLE, XML_COPY_BACK, XML_FALSE);
3841 if (!(nFlags & SC_SCENARIO_ATTRIB))
3842 AddAttribute(XML_NAMESPACE_TABLE, XML_COPY_STYLES, XML_FALSE);
3843 if (nFlags & SC_SCENARIO_VALUE)
3844 AddAttribute(XML_NAMESPACE_TABLE, XML_COPY_FORMULAS, XML_FALSE);
3845 if (nFlags & SC_SCENARIO_PROTECT)
3846 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
3847 SvXMLUnitConverter::convertBool(aBuffer, pDoc->IsActiveScenario(static_cast<SCTAB>(nCurrentTable)));
3848 AddAttribute(XML_NAMESPACE_TABLE, XML_IS_ACTIVE, aBuffer.makeStringAndClear());
3849 const ScRangeList* pRangeList = pDoc->GetScenarioRanges(static_cast<SCTAB>(nCurrentTable));
3850 rtl::OUString sRangeListStr;
3851 ScRangeStringConverter::GetStringFromRangeList( sRangeListStr, pRangeList, pDoc, FormulaGrammar::CONV_OOO );
3852 AddAttribute(XML_NAMESPACE_TABLE, XML_SCENARIO_RANGES, sRangeListStr);
3853 if (sComment.Len())
3854 AddAttribute(XML_NAMESPACE_TABLE, XML_COMMENT, rtl::OUString(sComment));
3855 SvXMLElementExport aElem(*this, XML_NAMESPACE_TABLE, XML_SCENARIO, sal_True, sal_True);
3859 void ScXMLExport::WriteTheLabelRanges( const uno::Reference< sheet::XSpreadsheetDocument >& xSpreadDoc )
3861 uno::Reference< beans::XPropertySet > xDocProp( xSpreadDoc, uno::UNO_QUERY );
3862 if( !xDocProp.is() ) return;
3864 sal_Int32 nCount(0);
3865 uno::Reference< container::XIndexAccess > xColRangesIAccess(xDocProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLLABELRNG ) ) ), uno::UNO_QUERY);
3866 if( xColRangesIAccess.is() )
3867 nCount += xColRangesIAccess->getCount();
3869 uno::Reference< container::XIndexAccess > xRowRangesIAccess(xDocProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ROWLABELRNG ) ) ), uno::UNO_QUERY);
3870 if( xRowRangesIAccess.is() )
3871 nCount += xRowRangesIAccess->getCount();
3873 if( nCount )
3875 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_LABEL_RANGES, sal_True, sal_True );
3876 WriteLabelRanges( xColRangesIAccess, sal_True );
3877 WriteLabelRanges( xRowRangesIAccess, sal_False );
3881 void ScXMLExport::WriteLabelRanges( const uno::Reference< container::XIndexAccess >& xRangesIAccess, sal_Bool bColumn )
3883 if( !xRangesIAccess.is() ) return;
3885 sal_Int32 nCount(xRangesIAccess->getCount());
3886 for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
3888 uno::Reference< sheet::XLabelRange > xRange(xRangesIAccess->getByIndex( nIndex ), uno::UNO_QUERY);
3889 if( xRange.is() )
3891 OUString sRangeStr;
3892 table::CellRangeAddress aCellRange( xRange->getLabelArea() );
3893 ScRangeStringConverter::GetStringFromRange( sRangeStr, aCellRange, pDoc, FormulaGrammar::CONV_OOO );
3894 AddAttribute( XML_NAMESPACE_TABLE, XML_LABEL_CELL_RANGE_ADDRESS, sRangeStr );
3895 aCellRange = xRange->getDataArea();
3896 ScRangeStringConverter::GetStringFromRange( sRangeStr, aCellRange, pDoc, FormulaGrammar::CONV_OOO );
3897 AddAttribute( XML_NAMESPACE_TABLE, XML_DATA_CELL_RANGE_ADDRESS, sRangeStr );
3898 AddAttribute( XML_NAMESPACE_TABLE, XML_ORIENTATION, bColumn ? XML_COLUMN : XML_ROW );
3899 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_LABEL_RANGE, sal_True, sal_True );
3904 void ScXMLExport::WriteNamedExpressions(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc)
3906 uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
3907 if (xPropertySet.is())
3909 uno::Reference <sheet::XNamedRanges> xNamedRanges(xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_NAMEDRANGES))), uno::UNO_QUERY);
3910 CheckAttrList();
3911 if (xNamedRanges.is())
3913 uno::Sequence <rtl::OUString> aRangesNames(xNamedRanges->getElementNames());
3914 sal_Int32 nNamedRangesCount(aRangesNames.getLength());
3915 if (nNamedRangesCount > 0)
3917 if (pDoc)
3919 ScRangeName* pNamedRanges(pDoc->GetRangeName());
3920 SvXMLElementExport aElemNEs(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSIONS, sal_True, sal_True);
3921 for (sal_Int32 i = 0; i < nNamedRangesCount; ++i)
3923 CheckAttrList();
3924 rtl::OUString sNamedRange(aRangesNames[i]);
3925 uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName(sNamedRange), uno::UNO_QUERY);
3926 if (xNamedRange.is())
3928 uno::Reference <container::XNamed> xNamed (xNamedRange, uno::UNO_QUERY);
3929 uno::Reference <sheet::XCellRangeReferrer> xCellRangeReferrer (xNamedRange, uno::UNO_QUERY);
3930 if (xNamed.is() && xCellRangeReferrer.is())
3932 rtl::OUString sOUName(xNamed->getName());
3933 AddAttribute(sAttrName, sOUName);
3935 OUString sOUBaseCellAddress;
3936 ScRangeStringConverter::GetStringFromAddress( sOUBaseCellAddress,
3937 xNamedRange->getReferencePosition(), pDoc, FormulaGrammar::CONV_OOO, ' ', sal_False, SCA_ABS_3D );
3938 AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, sOUBaseCellAddress);
3940 sal_uInt16 nRangeIndex;
3941 String sName(sOUName);
3942 pNamedRanges->SearchName(sName, nRangeIndex);
3943 ScRangeData* pNamedRange((*pNamedRanges)[nRangeIndex]); //should get directly and not with ScDocument
3944 String sContent;
3945 pNamedRange->GetSymbol(sContent, pDoc->GetStorageGrammar());
3946 rtl::OUString sOUTempContent(sContent);
3947 uno::Reference <table::XCellRange> xCellRange(xCellRangeReferrer->getReferredCells());
3948 if(xCellRange.is())
3950 rtl::OUString sOUContent(sOUTempContent.copy(1, sOUTempContent.getLength() - 2));
3951 AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sOUContent);
3952 sal_Int32 nRangeType(xNamedRange->getType());
3953 rtl::OUStringBuffer sBufferRangeType;
3954 if ((nRangeType & sheet::NamedRangeFlag::COLUMN_HEADER) == sheet::NamedRangeFlag::COLUMN_HEADER)
3955 sBufferRangeType.append(GetXMLToken(XML_REPEAT_COLUMN));
3956 if ((nRangeType & sheet::NamedRangeFlag::ROW_HEADER) == sheet::NamedRangeFlag::ROW_HEADER)
3958 if (sBufferRangeType.getLength() > 0)
3959 sBufferRangeType.appendAscii(" ");
3960 sBufferRangeType.append(GetXMLToken(XML_REPEAT_ROW));
3962 if ((nRangeType & sheet::NamedRangeFlag::FILTER_CRITERIA) == sheet::NamedRangeFlag::FILTER_CRITERIA)
3964 if (sBufferRangeType.getLength() > 0)
3965 sBufferRangeType.appendAscii(" ");
3966 sBufferRangeType.append(GetXMLToken(XML_FILTER));
3968 if ((nRangeType & sheet::NamedRangeFlag::PRINT_AREA) == sheet::NamedRangeFlag::PRINT_AREA)
3970 if (sBufferRangeType.getLength() > 0)
3971 sBufferRangeType.appendAscii(" ");
3972 sBufferRangeType.append(GetXMLToken(XML_PRINT_RANGE));
3974 rtl::OUString sRangeType = sBufferRangeType.makeStringAndClear();
3975 if (sRangeType.getLength())
3976 AddAttribute(XML_NAMESPACE_TABLE, XML_RANGE_USABLE_AS, sRangeType);
3977 SvXMLElementExport aElemNR(*this, XML_NAMESPACE_TABLE, XML_NAMED_RANGE, sal_True, sal_True);
3979 else
3981 AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, sOUTempContent);
3982 SvXMLElementExport aElemNE(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, sal_True, sal_True);
3993 void ScXMLExport::WriteExternalRefCaches()
3995 if (!pDoc)
3996 return;
3998 ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
3999 pRefMgr->resetSrcFileData(GetOrigFileName());
4000 sal_uInt16 nCount = pRefMgr->getExternalFileCount();
4001 for (sal_uInt16 nFileId = 0; nFileId < nCount; ++nFileId)
4003 const String* pUrl = pRefMgr->getExternalFileName(nFileId);
4004 if (!pUrl)
4005 continue;
4007 vector<String> aTabNames;
4008 pRefMgr->getAllCachedTableNames(nFileId, aTabNames);
4009 if (aTabNames.empty())
4010 continue;
4012 for (vector<String>::const_iterator itr = aTabNames.begin(), itrEnd = aTabNames.end();
4013 itr != itrEnd; ++itr)
4015 ScExternalRefCache::TableTypeRef pTable = pRefMgr->getCacheTable(nFileId, *itr, false);
4016 if (!pTable.get() || !pTable->isReferenced())
4017 continue;
4019 OUStringBuffer aBuf;
4020 aBuf.append(sal_Unicode('\''));
4021 aBuf.append(*pUrl);
4022 aBuf.append(sal_Unicode('\''));
4023 aBuf.append(sal_Unicode('#'));
4024 aBuf.append(*itr);
4025 AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, aBuf.makeStringAndClear());
4026 AddAttribute(XML_NAMESPACE_TABLE, XML_PRINT, GetXMLToken(XML_FALSE));
4027 AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sExternalRefTabStyleName);
4028 SvXMLElementExport aElemTable(*this, XML_NAMESPACE_TABLE, XML_TABLE, sal_True, sal_True);
4030 const ScExternalRefManager::SrcFileData* pExtFileData = pRefMgr->getExternalFileData(nFileId);
4031 if (pExtFileData)
4033 String aRelUrl;
4034 if (pExtFileData->maRelativeName.Len())
4035 aRelUrl = pExtFileData->maRelativeName;
4036 else
4037 aRelUrl = GetRelativeReference(pExtFileData->maRelativeName);
4038 AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aRelUrl);
4039 AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_NAME, *itr);
4040 if (pExtFileData->maFilterName.Len())
4041 AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_NAME, pExtFileData->maFilterName);
4042 if (pExtFileData->maFilterOptions.Len())
4043 AddAttribute(XML_NAMESPACE_TABLE, XML_FILTER_OPTIONS, pExtFileData->maFilterOptions);
4044 AddAttribute(XML_NAMESPACE_TABLE, XML_MODE, XML_COPY_RESULTS_ONLY);
4046 SvXMLElementExport aElemTableSource(*this, XML_NAMESPACE_TABLE, XML_TABLE_SOURCE, sal_True, sal_True);
4049 // Determine maximum column count of used area, for repeated cells.
4050 SCCOL nMaxColsUsed = 1; // assume that there is at least one cell somewhere..
4051 vector<SCROW> aRows;
4052 pTable->getAllRows(aRows);
4053 for (vector<SCROW>::const_iterator itrRow = aRows.begin(), itrRowEnd = aRows.end();
4054 itrRow != itrRowEnd; ++itrRow)
4056 SCROW nRow = *itrRow;
4057 vector<SCCOL> aCols;
4058 pTable->getAllCols(nRow, aCols);
4059 if (!aCols.empty())
4061 SCCOL nCol = aCols.back();
4062 if (nMaxColsUsed <= nCol)
4063 nMaxColsUsed = nCol + 1;
4067 // Write cache content for this table.
4068 SCROW nLastRow = 0;
4069 bool bFirstRow = true;
4070 for (vector<SCROW>::const_iterator itrRow = aRows.begin(), itrRowEnd = aRows.end();
4071 itrRow != itrRowEnd; ++itrRow)
4073 SCROW nRow = *itrRow;
4074 if (bFirstRow)
4076 if (nRow > 0)
4078 if (nRow > 1)
4080 OUStringBuffer aVal;
4081 aVal.append(nRow);
4082 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, aVal.makeStringAndClear());
4084 SvXMLElementExport aElemRow(*this, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True);
4085 OUStringBuffer aVal;
4086 aVal.append(static_cast<sal_Int32>(nMaxColsUsed));
4087 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4088 SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True);
4091 else
4093 SCROW nRowGap = nRow - nLastRow;
4094 if (nRowGap > 1)
4096 if (nRowGap > 2)
4098 OUStringBuffer aVal;
4099 aVal.append(static_cast<sal_Int32>(nRowGap-1));
4100 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, aVal.makeStringAndClear());
4102 SvXMLElementExport aElemRow(*this, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True);
4103 OUStringBuffer aVal;
4104 aVal.append(static_cast<sal_Int32>(nMaxColsUsed));
4105 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4106 SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True);
4109 SvXMLElementExport aElemRow(*this, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True);
4111 vector<SCCOL> aCols;
4112 pTable->getAllCols(nRow, aCols);
4113 SCCOL nLastCol = 0;
4114 bool bFirstCol = true;
4115 for (vector<SCCOL>::const_iterator itrCol = aCols.begin(), itrColEnd = aCols.end();
4116 itrCol != itrColEnd; ++itrCol)
4118 SCCOL nCol = *itrCol;
4119 if (bFirstCol)
4121 if (nCol > 0)
4123 if (nCol > 1)
4125 OUStringBuffer aVal;
4126 aVal.append(static_cast<sal_Int32>(nCol));
4127 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4129 SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True);
4132 else
4134 SCCOL nColGap = nCol - nLastCol;
4135 if (nColGap > 1)
4137 if (nColGap > 2)
4139 OUStringBuffer aVal;
4140 aVal.append(static_cast<sal_Int32>(nColGap-1));
4141 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aVal.makeStringAndClear());
4143 SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True);
4147 // Write out this cell.
4148 sal_uInt32 nNumFmt = 0;
4149 ScExternalRefCache::TokenRef pToken = pTable->getCell(nCol, nRow, &nNumFmt);
4150 OUString aStrVal;
4151 if (pToken.get())
4153 sal_Int32 nIndex = GetNumberFormatStyleIndex(nNumFmt);
4154 if (nIndex >= 0)
4156 const OUString aStyleName = *pCellStyles->GetStyleNameByIndex(nIndex, true);
4157 AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, aStyleName);
4160 switch(pToken->GetType())
4162 case svDouble:
4164 AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
4165 OUStringBuffer aVal;
4166 aVal.append(pToken->GetDouble());
4167 aStrVal = aVal.makeStringAndClear();
4168 AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, aStrVal);
4170 break;
4171 case svString:
4173 AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
4174 aStrVal = pToken->GetString();
4176 break;
4177 default:
4181 SvXMLElementExport aElemCell(*this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True);
4182 SvXMLElementExport aElemText(*this, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False);
4183 Characters(aStrVal);
4185 nLastCol = nCol;
4186 bFirstCol = false;
4188 nLastRow = nRow;
4189 bFirstRow = false;
4195 // core implementation
4196 void ScXMLExport::WriteConsolidation()
4198 if (pDoc)
4200 const ScConsolidateParam* pCons(pDoc->GetConsolidateDlgData());
4201 if( pCons )
4203 OUString sStrData;
4205 ScXMLConverter::GetStringFromFunction( sStrData, pCons->eFunction );
4206 AddAttribute( XML_NAMESPACE_TABLE, XML_FUNCTION, sStrData );
4208 sStrData = OUString();
4209 for( sal_Int32 nIndex = 0; nIndex < pCons->nDataAreaCount; ++nIndex )
4210 ScRangeStringConverter::GetStringFromArea( sStrData, *pCons->ppDataAreas[ nIndex ], pDoc, FormulaGrammar::CONV_OOO, sal_True );
4211 AddAttribute( XML_NAMESPACE_TABLE, XML_SOURCE_CELL_RANGE_ADDRESSES, sStrData );
4213 ScRangeStringConverter::GetStringFromAddress( sStrData, ScAddress( pCons->nCol, pCons->nRow, pCons->nTab ), pDoc, FormulaGrammar::CONV_OOO );
4214 AddAttribute( XML_NAMESPACE_TABLE, XML_TARGET_CELL_ADDRESS, sStrData );
4216 if( pCons->bByCol && !pCons->bByRow )
4217 AddAttribute( XML_NAMESPACE_TABLE, XML_USE_LABEL, XML_COLUMN );
4218 else if( !pCons->bByCol && pCons->bByRow )
4219 AddAttribute( XML_NAMESPACE_TABLE, XML_USE_LABEL, XML_ROW );
4220 else if( pCons->bByCol && pCons->bByRow )
4221 AddAttribute( XML_NAMESPACE_TABLE, XML_USE_LABEL, XML_BOTH );
4223 if( pCons->bReferenceData )
4224 AddAttribute( XML_NAMESPACE_TABLE, XML_LINK_TO_SOURCE_DATA, XML_TRUE );
4226 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_CONSOLIDATION, sal_True, sal_True );
4231 SvXMLAutoStylePoolP* ScXMLExport::CreateAutoStylePool()
4233 return new ScXMLAutoStylePoolP(*this);
4236 XMLPageExport* ScXMLExport::CreatePageExport()
4238 return new XMLTableMasterPageExport( *this );
4241 void ScXMLExport::GetChangeTrackViewSettings(uno::Sequence<beans::PropertyValue>& rProps)
4243 ScChangeViewSettings* pViewSettings(GetDocument() ? GetDocument()->GetChangeViewSettings() : NULL);
4244 if (pViewSettings)
4246 sal_Int32 nChangePos(rProps.getLength());
4247 rProps.realloc(nChangePos + 1);
4248 beans::PropertyValue* pProps(rProps.getArray());
4249 if (pProps)
4251 uno::Sequence<beans::PropertyValue> aChangeProps(SC_VIEWCHANGES_COUNT);
4252 beans::PropertyValue* pChangeProps(aChangeProps.getArray());
4253 if (pChangeProps)
4255 pChangeProps[SC_SHOW_CHANGES].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChanges"));
4256 pChangeProps[SC_SHOW_CHANGES].Value <<= pViewSettings->ShowChanges();
4257 pChangeProps[SC_SHOW_ACCEPTED_CHANGES].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowAcceptedChanges"));
4258 pChangeProps[SC_SHOW_ACCEPTED_CHANGES].Value <<= pViewSettings->IsShowAccepted();
4259 pChangeProps[SC_SHOW_REJECTED_CHANGES].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowRejectedChanges"));
4260 pChangeProps[SC_SHOW_REJECTED_CHANGES].Value <<= pViewSettings->IsShowRejected();
4261 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByDatetime"));
4262 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME].Value <<= pViewSettings->HasDate();
4263 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_MODE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByDatetimeMode"));
4264 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_MODE].Value <<= static_cast<sal_Int16>(pViewSettings->GetTheDateMode());
4265 util::DateTime aDateTime;
4266 ScXMLConverter::ConvertCoreToAPIDateTime(pViewSettings->GetTheFirstDateTime(), aDateTime);
4267 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByDatetimeFirstDatetime"));
4268 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME].Value <<= aDateTime;
4269 ScXMLConverter::ConvertCoreToAPIDateTime(pViewSettings->GetTheLastDateTime(), aDateTime);
4270 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByDatetimeSecondDatetime"));
4271 pChangeProps[SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME].Value <<= aDateTime;
4272 pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByAuthor"));
4273 pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR].Value <<= pViewSettings->HasAuthor();
4274 pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR_NAME].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByAuthorName"));
4275 pChangeProps[SC_SHOW_CHANGES_BY_AUTHOR_NAME].Value <<= rtl::OUString (pViewSettings->GetTheAuthorToShow());
4276 pChangeProps[SC_SHOW_CHANGES_BY_COMMENT].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByComment"));
4277 pChangeProps[SC_SHOW_CHANGES_BY_COMMENT].Value <<= pViewSettings->HasComment();
4278 pChangeProps[SC_SHOW_CHANGES_BY_COMMENT_TEXT].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByCommentText"));
4279 pChangeProps[SC_SHOW_CHANGES_BY_COMMENT_TEXT].Value <<= rtl::OUString (pViewSettings->GetTheComment());
4280 pChangeProps[SC_SHOW_CHANGES_BY_RANGES].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByRanges"));
4281 pChangeProps[SC_SHOW_CHANGES_BY_RANGES].Value <<= pViewSettings->HasRange();
4282 rtl::OUString sRangeList;
4283 ScRangeStringConverter::GetStringFromRangeList(sRangeList, &(pViewSettings->GetTheRangeList()), GetDocument(), FormulaGrammar::CONV_OOO);
4284 pChangeProps[SC_SHOW_CHANGES_BY_RANGES_LIST].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowChangesByRangesList"));
4285 pChangeProps[SC_SHOW_CHANGES_BY_RANGES_LIST].Value <<= sRangeList;
4287 pProps[nChangePos].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TrackedChangesViewSettings"));
4288 pProps[nChangePos].Value <<= aChangeProps;
4294 void ScXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>& rProps)
4296 rProps.realloc(4);
4297 beans::PropertyValue* pProps(rProps.getArray());
4298 if(pProps)
4300 if (GetModel().is())
4302 ScModelObj* pDocObj(ScModelObj::getImplementation( GetModel() ));
4303 if (pDocObj)
4305 SfxObjectShell* pEmbeddedObj = pDocObj->GetEmbeddedObject();
4306 if (pEmbeddedObj)
4308 Rectangle aRect(pEmbeddedObj->GetVisArea());
4309 sal_uInt16 i(0);
4310 pProps[i].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VisibleAreaTop"));
4311 pProps[i].Value <<= static_cast<sal_Int32>(aRect.getY());
4312 pProps[++i].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VisibleAreaLeft"));
4313 pProps[i].Value <<= static_cast<sal_Int32>(aRect.getX());
4314 pProps[++i].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VisibleAreaWidth"));
4315 pProps[i].Value <<= static_cast<sal_Int32>(aRect.getWidth());
4316 pProps[++i].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VisibleAreaHeight"));
4317 pProps[i].Value <<= static_cast<sal_Int32>(aRect.getHeight());
4322 GetChangeTrackViewSettings(rProps);
4325 void ScXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>& rProps)
4327 if (GetModel().is())
4329 uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
4330 if (xMultiServiceFactory.is())
4332 uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.SpreadsheetSettings"))), uno::UNO_QUERY);
4333 if (xProperties.is())
4334 SvXMLUnitConverter::convertPropertySet(rProps, xProperties);
4335 if (GetDocument() && GetDocument()->GetChangeTrack() && GetDocument()->GetChangeTrack()->IsProtected())
4337 rtl::OUStringBuffer aBuffer;
4338 SvXMLUnitConverter::encodeBase64(aBuffer, GetDocument()->GetChangeTrack()->GetProtection());
4339 if (aBuffer.getLength())
4341 sal_Int32 nCount(rProps.getLength());
4342 rProps.realloc(nCount + 1);
4343 rProps[nCount].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TrackedChangesProtectionKey"));
4344 rProps[nCount].Value <<= aBuffer.makeStringAndClear();
4351 XMLShapeExport* ScXMLExport::CreateShapeExport()
4353 return new ScXMLShapeExport(*this);
4356 void ScXMLExport::CreateSharedData(const sal_Int32 nTableCount)
4358 pSharedData = new ScMySharedData(nTableCount);
4361 XMLNumberFormatAttributesExportHelper* ScXMLExport::GetNumberFormatAttributesExportHelper()
4363 if (!pNumberFormatAttributesExportHelper)
4364 pNumberFormatAttributesExportHelper = new XMLNumberFormatAttributesExportHelper(GetNumberFormatsSupplier(), *this );
4365 return pNumberFormatAttributesExportHelper;
4368 void ScXMLExport::CollectUserDefinedNamespaces(const SfxItemPool* pPool, sal_uInt16 nAttrib)
4370 const SfxPoolItem* pItem;
4371 sal_uInt16 nItems(pPool->GetItemCount( nAttrib ));
4372 for( sal_uInt16 i = 0; i < nItems; ++i )
4374 if( 0 != (pItem = pPool->GetItem( nAttrib, i ) ) )
4376 const SvXMLAttrContainerItem *pUnknown((const SvXMLAttrContainerItem *)pItem);
4377 if( (pUnknown->GetAttrCount() > 0) )
4379 sal_uInt16 nIdx(pUnknown->GetFirstNamespaceIndex());
4380 while( USHRT_MAX != nIdx )
4382 if( (XML_NAMESPACE_UNKNOWN_FLAG & nIdx) != 0 )
4384 const OUString& rPrefix = pUnknown->GetPrefix( nIdx );
4385 // Add namespace declaration for unknown attributes if
4386 // there aren't existing ones for the prefix used by the
4387 // attibutes
4388 _GetNamespaceMap().Add( rPrefix,
4389 pUnknown->GetNamespace( nIdx ),
4390 XML_NAMESPACE_UNKNOWN );
4392 nIdx = pUnknown->GetNextNamespaceIndex( nIdx );
4398 // #i66550# needed for 'presentation:event-listener' element for URLs in shapes
4399 _GetNamespaceMap().Add(
4400 GetXMLToken( XML_NP_PRESENTATION ),
4401 GetXMLToken( XML_N_PRESENTATION ),
4402 XML_NAMESPACE_PRESENTATION );
4405 void ScXMLExport::IncrementProgressBar(sal_Bool bEditCell, sal_Int32 nInc)
4407 nProgressCount += nInc;
4408 if (bEditCell || nProgressCount > 100)
4410 GetProgressBarHelper()->Increment(nProgressCount);
4411 nProgressCount = 0;
4415 sal_uInt32 ScXMLExport::exportDoc( enum XMLTokenEnum eClass )
4417 if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES|
4418 EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
4420 if (GetDocument())
4422 CollectUserDefinedNamespaces(GetDocument()->GetPool(), ATTR_USERDEF);
4423 CollectUserDefinedNamespaces(GetDocument()->GetEditPool(), EE_PARA_XMLATTRIBS);
4424 CollectUserDefinedNamespaces(GetDocument()->GetEditPool(), EE_CHAR_XMLATTRIBS);
4425 ScDrawLayer* pDrawLayer = GetDocument()->GetDrawLayer();
4426 if (pDrawLayer)
4428 CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), EE_PARA_XMLATTRIBS);
4429 CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), EE_CHAR_XMLATTRIBS);
4430 CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), SDRATTR_XMLATTRIBUTES);
4434 return SvXMLExport::exportDoc( eClass );
4437 // XExporter
4438 void SAL_CALL ScXMLExport::setSourceDocument( const uno::Reference<lang::XComponent>& xComponent )
4439 throw(lang::IllegalArgumentException, uno::RuntimeException)
4441 ScUnoGuard aGuard;
4442 SvXMLExport::setSourceDocument( xComponent );
4444 pDoc = ScXMLConverter::GetScDocument( GetModel() );
4445 DBG_ASSERT( pDoc, "ScXMLExport::setSourceDocument - no ScDocument!" );
4446 if (!pDoc)
4447 throw lang::IllegalArgumentException();
4449 // create ScChangeTrackingExportHelper after document is known
4450 pChangeTrackingExportHelper = new ScChangeTrackingExportHelper(*this);
4452 // Set the document's storage grammar corresponding to the ODF version that
4453 // is to be written.
4454 SvtSaveOptions::ODFDefaultVersion meODFDefaultVersion = getDefaultVersion();
4455 switch (meODFDefaultVersion)
4457 // ODF 1.0 and 1.1 use GRAM_PODF, everything later or unspecified GRAM_ODFF
4458 case SvtSaveOptions::ODFVER_010:
4459 case SvtSaveOptions::ODFVER_011:
4460 pDoc->SetStorageGrammar( formula::FormulaGrammar::GRAM_PODF);
4461 break;
4462 default:
4463 pDoc->SetStorageGrammar( formula::FormulaGrammar::GRAM_ODFF);
4467 // XFilter
4468 sal_Bool SAL_CALL ScXMLExport::filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
4469 throw(::com::sun::star::uno::RuntimeException)
4471 ScUnoGuard aGuard;
4472 if (pDoc)
4473 pDoc->DisableIdle(TRUE);
4474 sal_Bool bReturn(SvXMLExport::filter(aDescriptor));
4475 if (pDoc)
4476 pDoc->DisableIdle(FALSE);
4477 return bReturn;
4480 void SAL_CALL ScXMLExport::cancel()
4481 throw(::com::sun::star::uno::RuntimeException)
4483 ScUnoGuard aGuard;
4484 if (pDoc)
4485 pDoc->DisableIdle(FALSE);
4486 SvXMLExport::cancel();
4489 // XInitialization
4490 void SAL_CALL ScXMLExport::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
4491 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
4493 ScUnoGuard aGuard;
4494 SvXMLExport::initialize(aArguments);
4497 // XServiceInfo
4498 ::rtl::OUString SAL_CALL ScXMLExport::getImplementationName( )
4499 throw(::com::sun::star::uno::RuntimeException)
4501 ScUnoGuard aGuard;
4503 sal_uInt16 nFlags = getExportFlags();
4504 if (nFlags & EXPORT_OASIS)
4506 nFlags |= EXPORT_OASIS;
4507 switch( nFlags )
4509 case EXPORT_ALL:
4510 return ScXMLOasisExport_getImplementationName();
4511 case (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS):
4512 return ScXMLOasisExport_Styles_getImplementationName();
4513 case (EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS):
4514 return ScXMLOasisExport_Content_getImplementationName();
4515 case EXPORT_META:
4516 return ScXMLOasisExport_Meta_getImplementationName();
4517 case EXPORT_SETTINGS:
4518 return ScXMLOasisExport_Settings_getImplementationName();
4519 default:
4520 // generic name for 'unknown' cases
4521 return ScXMLOasisExport_getImplementationName();
4524 else
4526 switch( nFlags )
4528 case EXPORT_ALL:
4529 return ScXMLOOoExport_getImplementationName();
4530 case (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS):
4531 return ScXMLOOoExport_Styles_getImplementationName();
4532 case (EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS):
4533 return ScXMLOOoExport_Content_getImplementationName();
4534 case EXPORT_META:
4535 return ScXMLOOoExport_Meta_getImplementationName();
4536 case EXPORT_SETTINGS:
4537 return ScXMLOOoExport_Settings_getImplementationName();
4538 default:
4539 // generic name for 'unknown' cases
4540 return ScXMLOOoExport_getImplementationName();
4543 return SvXMLExport::getImplementationName();
4546 sal_Bool SAL_CALL ScXMLExport::supportsService( const ::rtl::OUString& ServiceName )
4547 throw(::com::sun::star::uno::RuntimeException)
4549 ScUnoGuard aGuard;
4550 return SvXMLExport::supportsService( ServiceName );
4553 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLExport::getSupportedServiceNames( )
4554 throw(::com::sun::star::uno::RuntimeException)
4556 ScUnoGuard aGuard;
4557 return SvXMLExport::getSupportedServiceNames();
4560 // XUnoTunnel
4561 sal_Int64 SAL_CALL ScXMLExport::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
4562 throw(::com::sun::star::uno::RuntimeException)
4564 ScUnoGuard aGuard;
4565 return SvXMLExport::getSomething(aIdentifier);
4568 void ScXMLExport::DisposingModel()
4570 SvXMLExport::DisposingModel();
4571 pDoc = NULL;
4572 xCurrentTable = 0;