LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlexprt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1720 2955 58.2 %
Date: 2014-04-11 Functions: 112 135 83.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10