LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlexprt.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 2955 0.0 %
Date: 2014-04-14 Functions: 0 135 0.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           0 : OUString lcl_GetFormattedString( ScDocument* pDoc, const ScAddress& rPos )
     209             : {
     210             :     // return text/edit cell string content, with line feeds in edit cells
     211             : 
     212           0 :     if (!pDoc)
     213           0 :         return EMPTY_OUSTRING;
     214             : 
     215           0 :     switch (pDoc->GetCellType(rPos))
     216             :     {
     217             :         case CELLTYPE_STRING:
     218           0 :             return pDoc->GetString(rPos);
     219             :         case CELLTYPE_EDIT:
     220             :         {
     221           0 :             const EditTextObject* pData = pDoc->GetEditText(rPos);
     222           0 :             if (!pData)
     223           0 :                 return EMPTY_OUSTRING;
     224             : 
     225           0 :             EditEngine& rEngine = pDoc->GetEditEngine();
     226           0 :             rEngine.SetText(*pData);
     227           0 :             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           0 : OUString SAL_CALL ScXMLOOoExport_getImplementationName() throw()
     240             : {
     241           0 :     return OUString( "com.sun.star.comp.Calc.XMLExporter" );
     242             : }
     243             : 
     244           0 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_getSupportedServiceNames() throw()
     245             : {
     246           0 :     const OUString aServiceName( ScXMLOOoExport_getImplementationName() );
     247           0 :     return uno::Sequence< OUString >( &aServiceName, 1 );
     248             : }
     249             : 
     250           0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_createInstance(
     251             :                 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
     252             :     throw(uno::Exception, std::exception)
     253             : {
     254           0 :     return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), ScXMLOOoExport_getImplementationName(), EXPORT_ALL );
     255             : }
     256             : 
     257           0 : OUString SAL_CALL ScXMLOOoExport_Meta_getImplementationName() throw()
     258             : {
     259           0 :     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           0 : OUString SAL_CALL ScXMLOOoExport_Styles_getImplementationName() throw()
     276             : {
     277           0 :     return OUString( "com.sun.star.comp.Calc.XMLStylesExporter" );
     278             : }
     279             : 
     280           0 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_Styles_getSupportedServiceNames() throw()
     281             : {
     282           0 :     const OUString aServiceName( ScXMLOOoExport_Styles_getImplementationName() );
     283           0 :     return uno::Sequence< OUString > ( &aServiceName, 1 );
     284             : }
     285             : 
     286           0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Styles_createInstance(
     287             :                 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
     288             :     throw (uno::Exception, std::exception)
     289             : {
     290           0 :     return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), ScXMLOOoExport_Styles_getImplementationName(), EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS);
     291             : }
     292             : 
     293           0 : OUString SAL_CALL ScXMLOOoExport_Content_getImplementationName() throw()
     294             : {
     295           0 :     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           0 : OUString SAL_CALL ScXMLOOoExport_Settings_getImplementationName() throw()
     312             : {
     313           0 :     return OUString( "com.sun.star.comp.Calc.XMLSettingsExporter" );
     314             : }
     315             : 
     316           0 : uno::Sequence< OUString > SAL_CALL ScXMLOOoExport_Settings_getSupportedServiceNames() throw()
     317             : {
     318           0 :     const OUString aServiceName( ScXMLOOoExport_Settings_getImplementationName() );
     319           0 :     return uno::Sequence< OUString > ( &aServiceName, 1 );
     320             : }
     321             : 
     322           0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOOoExport_Settings_createInstance(
     323             :                 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
     324             :     throw( uno::Exception, std::exception )
     325             : {
     326           0 :     return (cppu::OWeakObject*)new ScXMLExport( comphelper::getComponentContext(rSMgr), ScXMLOOoExport_Settings_getImplementationName(), EXPORT_SETTINGS );
     327             : }
     328             : 
     329             : // Oasis Filter
     330             : 
     331           0 : OUString SAL_CALL ScXMLOasisExport_getImplementationName() throw()
     332             : {
     333           0 :     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           0 : OUString SAL_CALL ScXMLOasisExport_Meta_getImplementationName() throw()
     351             : {
     352           0 :     return OUString( "com.sun.star.comp.Calc.XMLOasisMetaExporter" );
     353             : }
     354             : 
     355           0 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Meta_getSupportedServiceNames() throw()
     356             : {
     357           0 :     const OUString aServiceName( ScXMLOasisExport_Meta_getImplementationName() );
     358           0 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     359           0 :     return aSeq;
     360             : }
     361             : 
     362           0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Meta_createInstance(
     363             :                 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
     364             :     throw (uno::Exception, std::exception)
     365             : {
     366           0 :     return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), ScXMLOasisExport_Meta_getImplementationName(), EXPORT_META|EXPORT_OASIS);
     367             : }
     368             : 
     369           0 : OUString SAL_CALL ScXMLOasisExport_Styles_getImplementationName() throw()
     370             : {
     371           0 :     return OUString( "com.sun.star.comp.Calc.XMLOasisStylesExporter" );
     372             : }
     373             : 
     374           0 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Styles_getSupportedServiceNames() throw()
     375             : {
     376           0 :     const OUString aServiceName( ScXMLOasisExport_Styles_getImplementationName() );
     377           0 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     378           0 :     return aSeq;
     379             : }
     380             : 
     381           0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Styles_createInstance(
     382             :     const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
     383             :         throw( uno::Exception, std::exception )
     384             : {
     385           0 :     return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), ScXMLOasisExport_Styles_getImplementationName(), EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS|EXPORT_OASIS);
     386             : }
     387             : 
     388           0 : OUString SAL_CALL ScXMLOasisExport_Content_getImplementationName() throw()
     389             : {
     390           0 :     return OUString( "com.sun.star.comp.Calc.XMLOasisContentExporter" );
     391             : }
     392             : 
     393           0 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Content_getSupportedServiceNames() throw()
     394             : {
     395           0 :     const OUString aServiceName( ScXMLOasisExport_Content_getImplementationName() );
     396           0 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     397           0 :     return aSeq;
     398             : }
     399             : 
     400           0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Content_createInstance(
     401             :                 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
     402             :     throw (uno::Exception, std::exception)
     403             : {
     404           0 :     return (cppu::OWeakObject*)new ScXMLExport(comphelper::getComponentContext(rSMgr), ScXMLOasisExport_Content_getImplementationName(), EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS|EXPORT_OASIS);
     405             : }
     406             : 
     407           0 : OUString SAL_CALL ScXMLOasisExport_Settings_getImplementationName() throw()
     408             : {
     409           0 :     return OUString( "com.sun.star.comp.Calc.XMLOasisSettingsExporter" );
     410             : }
     411             : 
     412           0 : uno::Sequence< OUString > SAL_CALL ScXMLOasisExport_Settings_getSupportedServiceNames() throw()
     413             : {
     414           0 :     const OUString aServiceName( ScXMLOasisExport_Settings_getImplementationName() );
     415           0 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     416           0 :     return aSeq;
     417             : }
     418             : 
     419           0 : uno::Reference< uno::XInterface > SAL_CALL ScXMLOasisExport_Settings_createInstance(
     420             :                 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
     421             :     throw (uno::Exception, std::exception)
     422             : {
     423           0 :     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           0 :     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           0 : ScXMLShapeExport::~ScXMLShapeExport()
     438             : {
     439           0 : }
     440             : 
     441           0 : void ScXMLShapeExport::onExport( const uno::Reference < drawing::XShape >& xShape )
     442             : {
     443           0 :     uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
     444           0 :     if( xShapeProp.is() )
     445             :     {
     446           0 :         sal_Int16 nLayerID = 0;
     447           0 :         if( (xShapeProp->getPropertyValue(OUString( SC_LAYERID )) >>= nLayerID) && (nLayerID == SC_LAYER_BACK) )
     448           0 :             GetExport().AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_BACKGROUND, XML_TRUE);
     449           0 :     }
     450           0 : }
     451             : 
     452           0 : sal_Int16 ScXMLExport::GetFieldUnit()
     453             : {
     454             :     css::uno::Reference<css::sheet::XGlobalSheetSettings> xProperties =
     455           0 :                 css::sheet::GlobalSheetSettings::create( comphelper::getProcessComponentContext() );
     456           0 :     return xProperties->getMetric();
     457             : }
     458             : 
     459             : 
     460             : // #110680#
     461           0 : ScXMLExport::ScXMLExport(
     462             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
     463             :     OUString const & implementationName, sal_uInt16 nExportFlag)
     464           0 : :   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           0 :     mbShowProgress( false )
     491             : {
     492           0 :     if (getExportFlags() & EXPORT_CONTENT)
     493             :     {
     494           0 :         pGroupColumns = new ScMyOpenCloseColumnRowGroup(*this, XML_TABLE_COLUMN_GROUP);
     495           0 :         pGroupRows = new ScMyOpenCloseColumnRowGroup(*this, XML_TABLE_ROW_GROUP);
     496           0 :         pColumnStyles = new ScColumnStyles();
     497           0 :         pRowStyles = new ScRowStyles();
     498           0 :         pRowFormatRanges = new ScRowFormatRanges();
     499           0 :         pMergedRangesContainer = new ScMyMergedRangesContainer();
     500           0 :         pValidationsContainer = new ScMyValidationsContainer();
     501           0 :         mpCellsItr.reset(new ScMyNotEmptyCellsIterator(*this));
     502           0 :         pDefaults = new ScMyDefaultStyles();
     503             :     }
     504           0 :     pCellStyles = new ScFormatRangeStyles();
     505             : 
     506             :     // document is not set here - create ScChangeTrackingExportHelper later
     507             : 
     508           0 :     xScPropHdlFactory = new XMLScPropHdlFactory;
     509           0 :     xCellStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScCellStylesProperties, xScPropHdlFactory, true);
     510           0 :     xColumnStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScColumnStylesProperties, xScPropHdlFactory, true);
     511           0 :     xRowStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScRowStylesProperties, xScPropHdlFactory, true);
     512           0 :     xTableStylesPropertySetMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLScTableStylesProperties, xScPropHdlFactory, true);
     513           0 :     xCellStylesExportPropertySetMapper = new ScXMLCellExportPropertyMapper(xCellStylesPropertySetMapper);
     514           0 :     xCellStylesExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(*this));
     515           0 :     xColumnStylesExportPropertySetMapper = new ScXMLColumnExportPropertyMapper(xColumnStylesPropertySetMapper);
     516           0 :     xRowStylesExportPropertySetMapper = new ScXMLRowExportPropertyMapper(xRowStylesPropertySetMapper);
     517           0 :     xTableStylesExportPropertySetMapper = new ScXMLTableExportPropertyMapper(xTableStylesPropertySetMapper);
     518             : 
     519             :     GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_CELL, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME),
     520           0 :         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           0 :         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           0 :         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           0 :         xTableStylesExportPropertySetMapper, OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX));
     527             : 
     528           0 :     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           0 :         sExternalRefTabStyleName = "ta_extref";
     534           0 :         GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_TABLE, sExternalRefTabStyleName);
     535             : 
     536           0 :         sAttrName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_NAME));
     537           0 :         sAttrStyleName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_STYLE_NAME));
     538           0 :         sAttrColumnsRepeated = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_NUMBER_COLUMNS_REPEATED));
     539           0 :         sAttrFormula = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_FORMULA));
     540           0 :         sAttrStringValue = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_STRING_VALUE));
     541           0 :         sAttrValueType = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE_TYPE));
     542           0 :         sElemCell = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_CELL));
     543           0 :         sElemCoveredCell = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_COVERED_TABLE_CELL));
     544           0 :         sElemCol = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_COLUMN));
     545           0 :         sElemRow = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_ROW));
     546           0 :         sElemTab = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE));
     547           0 :         sElemP = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TEXT, GetXMLToken(XML_P));
     548             :     }
     549           0 : }
     550             : 
     551             : 
     552           0 : ScXMLExport::~ScXMLExport()
     553             : {
     554           0 :         delete pGroupColumns;
     555           0 :         delete pGroupRows;
     556           0 :         delete pColumnStyles;
     557           0 :         delete pRowStyles;
     558           0 :         delete pCellStyles;
     559           0 :         delete pRowFormatRanges;
     560           0 :         delete pMergedRangesContainer;
     561           0 :         delete pValidationsContainer;
     562           0 :         delete pChangeTrackingExportHelper;
     563           0 :         delete pChartListener;
     564           0 :         delete pDefaults;
     565           0 :         delete pNumberFormatAttributesExportHelper;
     566           0 : }
     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           0 : void ScXMLExport::CollectSharedData(sal_Int32& nTableCount, sal_Int32& nShapesCount)
     617             : {
     618           0 :     if (!GetModel().is())
     619           0 :         return;
     620             : 
     621           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc(GetModel(), uno::UNO_QUERY);
     622           0 :     if (!xSpreadDoc.is())
     623           0 :         return;
     624             : 
     625           0 :     uno::Reference<container::XIndexAccess> xIndex(xSpreadDoc->getSheets(), uno::UNO_QUERY);
     626           0 :     if (!xIndex.is())
     627           0 :         return;
     628             : 
     629           0 :     nTableCount = xIndex->getCount();
     630           0 :     if (!pSharedData)
     631           0 :         CreateSharedData(nTableCount);
     632             : 
     633           0 :     pCellStyles->AddNewTable(nTableCount - 1);
     634             : 
     635           0 :     for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
     636             :     {
     637           0 :         nCurrentTable = sal::static_int_cast<sal_uInt16>(nTable);
     638           0 :         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIndex->getByIndex(nTable), uno::UNO_QUERY);
     639           0 :         if (!xDrawPageSupplier.is())
     640           0 :             continue;
     641             : 
     642           0 :         uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage());
     643           0 :         ScMyDrawPage aDrawPage;
     644           0 :         aDrawPage.bHasForms = false;
     645           0 :         aDrawPage.xDrawPage.set(xDrawPage);
     646           0 :         pSharedData->AddDrawPage(aDrawPage, nTable);
     647           0 :         uno::Reference<container::XIndexAccess> xShapesIndex(xDrawPage, uno::UNO_QUERY);
     648           0 :         if (!xShapesIndex.is())
     649           0 :             continue;
     650             : 
     651           0 :         sal_Int32 nShapes = xShapesIndex->getCount();
     652           0 :         for (sal_Int32 nShape = 0; nShape < nShapes; ++nShape)
     653             :         {
     654           0 :             uno::Reference<drawing::XShape> xShape(xShapesIndex->getByIndex(nShape), uno::UNO_QUERY);
     655           0 :             if (!xShape.is())
     656           0 :                 continue;
     657             : 
     658           0 :             uno::Reference<beans::XPropertySet> xShapeProp(xShape, uno::UNO_QUERY);
     659           0 :             if (!xShapeProp.is())
     660           0 :                 continue;
     661             : 
     662           0 :             sal_Int16 nLayerID = 0;
     663           0 :             bool bExtracted = xShapeProp->getPropertyValue(sLayerID) >>= nLayerID;
     664           0 :             if (!bExtracted)
     665           0 :                 continue;
     666             : 
     667           0 :             if ((nLayerID == SC_LAYER_INTERN) || (nLayerID == SC_LAYER_HIDDEN))
     668             :             {
     669           0 :                 CollectInternalShape(xShape);
     670           0 :                 continue;
     671             :             }
     672             : 
     673           0 :             ++nShapesCount;
     674             : 
     675           0 :             SvxShape* pShapeImp = SvxShape::getImplementation(xShape);
     676           0 :             if (!pShapeImp)
     677           0 :                 continue;
     678             : 
     679           0 :             SdrObject* pSdrObj = pShapeImp->GetSdrObject();
     680           0 :             if (!pSdrObj)
     681           0 :                 continue;
     682             : 
     683           0 :             if (ScDrawObjData *pAnchor = ScDrawLayer::GetNonRotatedObjData(pSdrObj))
     684             :             {
     685           0 :                 ScMyShape aMyShape;
     686           0 :                 aMyShape.aAddress = pAnchor->maStart;
     687             :                 SAL_WARN_IF(aMyShape.aAddress.Tab() != nTable, "sc", "not anchored to current sheet!");
     688           0 :                 aMyShape.aAddress.SetTab(nTable);
     689           0 :                 aMyShape.aEndAddress = pAnchor->maEnd;
     690           0 :                 aMyShape.aEndAddress.SetTab( nTable );
     691           0 :                 aMyShape.nEndX = pAnchor->maEndOffset.X();
     692           0 :                 aMyShape.nEndY = pAnchor->maEndOffset.Y();
     693           0 :                 aMyShape.xShape = xShape;
     694           0 :                 pSharedData->AddNewShape(aMyShape);
     695           0 :                 pSharedData->SetLastColumn(nTable, pAnchor->maStart.Col());
     696           0 :                 pSharedData->SetLastRow(nTable, pAnchor->maStart.Row());
     697             :             }
     698             :             else
     699           0 :                 pSharedData->AddTableShape(nTable, xShape);
     700           0 :         }
     701           0 :     }
     702             : }
     703             : 
     704           0 : 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           0 :     ScMyShapeList aDummyInitList;
     711             : 
     712           0 :     pSharedData->SortShapesContainer();
     713           0 :     pSharedData->SortNoteShapes();
     714           0 :     const ScMyShapeList* pShapeList(NULL);
     715           0 :     ScMyShapeList::const_iterator aShapeItr = aDummyInitList.end();
     716           0 :     if (pSharedData->GetShapesContainer())
     717             :     {
     718           0 :         pShapeList = pSharedData->GetShapesContainer()->GetShapes();
     719           0 :         aShapeItr = pShapeList->begin();
     720             :     }
     721           0 :     if (pSharedData->HasDrawPage())
     722             :     {
     723           0 :         for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
     724             :         {
     725           0 :             uno::Reference<drawing::XDrawPage> xDrawPage(pSharedData->GetDrawPage(nTable));
     726           0 :             uno::Reference<drawing::XShapes> xShapes (xDrawPage, uno::UNO_QUERY);
     727             : 
     728           0 :             if (xShapes.is())
     729             :             {
     730           0 :                 GetShapeExport()->seekShapes(xShapes);
     731           0 :                 uno::Reference< form::XFormsSupplier2 > xFormsSupplier( xDrawPage, uno::UNO_QUERY );
     732           0 :                 if( xFormsSupplier.is() && xFormsSupplier->hasForms() )
     733             :                 {
     734           0 :                     GetFormExport()->examineForms(xDrawPage);
     735           0 :                     pSharedData->SetDrawPageHasForms(nTable, true);
     736             :                 }
     737           0 :                 ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
     738           0 :                 if (pTableShapes)
     739             :                 {
     740           0 :                     ScMyTableXShapes::iterator aItr((*pTableShapes)[nTable].begin());
     741           0 :                     ScMyTableXShapes::iterator aEndItr((*pTableShapes)[nTable].end());
     742           0 :                     while (aItr != aEndItr)
     743             :                     {
     744           0 :                         GetShapeExport()->collectShapeAutoStyles(*aItr);
     745           0 :                         IncrementProgressBar(false);
     746           0 :                         ++aItr;
     747             :                     }
     748             :                 }
     749           0 :                 if (pShapeList)
     750             :                 {
     751           0 :                     ScMyShapeList::const_iterator aEndItr(pShapeList->end());
     752           0 :                     while (aShapeItr != aEndItr && (static_cast<sal_Int32>(aShapeItr->aAddress.Tab()) == nTable))
     753             :                     {
     754           0 :                         GetShapeExport()->collectShapeAutoStyles(aShapeItr->xShape);
     755           0 :                         IncrementProgressBar(false);
     756           0 :                         ++aShapeItr;
     757             :                     }
     758             :                 }
     759           0 :                 if (pSharedData->GetNoteShapes())
     760             :                 {
     761           0 :                     const ScMyNoteShapeList* pNoteShapes = pSharedData->GetNoteShapes()->GetNotes();
     762           0 :                     if (pNoteShapes)
     763             :                     {
     764           0 :                         for (ScMyNoteShapeList::const_iterator aNoteShapeItr = pNoteShapes->begin(), aNoteShapeEndItr = pNoteShapes->end();
     765             :                              aNoteShapeItr != aNoteShapeEndItr; ++aNoteShapeItr)
     766             :                         {
     767           0 :                             if (static_cast<sal_Int32>(aNoteShapeItr->aPos.Tab()) == nTable)
     768           0 :                                 GetShapeExport()->collectShapeAutoStyles(aNoteShapeItr->xShape);
     769             :                         }
     770             :                     }
     771           0 :                 }
     772             :             }
     773           0 :         }
     774             :     }
     775           0 :     pSharedData->SortNoteShapes(); // sort twice, because some more shapes are added
     776           0 : }
     777             : 
     778           0 : void ScXMLExport::_ExportMeta()
     779             : {
     780           0 :     sal_Int32 nCellCount(pDoc ? pDoc->GetCellCount() : 0);
     781           0 :     sal_Int32 nTableCount(0);
     782           0 :     sal_Int32 nShapesCount(0);
     783           0 :     GetAutoStylePool()->ClearEntries();
     784           0 :     CollectSharedData(nTableCount, nShapesCount);
     785             : 
     786           0 :     uno::Sequence<beans::NamedValue> stats(3);
     787           0 :     stats[0] = beans::NamedValue(OUString("TableCount"),
     788           0 :                 uno::makeAny(nTableCount));
     789           0 :     stats[1] = beans::NamedValue(OUString("CellCount"),
     790           0 :                 uno::makeAny(nCellCount));
     791           0 :     stats[2] = beans::NamedValue(OUString("ObjectCount"),
     792           0 :                 uno::makeAny(nShapesCount));
     793             : 
     794             :     // update document statistics at the model
     795           0 :     uno::Reference<document::XDocumentPropertiesSupplier> xPropSup(GetModel(),
     796           0 :         uno::UNO_QUERY_THROW);
     797             :     uno::Reference<document::XDocumentProperties> xDocProps(
     798           0 :         xPropSup->getDocumentProperties());
     799           0 :     if (xDocProps.is()) {
     800           0 :         xDocProps->setDocumentStatistics(stats);
     801             :     }
     802             : 
     803             :     // export document properties
     804           0 :     SvXMLExport::_ExportMeta();
     805           0 : }
     806             : 
     807           0 : void ScXMLExport::_ExportFontDecls()
     808             : {
     809           0 :     GetFontAutoStylePool(); // make sure the pool is created
     810           0 :     SvXMLExport::_ExportFontDecls();
     811           0 : }
     812             : 
     813           0 : table::CellRangeAddress ScXMLExport::GetEndAddress(const uno::Reference<sheet::XSpreadsheet>& xTable, const sal_Int32 /* nTable */)
     814             : {
     815           0 :     table::CellRangeAddress aCellAddress;
     816           0 :     uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursor());
     817           0 :     uno::Reference<sheet::XUsedAreaCursor> xUsedArea (xCursor, uno::UNO_QUERY);
     818           0 :     uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
     819           0 :     if (xUsedArea.is() && xCellAddress.is())
     820             :     {
     821           0 :         xUsedArea->gotoEndOfUsedArea(true);
     822           0 :         aCellAddress = xCellAddress->getRangeAddress();
     823             :     }
     824           0 :     return aCellAddress;
     825             : }
     826             : 
     827           0 : void ScXMLExport::GetAreaLinks( ScMyAreaLinksContainer& rAreaLinks )
     828             : {
     829           0 :     if (pDoc->GetLinkManager())
     830             :     {
     831           0 :         const sfx2::SvBaseLinks& rLinks = pDoc->GetLinkManager()->GetLinks();
     832           0 :         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           0 :     rAreaLinks.Sort();
     849           0 : }
     850             : 
     851             : // core implementation
     852           0 : void ScXMLExport::GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp )
     853             : {
     854           0 :     if (pDoc)
     855             :     {
     856           0 :         ScDetOpList* pOpList(pDoc->GetDetOpList());
     857           0 :         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           0 : }
     881             : 
     882           0 : void ScXMLExport::WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex,
     883             :     const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible)
     884             : {
     885           0 :     CheckAttrList();
     886           0 :     AddAttribute(sAttrStyleName, *pColumnStyles->GetStyleNameByIndex(nStyleIndex));
     887           0 :     if (!bIsVisible)
     888           0 :         AddAttribute(XML_NAMESPACE_TABLE, XML_VISIBILITY, XML_COLLAPSE);
     889           0 :     if (nRepeatColumns > 1)
     890             :     {
     891           0 :         OUString sOUEndCol(OUString::number(nRepeatColumns));
     892           0 :         AddAttribute(sAttrColumnsRepeated, sOUEndCol);
     893             :     }
     894           0 :     if (nIndex != -1)
     895           0 :         AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
     896           0 :     SvXMLElementExport aElemC(*this, sElemCol, true, true);
     897           0 : }
     898             : 
     899           0 : void ScXMLExport::WriteColumn(const sal_Int32 nColumn, const sal_Int32 nRepeatColumns,
     900             :     const sal_Int32 nStyleIndex, const bool bIsVisible)
     901             : {
     902           0 :     sal_Int32 nRepeat(1);
     903           0 :     sal_Int32 nPrevIndex((*pDefaults->GetColDefaults())[nColumn].nIndex);
     904           0 :     bool bPrevAutoStyle((*pDefaults->GetColDefaults())[nColumn].bIsAutoStyle);
     905           0 :     for (sal_Int32 i = nColumn + 1; i < nColumn + nRepeatColumns; ++i)
     906             :     {
     907           0 :         if (((*pDefaults->GetColDefaults())[i].nIndex != nPrevIndex) ||
     908           0 :             ((*pDefaults->GetColDefaults())[i].bIsAutoStyle != bPrevAutoStyle))
     909             :         {
     910           0 :             WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
     911           0 :             nPrevIndex = (*pDefaults->GetColDefaults())[i].nIndex;
     912           0 :             bPrevAutoStyle = (*pDefaults->GetColDefaults())[i].bIsAutoStyle;
     913           0 :             nRepeat = 1;
     914             :         }
     915             :         else
     916           0 :             ++nRepeat;
     917             :     }
     918           0 :     WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
     919           0 : }
     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           0 : void ScXMLExport::ExportColumns(const sal_Int32 nTable, const table::CellRangeAddress& aColumnHeaderRange, const bool bHasColumnHeader)
     932             : {
     933           0 :     sal_Int32 nColsRepeated (1);
     934             :     sal_Int32 nIndex;
     935           0 :     sal_Int32 nPrevColumn(0);
     936           0 :     bool bPrevIsVisible (true);
     937           0 :     bool bWasHeader (false);
     938           0 :     bool bIsHeader (false);
     939           0 :     bool bIsClosed (true);
     940           0 :     sal_Int32 nPrevIndex (-1);
     941             :     sal_Int32 nColumn;
     942           0 :     for (nColumn = 0; nColumn <= pSharedData->GetLastColumn(nTable); ++nColumn)
     943             :     {
     944           0 :         CheckAttrList();
     945           0 :         bool bIsVisible(true);
     946           0 :         nIndex = pColumnStyles->GetStyleNameIndex(nTable, nColumn, bIsVisible);
     947             : 
     948           0 :         bIsHeader = bHasColumnHeader && (aColumnHeaderRange.StartColumn <= nColumn) && (nColumn <= aColumnHeaderRange.EndColumn);
     949           0 :         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           0 :         else if (nColumn == 0)
     986             :         {
     987           0 :             if (pGroupColumns->IsGroupStart(nColumn))
     988           0 :                 pGroupColumns->OpenGroups(nColumn);
     989           0 :             bPrevIsVisible = bIsVisible;
     990           0 :             nPrevIndex = nIndex;
     991             :         }
     992           0 :         else if ((bIsVisible == bPrevIsVisible) && (nIndex == nPrevIndex) &&
     993           0 :             !pGroupColumns->IsGroupStart(nColumn) && !pGroupColumns->IsGroupEnd(nColumn - 1))
     994           0 :             ++nColsRepeated;
     995             :         else
     996             :         {
     997           0 :             WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
     998           0 :             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           0 :             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           0 :             bPrevIsVisible = bIsVisible;
    1015           0 :             nPrevIndex = nIndex;
    1016           0 :             nPrevColumn = nColumn;
    1017           0 :             nColsRepeated = 1;
    1018             :         }
    1019             :     }
    1020           0 :     WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
    1021           0 :     if (!bIsClosed)
    1022           0 :         CloseHeaderColumn();
    1023           0 :     if (pGroupColumns->IsGroupEnd(nColumn - 1))
    1024           0 :         pGroupColumns->CloseGroups(nColumn - 1);
    1025           0 : }
    1026             : 
    1027           0 : void ScXMLExport::ExportExternalRefCacheStyles()
    1028             : {
    1029             :     sal_Int32 nEntryIndex = GetCellStylesPropertySetMapper()->FindEntryIndex(
    1030           0 :         "NumberFormat", XML_NAMESPACE_STYLE, OUString("data-style-name"));
    1031             : 
    1032           0 :     if (nEntryIndex < 0)
    1033             :         // No entry index for the number format is found.
    1034           0 :         return;
    1035             : 
    1036           0 :     ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
    1037           0 :     if (!pRefMgr->hasExternalData())
    1038             :         // No external reference data cached.
    1039           0 :         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           0 : const SvxFieldData* toXMLPropertyStates(
    1082             :     std::vector<XMLPropertyState>& rPropStates, const std::vector<const SfxPoolItem*>& rSecAttrs,
    1083             :     const UniReference<XMLPropertySetMapper>& xMapper, const ScXMLEditAttributeMap& rAttrMap )
    1084             : {
    1085           0 :     const SvxFieldData* pField = NULL;
    1086           0 :     sal_Int32 nEntryCount = xMapper->GetEntryCount();
    1087           0 :     rPropStates.reserve(rSecAttrs.size());
    1088           0 :     std::vector<const SfxPoolItem*>::const_iterator it = rSecAttrs.begin(), itEnd = rSecAttrs.end();
    1089           0 :     for (; it != itEnd; ++it)
    1090             :     {
    1091           0 :         const SfxPoolItem* p = *it;
    1092           0 :         if (p->Which() == EE_FEATURE_FIELD)
    1093             :         {
    1094           0 :             pField = static_cast<const SvxFieldItem*>(p)->GetField();
    1095           0 :             continue;
    1096             :         }
    1097             : 
    1098           0 :         const ScXMLEditAttributeMap::Entry* pEntry = rAttrMap.getEntryByItemID(p->Which());
    1099           0 :         if (!pEntry)
    1100           0 :             continue;
    1101             : 
    1102             :         sal_Int32 nIndex = xMapper->GetEntryIndex(
    1103           0 :             pEntry->nmXMLNS, OUString::createFromAscii(pEntry->mpXMLName), 0);
    1104             : 
    1105           0 :         if (nIndex == -1 || nIndex >= nEntryCount)
    1106           0 :             continue;
    1107             : 
    1108           0 :         uno::Any aAny;
    1109           0 :         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           0 :                 if (!static_cast<const SvxWeightItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
    1126           0 :                     continue;
    1127             : 
    1128           0 :                 rPropStates.push_back(XMLPropertyState(nIndex, aAny));
    1129             :             }
    1130           0 :             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           0 :                 if (!static_cast<const SvxPostureItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
    1146           0 :                     continue;
    1147             : 
    1148           0 :                 rPropStates.push_back(XMLPropertyState(nIndex, aAny));
    1149             :             }
    1150           0 :             break;
    1151             :             case EE_CHAR_UNDERLINE:
    1152             :             {
    1153             :                 // Underline attribute needs to export multiple entries.
    1154           0 :                 sal_Int32 nIndexStyle = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, "text-underline-style", 0);
    1155           0 :                 if (nIndexStyle == -1 || nIndexStyle > nEntryCount)
    1156             :                     break;
    1157             : 
    1158           0 :                 sal_Int32 nIndexWidth = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, "text-underline-width", 0);
    1159           0 :                 if (nIndexWidth == -1 || nIndexWidth > nEntryCount)
    1160             :                     break;
    1161             : 
    1162           0 :                 sal_Int32 nIndexColor = xMapper->FindEntryIndex("CharUnderlineColor", XML_NAMESPACE_STYLE, "text-underline-color");
    1163           0 :                 if (nIndexColor == -1 || nIndexColor > nEntryCount)
    1164             :                     break;
    1165             : 
    1166           0 :                 sal_Int32 nIndexHasColor = xMapper->FindEntryIndex("CharUnderlineHasColor", XML_NAMESPACE_STYLE, "text-underline-color");
    1167           0 :                 if (nIndexHasColor == -1 || nIndexHasColor > nEntryCount)
    1168             :                     break;
    1169             : 
    1170           0 :                 const SvxUnderlineItem* pUL = static_cast<const SvxUnderlineItem*>(p);
    1171           0 :                 pUL->QueryValue(aAny, MID_TL_STYLE);
    1172           0 :                 rPropStates.push_back(XMLPropertyState(nIndexStyle, aAny));
    1173           0 :                 rPropStates.push_back(XMLPropertyState(nIndexWidth, aAny));
    1174             : 
    1175           0 :                 pUL->QueryValue(aAny, MID_TL_COLOR);
    1176           0 :                 rPropStates.push_back(XMLPropertyState(nIndexColor, aAny));
    1177             : 
    1178           0 :                 pUL->QueryValue(aAny, MID_TL_HASCOLOR);
    1179           0 :                 rPropStates.push_back(XMLPropertyState(nIndexHasColor, aAny));
    1180             :             }
    1181           0 :             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           0 :                 if (!static_cast<const SvxCrossedOutItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
    1209           0 :                     continue;
    1210             : 
    1211           0 :                 rPropStates.push_back(XMLPropertyState(nIndex, aAny));
    1212             :             }
    1213           0 :             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           0 :     }
    1292             : 
    1293           0 :     return pField;
    1294             : }
    1295             : 
    1296             : }
    1297             : 
    1298           0 : void ScXMLExport::ExportCellTextAutoStyles(sal_Int32 nTable)
    1299             : {
    1300           0 :     if (!ValidTab(nTable))
    1301           0 :         return;
    1302             : 
    1303           0 :     UniReference<XMLPropertySetMapper> xMapper = GetTextParagraphExport()->GetTextPropMapper()->getPropertySetMapper();
    1304           0 :     UniReference<SvXMLAutoStylePoolP> xStylePool = GetAutoStylePool();
    1305           0 :     const ScXMLEditAttributeMap& rAttrMap = GetEditAttributeMap();
    1306             : 
    1307           0 :     sc::EditTextIterator aIter(*pDoc, nTable);
    1308           0 :     sal_Int32 nCellCount = 0;
    1309           0 :     for (const EditTextObject* pEdit = aIter.first(); pEdit; pEdit = aIter.next(), ++nCellCount)
    1310             :     {
    1311           0 :         std::vector<editeng::Section> aAttrs;
    1312           0 :         pEdit->GetAllSections(aAttrs);
    1313           0 :         if (aAttrs.empty())
    1314           0 :             continue;
    1315             : 
    1316           0 :         std::vector<editeng::Section>::const_iterator itSec = aAttrs.begin(), itSecEnd = aAttrs.end();
    1317           0 :         for (; itSec != itSecEnd; ++itSec)
    1318             :         {
    1319           0 :             const std::vector<const SfxPoolItem*>& rSecAttrs = itSec->maAttributes;
    1320           0 :             if (rSecAttrs.empty())
    1321             :                 // No formats applied to this section. Skip it.
    1322           0 :                 continue;
    1323             : 
    1324           0 :             std::vector<XMLPropertyState> aPropStates;
    1325           0 :             toXMLPropertyStates(aPropStates, rSecAttrs, xMapper, rAttrMap);
    1326           0 :             if (!aPropStates.empty())
    1327           0 :                 xStylePool->Add(XML_STYLE_FAMILY_TEXT_TEXT, OUString(), aPropStates, false);
    1328           0 :         }
    1329           0 :     }
    1330             : 
    1331           0 :     GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nCellCount);
    1332             : }
    1333             : 
    1334           0 : void ScXMLExport::WriteRowContent()
    1335             : {
    1336           0 :     ScMyRowFormatRange aRange;
    1337           0 :     sal_Int32 nIndex(-1);
    1338             : #if OSL_DEBUG_LEVEL > 0
    1339             :     sal_Int32 nPrevCol(0);
    1340             : #endif
    1341           0 :     sal_Int32 nCols(0);
    1342           0 :     sal_Int32 nPrevValidationIndex(-1);
    1343           0 :     bool bIsAutoStyle(true);
    1344           0 :     bool bIsFirst(true);
    1345           0 :     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           0 :         if (bIsFirst)
    1351             :         {
    1352           0 :             nIndex = aRange.nIndex;
    1353           0 :             nPrevValidationIndex = aRange.nValidationIndex;
    1354           0 :             bIsAutoStyle = aRange.bIsAutoStyle;
    1355           0 :             nCols = aRange.nRepeatColumns;
    1356           0 :             bIsFirst = false;
    1357             : #if OSL_DEBUG_LEVEL > 0
    1358             :             nPrevCol = aRange.nStartColumn;
    1359             : #endif
    1360             :         }
    1361             :         else
    1362             :         {
    1363           0 :             if (((aRange.nIndex == nIndex && aRange.bIsAutoStyle == bIsAutoStyle) ||
    1364           0 :                 (aRange.nIndex == nIndex && nIndex == -1)) &&
    1365           0 :                 nPrevValidationIndex == aRange.nValidationIndex)
    1366           0 :                 nCols += aRange.nRepeatColumns;
    1367             :             else
    1368             :             {
    1369           0 :                 if (nIndex != -1)
    1370           0 :                     AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
    1371           0 :                 if (nPrevValidationIndex > -1)
    1372           0 :                     AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
    1373           0 :                 if (nCols > 1)
    1374             :                 {
    1375           0 :                     OUStringBuffer aBuf;
    1376           0 :                     ::sax::Converter::convertNumber(aBuf, nCols);
    1377           0 :                     AddAttribute(sAttrColumnsRepeated, aBuf.makeStringAndClear());
    1378             :                 }
    1379           0 :                 SvXMLElementExport aElemC(*this, sElemCell, true, true);
    1380           0 :                 nIndex = aRange.nIndex;
    1381           0 :                 bIsAutoStyle = aRange.bIsAutoStyle;
    1382           0 :                 nCols = aRange.nRepeatColumns;
    1383           0 :                 nPrevValidationIndex = aRange.nValidationIndex;
    1384             : #if OSL_DEBUG_LEVEL > 0
    1385             :                 nPrevCol = aRange.nStartColumn;
    1386             : #endif
    1387             :             }
    1388             :         }
    1389             :     }
    1390           0 :     if (!bIsFirst)
    1391             :     {
    1392           0 :         table::CellAddress aCellAddress;
    1393           0 :         if (nIndex != -1)
    1394           0 :             AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
    1395           0 :         if (nPrevValidationIndex > -1)
    1396           0 :             AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
    1397           0 :         if (nCols > 1)
    1398             :         {
    1399           0 :             OUStringBuffer aBuf;
    1400           0 :             ::sax::Converter::convertNumber(aBuf, nCols);
    1401           0 :             AddAttribute(sAttrColumnsRepeated, aBuf.makeStringAndClear());
    1402             :         }
    1403           0 :         SvXMLElementExport aElemC(*this, sElemCell, true, true);
    1404             :     }
    1405           0 : }
    1406             : 
    1407           0 : void ScXMLExport::WriteRowStartTag(
    1408             :     const sal_Int32 nIndex, const sal_Int32 nEqualRows,
    1409             :     bool bHidden, bool bFiltered)
    1410             : {
    1411           0 :     AddAttribute(sAttrStyleName, *pRowStyles->GetStyleNameByIndex(nIndex));
    1412           0 :     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           0 :     if (nEqualRows > 1)
    1420             :     {
    1421           0 :         OUStringBuffer aBuf;
    1422           0 :         ::sax::Converter::convertNumber(aBuf, nEqualRows);
    1423           0 :         AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, aBuf.makeStringAndClear());
    1424             :     }
    1425             : 
    1426           0 :     StartElement( sElemRow, true);
    1427           0 : }
    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           0 : void ScXMLExport::OpenNewRow(
    1441             :     const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
    1442             :     bool bHidden, bool bFiltered)
    1443             : {
    1444           0 :     nOpenRow = nStartRow;
    1445           0 :     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           0 :     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           0 :         WriteRowStartTag(nIndex, nEqualRows, bHidden, bFiltered);
    1473           0 : }
    1474             : 
    1475           0 : void ScXMLExport::OpenAndCloseRow(
    1476             :     const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
    1477             :     bool bHidden, bool bFiltered)
    1478             : {
    1479           0 :     OpenNewRow(nIndex, nStartRow, nEqualRows, bHidden, bFiltered);
    1480           0 :     WriteRowContent();
    1481           0 :     CloseRow(nStartRow + nEqualRows - 1);
    1482           0 :     pRowFormatRanges->Clear();
    1483           0 : }
    1484             : 
    1485           0 : void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLCachedRowAttrAccess& rRowAttr)
    1486             : {
    1487           0 :     if (nRepeatRow > 1)
    1488             :     {
    1489           0 :         sal_Int32 nPrevIndex(0), nIndex;
    1490           0 :         bool bPrevHidden = false;
    1491           0 :         bool bPrevFiltered = false;
    1492           0 :         bool bHidden = false;
    1493           0 :         bool bFiltered = false;
    1494           0 :         sal_Int32 nEqualRows(1);
    1495           0 :         sal_Int32 nEndRow(nStartRow + nRepeatRow);
    1496             :         sal_Int32 nRow;
    1497           0 :         for (nRow = nStartRow; nRow < nEndRow; ++nRow)
    1498             :         {
    1499           0 :             if (nRow == nStartRow)
    1500             :             {
    1501           0 :                 nPrevIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
    1502           0 :                 if (pDoc)
    1503             :                 {
    1504           0 :                     bPrevHidden = rRowAttr.rowHidden(nTable, nRow);
    1505           0 :                     bPrevFiltered = rRowAttr.rowFiltered(nTable, nRow);
    1506             :                 }
    1507             :             }
    1508             :             else
    1509             :             {
    1510           0 :                 nIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
    1511           0 :                 if (pDoc)
    1512             :                 {
    1513           0 :                     bHidden = rRowAttr.rowHidden(nTable, nRow);
    1514           0 :                     bFiltered = rRowAttr.rowFiltered(nTable, nRow);
    1515             :                 }
    1516           0 :                 if (nIndex == nPrevIndex && bHidden == bPrevHidden && bFiltered == bPrevFiltered &&
    1517           0 :                     !(bHasRowHeader && ((nRow == aRowHeaderRange.StartRow) || (nRow - 1 == aRowHeaderRange.EndRow))) &&
    1518           0 :                     !(pGroupRows->IsGroupStart(nRow)) &&
    1519           0 :                     !(pGroupRows->IsGroupEnd(nRow - 1)))
    1520           0 :                     ++nEqualRows;
    1521             :                 else
    1522             :                 {
    1523           0 :                     if (nRow < nEndRow)
    1524             :                     {
    1525           0 :                         ScRowFormatRanges* pTempRowFormatRanges = new ScRowFormatRanges(pRowFormatRanges);
    1526           0 :                         OpenAndCloseRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
    1527           0 :                         delete pRowFormatRanges;
    1528           0 :                         pRowFormatRanges = pTempRowFormatRanges;
    1529             :                     }
    1530             :                     else
    1531           0 :                         OpenAndCloseRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
    1532           0 :                     nEqualRows = 1;
    1533           0 :                     nPrevIndex = nIndex;
    1534           0 :                     bPrevHidden = bHidden;
    1535           0 :                     bPrevFiltered = bFiltered;
    1536             :                 }
    1537             :             }
    1538             :         }
    1539           0 :         OpenNewRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
    1540             :     }
    1541             :     else
    1542             :     {
    1543           0 :         sal_Int32 nIndex = pRowStyles->GetStyleNameIndex(nTable, nStartRow);
    1544           0 :         bool bHidden = false;
    1545           0 :         bool bFiltered = false;
    1546           0 :         if (pDoc)
    1547             :         {
    1548           0 :             bHidden = rRowAttr.rowHidden(nTable, nStartRow);
    1549           0 :             bFiltered = rRowAttr.rowFiltered(nTable, nStartRow);
    1550             :         }
    1551           0 :         OpenNewRow(nIndex, nStartRow, 1, bHidden, bFiltered);
    1552             :     }
    1553           0 :     nOpenRow = nStartRow + nRepeatRow - 1;
    1554           0 : }
    1555             : 
    1556           0 : void ScXMLExport::CloseRow(const sal_Int32 nRow)
    1557             : {
    1558           0 :     if (nOpenRow > -1)
    1559             :     {
    1560           0 :         EndElement(sElemRow, true);
    1561           0 :         if (bHasRowHeader && nRow == aRowHeaderRange.EndRow)
    1562             :         {
    1563           0 :             CloseHeaderRows();
    1564           0 :             bRowHeaderOpen = false;
    1565             :         }
    1566           0 :         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           0 :     nOpenRow = -1;
    1576           0 : }
    1577             : 
    1578           0 : 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           0 :     pRowFormatRanges->Clear();
    1582           0 :     ScXMLCachedRowAttrAccess aRowAttr(pDoc);
    1583           0 :     if (nStartRow == nEndRow)
    1584             :     {
    1585           0 :         pCellStyles->GetFormatRanges(nStartCol, nEndCol, nStartRow, nSheet, pRowFormatRanges);
    1586           0 :         if (nOpenRow == - 1)
    1587           0 :             OpenRow(nSheet, nStartRow, 1, aRowAttr);
    1588           0 :         WriteRowContent();
    1589           0 :         pRowFormatRanges->Clear();
    1590             :     }
    1591             :     else
    1592             :     {
    1593           0 :         if (nOpenRow > -1)
    1594             :         {
    1595           0 :             pCellStyles->GetFormatRanges(nStartCol, pSharedData->GetLastColumn(nSheet), nStartRow, nSheet, pRowFormatRanges);
    1596           0 :             WriteRowContent();
    1597           0 :             CloseRow(nStartRow);
    1598           0 :             sal_Int32 nRows(1);
    1599           0 :             sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
    1600           0 :             while (nRows < nTotalRows)
    1601             :             {
    1602           0 :                 pRowFormatRanges->Clear();
    1603           0 :                 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
    1604           0 :                 sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
    1605             :                 OSL_ENSURE(nMaxRows, "something wents wrong");
    1606           0 :                 if (nMaxRows >= nTotalRows - nRows)
    1607             :                 {
    1608           0 :                     OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
    1609           0 :                     nRows += nTotalRows - nRows;
    1610             :                 }
    1611             :                 else
    1612             :                 {
    1613           0 :                     OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
    1614           0 :                     nRows += nMaxRows;
    1615             :                 }
    1616           0 :                 if (!pRowFormatRanges->GetSize())
    1617           0 :                     pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
    1618           0 :                 WriteRowContent();
    1619           0 :                 CloseRow(nStartRow + nRows - 1);
    1620             :             }
    1621           0 :             if (nTotalRows == 1)
    1622           0 :                 CloseRow(nStartRow);
    1623           0 :             OpenRow(nSheet, nEndRow, 1, aRowAttr);
    1624           0 :             pRowFormatRanges->Clear();
    1625           0 :             pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
    1626           0 :             WriteRowContent();
    1627             :         }
    1628             :         else
    1629             :         {
    1630           0 :             sal_Int32 nRows(0);
    1631           0 :             sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
    1632           0 :             while (nRows < nTotalRows)
    1633             :             {
    1634           0 :                 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
    1635           0 :                 sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
    1636           0 :                 if (nMaxRows >= nTotalRows - nRows)
    1637             :                 {
    1638           0 :                     OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
    1639           0 :                     nRows += nTotalRows - nRows;
    1640             :                 }
    1641             :                 else
    1642             :                 {
    1643           0 :                     OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
    1644           0 :                     nRows += nMaxRows;
    1645             :                 }
    1646           0 :                 if (!pRowFormatRanges->GetSize())
    1647           0 :                     pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges);
    1648           0 :                 WriteRowContent();
    1649           0 :                 CloseRow(nStartRow + nRows - 1);
    1650             :             }
    1651           0 :             OpenRow(nSheet, nEndRow, 1, aRowAttr);
    1652           0 :             pRowFormatRanges->Clear();
    1653           0 :             pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges);
    1654           0 :             WriteRowContent();
    1655             :         }
    1656             :     }
    1657           0 : }
    1658             : 
    1659           0 : void ScXMLExport::GetColumnRowHeader(bool& rHasColumnHeader, table::CellRangeAddress& rColumnHeaderRange,
    1660             :                                      bool& rHasRowHeader, table::CellRangeAddress& rRowHeaderRange,
    1661             :                                      OUString& rPrintRanges) const
    1662             : {
    1663           0 :     uno::Reference <sheet::XPrintAreas> xPrintAreas (xCurrentTable, uno::UNO_QUERY);
    1664           0 :     if (xPrintAreas.is())
    1665             :     {
    1666           0 :         rHasRowHeader = xPrintAreas->getPrintTitleRows();
    1667           0 :         rHasColumnHeader = xPrintAreas->getPrintTitleColumns();
    1668           0 :         rRowHeaderRange = xPrintAreas->getTitleRows();
    1669           0 :         rColumnHeaderRange = xPrintAreas->getTitleColumns();
    1670           0 :         uno::Sequence< table::CellRangeAddress > aRangeList( xPrintAreas->getPrintAreas() );
    1671           0 :         ScRangeStringConverter::GetStringFromRangeList( rPrintRanges, aRangeList, pDoc, FormulaGrammar::CONV_OOO );
    1672           0 :     }
    1673           0 : }
    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           0 : void ScXMLExport::FillColumnRowGroups()
    1696             : {
    1697           0 :     if (pDoc)
    1698             :     {
    1699           0 :         ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable( static_cast<SCTAB>(nCurrentTable), false );
    1700           0 :         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           0 : }
    1713             : 
    1714           0 : void ScXMLExport::SetBodyAttributes()
    1715             : {
    1716           0 :     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           0 : }
    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           0 : const ScXMLEditAttributeMap& ScXMLExport::GetEditAttributeMap() const
    1867             : {
    1868           0 :     if (!mpEditAttrMap)
    1869           0 :         mpEditAttrMap.reset(new ScXMLEditAttributeMap);
    1870           0 :     return *mpEditAttrMap;
    1871             : }
    1872             : 
    1873           0 : void ScXMLExport::_ExportContent()
    1874             : {
    1875           0 :     nCurrentTable = 0;
    1876           0 :     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           0 :     ScXMLExportDatabaseRanges aExportDatabaseRanges(*this);
    1884           0 :     if (!GetModel().is())
    1885           0 :         return;
    1886             : 
    1887           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
    1888           0 :     if ( !xSpreadDoc.is() )
    1889           0 :         return;
    1890             : 
    1891           0 :     ScSheetSaveData* pSheetData = ScModelObj::getImplementation(xSpreadDoc)->GetSheetSaveData();
    1892           0 :     if (pSheetData)
    1893           0 :         pSheetData->ResetSaveEntries();
    1894             : 
    1895           0 :     uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
    1896           0 :     if ( xIndex.is() )
    1897             :     {
    1898             :         //_GetNamespaceMap().ClearQNamesCache();
    1899           0 :         pChangeTrackingExportHelper->CollectAndWriteChanges();
    1900           0 :         WriteCalculationSettings(xSpreadDoc);
    1901           0 :         sal_Int32 nTableCount(xIndex->getCount());
    1902           0 :         ScMyAreaLinksContainer aAreaLinks;
    1903           0 :         GetAreaLinks( aAreaLinks );
    1904           0 :         ScMyEmptyDatabaseRangesContainer aEmptyRanges(aExportDatabaseRanges.GetEmptyDatabaseRanges());
    1905           0 :         ScMyDetectiveOpContainer aDetectiveOpContainer;
    1906           0 :         GetDetectiveOpList( aDetectiveOpContainer );
    1907             : 
    1908           0 :         pCellStyles->Sort();
    1909           0 :         pMergedRangesContainer->Sort();
    1910           0 :         pSharedData->GetDetectiveObjContainer()->Sort();
    1911             : 
    1912           0 :         mpCellsItr->Clear();
    1913           0 :         mpCellsItr->SetShapes( pSharedData->GetShapesContainer() );
    1914           0 :         mpCellsItr->SetNoteShapes( pSharedData->GetNoteShapes() );
    1915           0 :         mpCellsItr->SetMergedRanges( pMergedRangesContainer );
    1916           0 :         mpCellsItr->SetAreaLinks( &aAreaLinks );
    1917           0 :         mpCellsItr->SetEmptyDatabaseRanges( &aEmptyRanges );
    1918           0 :         mpCellsItr->SetDetectiveObj( pSharedData->GetDetectiveObjContainer() );
    1919           0 :         mpCellsItr->SetDetectiveOp( &aDetectiveOpContainer );
    1920             : 
    1921           0 :         if (nTableCount > 0)
    1922           0 :             pValidationsContainer->WriteValidations(*this);
    1923           0 :         WriteTheLabelRanges( xSpreadDoc );
    1924           0 :         for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable)
    1925             :         {
    1926           0 :             sal_Int32 nStartOffset = -1;
    1927           0 :             sal_Int32 nEndOffset = -1;
    1928           0 :             if (pSheetData && pDoc && pDoc->IsStreamValid((SCTAB)nTable) && !pDoc->GetChangeTrack())
    1929           0 :                 pSheetData->GetStreamPos( nTable, nStartOffset, nEndOffset );
    1930             : 
    1931           0 :             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           0 :                 uno::Reference<sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
    1946           0 :                 WriteTable(nTable, xTable);
    1947             :             }
    1948           0 :             IncrementProgressBar(false);
    1949           0 :         }
    1950             :     }
    1951           0 :     WriteExternalRefCaches();
    1952           0 :     WriteNamedExpressions();
    1953           0 :     WriteDataStream();
    1954           0 :     aExportDatabaseRanges.WriteDatabaseRanges();
    1955           0 :     ScXMLExportDataPilot aExportDataPilot(*this);
    1956           0 :     aExportDataPilot.WriteDataPilots(xSpreadDoc);
    1957           0 :     WriteConsolidation();
    1958           0 :     ScXMLExportDDELinks aExportDDELinks(*this);
    1959           0 :     aExportDDELinks.WriteDDELinks(xSpreadDoc);
    1960           0 :     IncrementProgressBar(true, 0);
    1961           0 :     GetProgressBarHelper()->SetValue(GetProgressBarHelper()->GetReference());
    1962             : }
    1963             : 
    1964           0 : void ScXMLExport::_ExportStyles( bool bUsed )
    1965             : {
    1966           0 :     if (!pSharedData)
    1967             :     {
    1968           0 :         sal_Int32 nTableCount(0);
    1969           0 :         sal_Int32 nShapesCount(0);
    1970           0 :         CollectSharedData(nTableCount, nShapesCount);
    1971             :     }
    1972           0 :     ScXMLStyleExport aStylesExp(*this, OUString(), GetAutoStylePool().get());
    1973           0 :     if (GetModel().is())
    1974             :     {
    1975           0 :         uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
    1976           0 :         if (xMultiServiceFactory.is())
    1977             :         {
    1978           0 :             uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance("com.sun.star.sheet.Defaults"), uno::UNO_QUERY);
    1979           0 :             if (xProperties.is())
    1980           0 :                 aStylesExp.exportDefaultStyle(xProperties, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), xCellStylesExportPropertySetMapper);
    1981           0 :             if (pSharedData->HasShapes())
    1982             :             {
    1983           0 :                 GetShapeExport()->ExportGraphicDefaults();
    1984           0 :             }
    1985             :         }
    1986           0 :         uno::Reference <style::XStyleFamiliesSupplier> xStyleFamiliesSupplier (GetModel(), uno::UNO_QUERY);
    1987           0 :         if (xStyleFamiliesSupplier.is())
    1988             :         {
    1989           0 :             uno::Reference <container::XNameAccess> xStylesFamilies(xStyleFamiliesSupplier->getStyleFamilies());
    1990           0 :             if (xStylesFamilies.is())
    1991             :             {
    1992           0 :                 uno::Reference <container::XIndexAccess> xCellStyles(xStylesFamilies->getByName("CellStyles"), uno::UNO_QUERY);
    1993           0 :                 if (xCellStyles.is())
    1994             :                 {
    1995           0 :                     sal_Int32 nCount(xCellStyles->getCount());
    1996           0 :                     OUString sNumberFormat(SC_UNONAME_NUMFMT);
    1997           0 :                     for (sal_Int32 i = 0; i < nCount; ++i)
    1998             :                     {
    1999           0 :                         uno::Reference <beans::XPropertySet> xCellProperties(xCellStyles->getByIndex(i), uno::UNO_QUERY);
    2000           0 :                         if (xCellProperties.is())
    2001             :                         {
    2002           0 :                             sal_Int32 nNumberFormat = 0;
    2003           0 :                             if (xCellProperties->getPropertyValue(sNumberFormat) >>= nNumberFormat)
    2004           0 :                                 addDataStyle(nNumberFormat);
    2005             :                         }
    2006           0 :                     }
    2007           0 :                 }
    2008           0 :             }
    2009           0 :         }
    2010             :     }
    2011           0 :     exportDataStyles();
    2012             : 
    2013             :     aStylesExp.exportStyleFamily(OUString("CellStyles"),
    2014           0 :         OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), xCellStylesExportPropertySetMapper, false, XML_STYLE_FAMILY_TABLE_CELL);
    2015             : 
    2016           0 :     SvXMLExport::_ExportStyles(bUsed);
    2017           0 : }
    2018             : 
    2019           0 : 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           0 :     uno::Reference<sheet::XSheetCellRanges> xCellRanges( xProperties, uno::UNO_QUERY );
    2025             : 
    2026           0 :     OUString SC_SCELLPREFIX(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX);
    2027           0 :     OUString SC_NUMBERFORMAT(SC_UNONAME_NUMFMT);
    2028             : 
    2029           0 :     OUString sStyleName;
    2030           0 :     sal_Int32 nNumberFormat(-1);
    2031           0 :     sal_Int32 nValidationIndex(-1);
    2032           0 :     std::vector< XMLPropertyState > xPropStates(xCellStylesExportPropertySetMapper->Filter( xProperties ));
    2033           0 :     std::vector< XMLPropertyState >::iterator aItr(xPropStates.begin());
    2034           0 :     std::vector< XMLPropertyState >::iterator aEndItr(xPropStates.end());
    2035           0 :     sal_Int32 nCount(0);
    2036           0 :     while (aItr != aEndItr)
    2037             :     {
    2038           0 :         if (aItr->mnIndex != -1)
    2039             :         {
    2040           0 :             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           0 :                     aItr->maValue >>= sStyleName;
    2056           0 :                     aItr->mnIndex = -1;
    2057           0 :                     ++aItr;
    2058           0 :                     ++nCount;
    2059             :                 }
    2060           0 :                 break;
    2061             :                 case CTF_SC_NUMBERFORMAT :
    2062             :                 {
    2063           0 :                     if (aItr->maValue >>= nNumberFormat)
    2064           0 :                         addDataStyle(nNumberFormat);
    2065           0 :                     ++aItr;
    2066           0 :                     ++nCount;
    2067             :                 }
    2068           0 :                 break;
    2069             :                 default:
    2070             :                 {
    2071           0 :                     ++aItr;
    2072           0 :                     ++nCount;
    2073             :                 }
    2074           0 :                 break;
    2075             :             }
    2076             :         }
    2077             :         else
    2078             :         {
    2079           0 :             ++aItr;
    2080           0 :             ++nCount;
    2081             :         }
    2082             :     }
    2083           0 :     if (nCount == 1) // this is the CellStyle and should be removed if alone
    2084           0 :         xPropStates.clear();
    2085           0 :     if (nNumberFormat == -1)
    2086           0 :         xProperties->getPropertyValue(SC_NUMBERFORMAT) >>= nNumberFormat;
    2087           0 :     if (!sStyleName.isEmpty())
    2088             :     {
    2089           0 :         if (!xPropStates.empty())
    2090             :         {
    2091             :             sal_Int32 nIndex;
    2092           0 :             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           0 :                 OUString sName;
    2106           0 :                 bool bIsAutoStyle(true);
    2107           0 :                 if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_CELL, sStyleName, xPropStates))
    2108             :                 {
    2109           0 :                     OUString* pTemp(new OUString(sName));
    2110           0 :                     if (!pCellStyles->AddStyleName(pTemp, nIndex))
    2111           0 :                         delete pTemp;
    2112             :                 }
    2113             :                 else
    2114           0 :                     nIndex = pCellStyles->GetIndexOfStyleName(sName, SC_SCELLPREFIX, bIsAutoStyle);
    2115             : 
    2116           0 :                 uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
    2117           0 :                 table::CellRangeAddress* pAddresses(aAddresses.getArray());
    2118           0 :                 bool bGetMerge(true);
    2119           0 :                 for (sal_Int32 i = 0; i < aAddresses.getLength(); ++i, ++pAddresses)
    2120             :                 {
    2121           0 :                     pSharedData->SetLastColumn(nTable, pAddresses->EndColumn);
    2122           0 :                     pSharedData->SetLastRow(nTable, pAddresses->EndRow);
    2123           0 :                     pCellStyles->AddRangeStyleName(*pAddresses, nIndex, bIsAutoStyle, nValidationIndex, nNumberFormat);
    2124           0 :                     if (bGetMerge)
    2125           0 :                         bGetMerge = GetMerged(pAddresses, xTable);
    2126           0 :                 }
    2127             :             }
    2128             :         }
    2129             :         else
    2130             :         {
    2131           0 :             OUString* pTemp(new OUString(EncodeStyleName(sStyleName)));
    2132           0 :             sal_Int32 nIndex(0);
    2133           0 :             if (!pCellStyles->AddStyleName(pTemp, nIndex, false))
    2134             :             {
    2135           0 :                 delete pTemp;
    2136           0 :                 pTemp = NULL;
    2137             :             }
    2138           0 :             if ( !pOldName )
    2139             :             {
    2140           0 :                 uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
    2141           0 :                 table::CellRangeAddress* pAddresses(aAddresses.getArray());
    2142           0 :                 bool bGetMerge(true);
    2143           0 :                 for (sal_Int32 i = 0; i < aAddresses.getLength(); ++i, ++pAddresses)
    2144             :                 {
    2145           0 :                     if (bGetMerge)
    2146           0 :                         bGetMerge = GetMerged(pAddresses, xTable);
    2147           0 :                     pCellStyles->AddRangeStyleName(*pAddresses, nIndex, false, nValidationIndex, nNumberFormat);
    2148           0 :                     if( sStyleName != "Default" || nValidationIndex != -1 )
    2149             :                     {
    2150           0 :                         pSharedData->SetLastColumn(nTable, pAddresses->EndColumn);
    2151           0 :                         pSharedData->SetLastRow(nTable, pAddresses->EndRow);
    2152             :                     }
    2153           0 :                 }
    2154             :             }
    2155             :         }
    2156           0 :     }
    2157           0 : }
    2158             : 
    2159           0 : void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>& xColumnProperties,
    2160             :                                      const OUString* pOldName, sal_Int32& rIndex, bool& rIsVisible)
    2161             : {
    2162           0 :     OUString SC_SCOLUMNPREFIX(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX);
    2163             : 
    2164           0 :     std::vector<XMLPropertyState> xPropStates(xColumnStylesExportPropertySetMapper->Filter(xColumnProperties));
    2165           0 :     if(!xPropStates.empty())
    2166             :     {
    2167           0 :         std::vector< XMLPropertyState >::iterator aItr(xPropStates.begin());
    2168           0 :         std::vector< XMLPropertyState >::iterator aEndItr(xPropStates.end());
    2169           0 :         while (aItr != aEndItr)
    2170             :         {
    2171           0 :             if (xColumnStylesPropertySetMapper->GetEntryContextId(aItr->mnIndex) == CTF_SC_ISVISIBLE)
    2172             :             {
    2173           0 :                 aItr->maValue >>= rIsVisible;
    2174           0 :                 break;
    2175             :             }
    2176           0 :             ++aItr;
    2177             :         }
    2178             : 
    2179           0 :         OUString sParent;
    2180           0 :         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           0 :             OUString sName;
    2193           0 :             if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_COLUMN, sParent, xPropStates))
    2194             :             {
    2195           0 :                 OUString* pTemp(new OUString(sName));
    2196           0 :                 rIndex = pColumnStyles->AddStyleName(pTemp);
    2197             :             }
    2198             :             else
    2199           0 :                 rIndex = pColumnStyles->GetIndexOfStyleName(sName, SC_SCOLUMNPREFIX);
    2200           0 :         }
    2201           0 :     }
    2202           0 : }
    2203             : 
    2204           0 : void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRowProperties,
    2205             :                                   const OUString* pOldName, sal_Int32& rIndex)
    2206             : {
    2207           0 :     OUString SC_SROWPREFIX(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX);
    2208             : 
    2209           0 :     std::vector<XMLPropertyState> xPropStates(xRowStylesExportPropertySetMapper->Filter(xRowProperties));
    2210           0 :     if(!xPropStates.empty())
    2211             :     {
    2212           0 :         OUString sParent;
    2213           0 :         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           0 :             OUString sName;
    2226           0 :             if (GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_ROW, sParent, xPropStates))
    2227             :             {
    2228           0 :                 OUString* pTemp(new OUString(sName));
    2229           0 :                 rIndex = pRowStyles->AddStyleName(pTemp);
    2230             :             }
    2231             :             else
    2232           0 :                 rIndex = pRowStyles->GetIndexOfStyleName(sName, SC_SROWPREFIX);
    2233           0 :         }
    2234           0 :     }
    2235           0 : }
    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           0 : void ScXMLExport::_ExportAutoStyles()
    2259             : {
    2260           0 :     if (!GetModel().is())
    2261           0 :         return;
    2262             : 
    2263           0 :     Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
    2264           0 :     if (!xSpreadDoc.is())
    2265           0 :         return;
    2266             : 
    2267           0 :     Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
    2268           0 :     if (!xIndex.is())
    2269           0 :         return;
    2270             : 
    2271           0 :     if (getExportFlags() & EXPORT_CONTENT)
    2272             :     {
    2273             :         //  re-create automatic styles with old names from stored data
    2274           0 :         ScSheetSaveData* pSheetData = ScModelObj::getImplementation(xSpreadDoc)->GetSheetSaveData();
    2275           0 :         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           0 :             SCTAB nTabCount = pDoc->GetTableCount();
    2280           0 :             for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
    2281           0 :                 if (pDoc->IsStreamValid(nTab))
    2282           0 :                     pDoc->InterpretDirtyCells(ScRange(0, 0, nTab, MAXCOL, MAXROW, nTab));
    2283             : 
    2284             :             // stored cell styles
    2285           0 :             const std::vector<ScCellStyleEntry>& rCellEntries = pSheetData->GetCellStyles();
    2286           0 :             std::vector<ScCellStyleEntry>::const_iterator aCellIter = rCellEntries.begin();
    2287           0 :             std::vector<ScCellStyleEntry>::const_iterator aCellEnd = rCellEntries.end();
    2288           0 :             while (aCellIter != aCellEnd)
    2289             :             {
    2290           0 :                 ScAddress aPos = aCellIter->maCellPos;
    2291           0 :                 sal_Int32 nTable = aPos.Tab();
    2292           0 :                 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
    2293           0 :                 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           0 :                 ++aCellIter;
    2302             :             }
    2303             : 
    2304             :             // stored column styles
    2305           0 :             const std::vector<ScCellStyleEntry>& rColumnEntries = pSheetData->GetColumnStyles();
    2306           0 :             std::vector<ScCellStyleEntry>::const_iterator aColumnIter = rColumnEntries.begin();
    2307           0 :             std::vector<ScCellStyleEntry>::const_iterator aColumnEnd = rColumnEntries.end();
    2308           0 :             while (aColumnIter != aColumnEnd)
    2309             :             {
    2310           0 :                 ScAddress aPos = aColumnIter->maCellPos;
    2311           0 :                 sal_Int32 nTable = aPos.Tab();
    2312           0 :                 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
    2313           0 :                 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           0 :                 ++aColumnIter;
    2324             :             }
    2325             : 
    2326             :             // stored row styles
    2327           0 :             const std::vector<ScCellStyleEntry>& rRowEntries = pSheetData->GetRowStyles();
    2328           0 :             std::vector<ScCellStyleEntry>::const_iterator aRowIter = rRowEntries.begin();
    2329           0 :             std::vector<ScCellStyleEntry>::const_iterator aRowEnd = rRowEntries.end();
    2330           0 :             while (aRowIter != aRowEnd)
    2331             :             {
    2332           0 :                 ScAddress aPos = aRowIter->maCellPos;
    2333           0 :                 sal_Int32 nTable = aPos.Tab();
    2334           0 :                 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
    2335           0 :                 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           0 :                 ++aRowIter;
    2345             :             }
    2346             : 
    2347             :             // stored table styles
    2348           0 :             const std::vector<ScCellStyleEntry>& rTableEntries = pSheetData->GetTableStyles();
    2349           0 :             std::vector<ScCellStyleEntry>::const_iterator aTableIter = rTableEntries.begin();
    2350           0 :             std::vector<ScCellStyleEntry>::const_iterator aTableEnd = rTableEntries.end();
    2351           0 :             while (aTableIter != aTableEnd)
    2352             :             {
    2353           0 :                 ScAddress aPos = aTableIter->maCellPos;
    2354           0 :                 sal_Int32 nTable = aPos.Tab();
    2355           0 :                 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
    2356           0 :                 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           0 :                 ++aTableIter;
    2370             :             }
    2371             : 
    2372             :             // stored styles for notes
    2373             : 
    2374           0 :             UniReference<SvXMLExportPropertyMapper> xShapeMapper = XMLShapeExport::CreateShapePropMapper( *this );
    2375           0 :             GetShapeExport(); // make sure the graphics styles family is added
    2376             : 
    2377           0 :             const std::vector<ScNoteStyleEntry>& rNoteEntries = pSheetData->GetNoteStyles();
    2378           0 :             std::vector<ScNoteStyleEntry>::const_iterator aNoteIter = rNoteEntries.begin();
    2379           0 :             std::vector<ScNoteStyleEntry>::const_iterator aNoteEnd = rNoteEntries.end();
    2380           0 :             while (aNoteIter != aNoteEnd)
    2381             :             {
    2382           0 :                 ScAddress aPos = aNoteIter->maCellPos;
    2383           0 :                 SCTAB nTable = aPos.Tab();
    2384           0 :                 bool bCopySheet = pDoc->IsStreamValid( nTable );
    2385           0 :                 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           0 :                 ++aNoteIter;
    2419             :             }
    2420             : 
    2421             :             // note paragraph styles
    2422             : 
    2423           0 :             UniReference<SvXMLExportPropertyMapper> xParaPropMapper = GetTextParagraphExport()->GetParagraphPropertyMapper();
    2424             : 
    2425           0 :             const std::vector<ScTextStyleEntry>& rNoteParaEntries = pSheetData->GetNoteParaStyles();
    2426           0 :             std::vector<ScTextStyleEntry>::const_iterator aNoteParaIter = rNoteParaEntries.begin();
    2427           0 :             std::vector<ScTextStyleEntry>::const_iterator aNoteParaEnd = rNoteParaEntries.end();
    2428           0 :             while (aNoteParaIter != aNoteParaEnd)
    2429             :             {
    2430           0 :                 ScAddress aPos = aNoteParaIter->maCellPos;
    2431           0 :                 SCTAB nTable = aPos.Tab();
    2432           0 :                 bool bCopySheet = pDoc->IsStreamValid( nTable );
    2433           0 :                 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           0 :                 ++aNoteParaIter;
    2454             :             }
    2455             : 
    2456             :             // note text styles
    2457             : 
    2458           0 :             UniReference<SvXMLExportPropertyMapper> xTextPropMapper = XMLTextParagraphExport::CreateCharExtPropMapper( *this );
    2459             : 
    2460           0 :             const std::vector<ScTextStyleEntry>& rNoteTextEntries = pSheetData->GetNoteTextStyles();
    2461           0 :             std::vector<ScTextStyleEntry>::const_iterator aNoteTextIter = rNoteTextEntries.begin();
    2462           0 :             std::vector<ScTextStyleEntry>::const_iterator aNoteTextEnd = rNoteTextEntries.end();
    2463           0 :             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           0 :             const std::vector<ScTextStyleEntry>& rTextEntries = pSheetData->GetTextStyles();
    2496           0 :             std::vector<ScTextStyleEntry>::const_iterator aTextIter = rTextEntries.begin();
    2497           0 :             std::vector<ScTextStyleEntry>::const_iterator aTextEnd = rTextEntries.end();
    2498           0 :             while (aTextIter != aTextEnd)
    2499             :             {
    2500           0 :                 ScAddress aPos = aTextIter->maCellPos;
    2501           0 :                 sal_Int32 nTable = aPos.Tab();
    2502           0 :                 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
    2503           0 :                 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           0 :                 ++aTextIter;
    2524           0 :             }
    2525             :         }
    2526             : 
    2527           0 :         ExportExternalRefCacheStyles();
    2528             : 
    2529           0 :         if (!pSharedData)
    2530             :         {
    2531           0 :             sal_Int32 nTableCount(0);
    2532           0 :             sal_Int32 nShapesCount(0);
    2533           0 :             CollectSharedData(nTableCount, nShapesCount);
    2534             :         }
    2535           0 :         sal_Int32 nTableCount(xIndex->getCount());
    2536           0 :         pCellStyles->AddNewTable(nTableCount - 1);
    2537           0 :         CollectShapesAutoStyles(nTableCount);
    2538           0 :         for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable, IncrementProgressBar(false))
    2539             :         {
    2540           0 :             Reference <sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
    2541           0 :             if (!xTable.is())
    2542           0 :                 continue;
    2543             : 
    2544             :             // table styles array must be complete, including copied tables - Add should find the stored style
    2545           0 :             Reference<beans::XPropertySet> xTableProperties(xTable, uno::UNO_QUERY);
    2546           0 :             if (xTableProperties.is())
    2547             :             {
    2548           0 :                 std::vector<XMLPropertyState> xPropStates(xTableStylesExportPropertySetMapper->Filter(xTableProperties));
    2549           0 :                 if(!xPropStates.empty())
    2550             :                 {
    2551           0 :                     OUString sParent;
    2552           0 :                     OUString sName;
    2553           0 :                     GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_TABLE, sParent, xPropStates);
    2554           0 :                     aTableStyles.push_back(sName);
    2555           0 :                 }
    2556             :             }
    2557             : 
    2558             :             // collect other auto-styles only for non-copied sheets
    2559           0 :             Reference<sheet::XUniqueCellFormatRangesSupplier> xCellFormatRanges ( xTable, uno::UNO_QUERY );
    2560           0 :             if ( xCellFormatRanges.is() )
    2561             :             {
    2562           0 :                 Reference<container::XIndexAccess> xFormatRangesIndex(xCellFormatRanges->getUniqueCellFormatRanges());
    2563           0 :                 if (xFormatRangesIndex.is())
    2564             :                 {
    2565           0 :                     sal_Int32 nFormatRangesCount(xFormatRangesIndex->getCount());
    2566           0 :                     GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nFormatRangesCount);
    2567           0 :                     for (sal_Int32 nFormatRange = 0; nFormatRange < nFormatRangesCount; ++nFormatRange)
    2568             :                     {
    2569           0 :                         Reference< sheet::XSheetCellRanges> xCellRanges(xFormatRangesIndex->getByIndex(nFormatRange), uno::UNO_QUERY);
    2570           0 :                         if (xCellRanges.is())
    2571             :                         {
    2572           0 :                             Reference <beans::XPropertySet> xProperties (xCellRanges, uno::UNO_QUERY);
    2573           0 :                             if (xProperties.is())
    2574             :                             {
    2575           0 :                                 AddStyleFromCells(xProperties, xTable, nTable, NULL);
    2576           0 :                                 IncrementProgressBar(false);
    2577           0 :                             }
    2578             :                         }
    2579           0 :                     }
    2580           0 :                 }
    2581             :             }
    2582           0 :             Reference<table::XColumnRowRange> xColumnRowRange (xTable, uno::UNO_QUERY);
    2583           0 :             if (xColumnRowRange.is())
    2584             :             {
    2585           0 :                 if (pDoc)
    2586             :                 {
    2587           0 :                     pDoc->SyncColRowFlags();
    2588           0 :                     Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns());
    2589           0 :                     if (xTableColumns.is())
    2590             :                     {
    2591           0 :                         sal_Int32 nColumns(pDoc->GetLastChangedCol(sal::static_int_cast<SCTAB>(nTable)));
    2592           0 :                         pSharedData->SetLastColumn(nTable, nColumns);
    2593           0 :                         table::CellRangeAddress aCellAddress(GetEndAddress(xTable, nTable));
    2594           0 :                         if (aCellAddress.EndColumn > nColumns)
    2595             :                         {
    2596           0 :                             ++nColumns;
    2597           0 :                             pColumnStyles->AddNewTable(nTable, aCellAddress.EndColumn);
    2598             :                         }
    2599             :                         else
    2600           0 :                             pColumnStyles->AddNewTable(nTable, nColumns);
    2601           0 :                         sal_Int32 nColumn = 0;
    2602           0 :                         while (nColumn <= MAXCOL)
    2603             :                         {
    2604           0 :                             sal_Int32 nIndex(-1);
    2605           0 :                             bool bIsVisible(true);
    2606           0 :                             Reference <beans::XPropertySet> xColumnProperties(xTableColumns->getByIndex(nColumn), uno::UNO_QUERY);
    2607           0 :                             if (xColumnProperties.is())
    2608             :                             {
    2609           0 :                                 AddStyleFromColumn( xColumnProperties, NULL, nIndex, bIsVisible );
    2610           0 :                                 pColumnStyles->AddFieldStyleName(nTable, nColumn, nIndex, bIsVisible);
    2611             :                             }
    2612           0 :                             sal_Int32 nOld(nColumn);
    2613           0 :                             nColumn = pDoc->GetNextDifferentChangedCol(sal::static_int_cast<SCTAB>(nTable), static_cast<SCCOL>(nColumn));
    2614           0 :                             for (sal_Int32 i = nOld + 1; i < nColumn; ++i)
    2615           0 :                                 pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
    2616           0 :                         }
    2617           0 :                         if (aCellAddress.EndColumn > nColumns)
    2618             :                         {
    2619           0 :                             bool bIsVisible(true);
    2620           0 :                             sal_Int32 nIndex(pColumnStyles->GetStyleNameIndex(nTable, nColumns, bIsVisible));
    2621           0 :                             for (sal_Int32 i = nColumns + 1; i <= aCellAddress.EndColumn; ++i)
    2622           0 :                                 pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
    2623             :                         }
    2624             :                     }
    2625           0 :                     Reference<table::XTableRows> xTableRows(xColumnRowRange->getRows());
    2626           0 :                     if (xTableRows.is())
    2627             :                     {
    2628           0 :                         sal_Int32 nRows(pDoc->GetLastChangedRow(sal::static_int_cast<SCTAB>(nTable)));
    2629           0 :                         pSharedData->SetLastRow(nTable, nRows);
    2630             : 
    2631           0 :                         pRowStyles->AddNewTable(nTable, MAXROW);
    2632           0 :                         sal_Int32 nRow = 0;
    2633           0 :                         while (nRow <= MAXROW)
    2634             :                         {
    2635           0 :                             sal_Int32 nIndex = 0;
    2636           0 :                             Reference <beans::XPropertySet> xRowProperties(xTableRows->getByIndex(nRow), uno::UNO_QUERY);
    2637           0 :                             if(xRowProperties.is())
    2638             :                             {
    2639           0 :                                 AddStyleFromRow( xRowProperties, NULL, nIndex );
    2640           0 :                                 pRowStyles->AddFieldStyleName(nTable, nRow, nIndex);
    2641             :                             }
    2642           0 :                             sal_Int32 nOld(nRow);
    2643           0 :                             nRow = pDoc->GetNextDifferentChangedRow(sal::static_int_cast<SCTAB>(nTable), static_cast<SCROW>(nRow), false);
    2644           0 :                             if (nRow > nOld + 1)
    2645           0 :                                 pRowStyles->AddFieldStyleName(nTable, nOld + 1, nIndex, nRow - 1);
    2646           0 :                         }
    2647           0 :                     }
    2648             :                 }
    2649             :             }
    2650             : 
    2651           0 :             ExportCellTextAutoStyles(nTable);
    2652           0 :         }
    2653             : 
    2654           0 :         pChangeTrackingExportHelper->CollectAutoStyles();
    2655             : 
    2656             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_COLUMN,
    2657           0 :             GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
    2658             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_ROW,
    2659           0 :             GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
    2660             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_TABLE,
    2661           0 :             GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
    2662           0 :         exportAutoDataStyles();
    2663             :         GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_CELL,
    2664           0 :             GetDocHandler(), GetMM100UnitConverter(), GetNamespaceMap());
    2665             : 
    2666           0 :         GetShapeExport()->exportAutoStyles();
    2667           0 :         GetFormExport()->exportAutoStyles( );
    2668             : 
    2669           0 :         if (pDoc)
    2670             :         {
    2671           0 :             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           0 :             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           0 :     if (getExportFlags() & EXPORT_MASTERSTYLES)
    2687             :     {
    2688           0 :         GetPageExport()->collectAutoStyles(true);
    2689           0 :         GetPageExport()->exportAutoStyles();
    2690             :     }
    2691             : 
    2692             :     // #i30251#; only write Text Styles once
    2693             : 
    2694           0 :     if ((getExportFlags() & EXPORT_CONTENT) || (getExportFlags() & EXPORT_MASTERSTYLES))
    2695           0 :         GetTextParagraphExport()->exportTextAutoStyles();
    2696             : }
    2697             : 
    2698           0 : void ScXMLExport::_ExportMasterStyles()
    2699             : {
    2700           0 :     GetPageExport()->exportMasterStyles( true );
    2701           0 : }
    2702             : 
    2703           0 : void ScXMLExport::CollectInternalShape( uno::Reference< drawing::XShape > xShape )
    2704             : {
    2705             :     // detective objects and notes
    2706           0 :     if( SvxShape* pShapeImp = SvxShape::getImplementation( xShape ) )
    2707             :     {
    2708           0 :         if( SdrObject* pObject = pShapeImp->GetSdrObject() )
    2709             :         {
    2710             :             // collect note caption objects from all layers (internal or hidden)
    2711           0 :             if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, static_cast< SCTAB >( nCurrentTable ) ) )
    2712             :             {
    2713           0 :                 if(pDoc->GetNote(pCaptData->maStart))
    2714             :                 {
    2715           0 :                     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           0 :                     pSharedData->SetLastColumn( nCurrentTable, pCaptData->maStart.Col() );
    2721           0 :                     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           0 : }
    2738             : 
    2739           0 : bool ScXMLExport::GetMerged (const table::CellRangeAddress* pCellAddress,
    2740             :                             const uno::Reference <sheet::XSpreadsheet>& xTable)
    2741             : {
    2742           0 :     bool bReady(false);
    2743           0 :     sal_Int32 nRow(pCellAddress->StartRow);
    2744           0 :     sal_Int32 nCol(pCellAddress->StartColumn);
    2745           0 :     sal_Int32 nEndRow(pCellAddress->EndRow);
    2746           0 :     sal_Int32 nEndCol(pCellAddress->EndColumn);
    2747           0 :     bool bRowInc(nEndRow > nRow);
    2748           0 :     while(!bReady && nRow <= nEndRow && nCol <= nEndCol)
    2749             :     {
    2750           0 :         uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xTable->getCellRangeByPosition(nCol, nRow, nCol, nRow), uno::UNO_QUERY);
    2751           0 :         if (xSheetCellRange.is())
    2752             :         {
    2753           0 :             uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursorByRange(xSheetCellRange));
    2754           0 :             if(xCursor.is())
    2755             :             {
    2756           0 :                 uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
    2757           0 :                 xCursor->collapseToMergedArea();
    2758           0 :                 table::CellRangeAddress aCellAddress2(xCellAddress->getRangeAddress());
    2759           0 :                 if ((aCellAddress2.EndRow > nRow ||
    2760           0 :                     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           0 :                     bReady = true;
    2770           0 :             }
    2771             :         }
    2772           0 :         if (!bReady)
    2773             :         {
    2774           0 :             if (bRowInc)
    2775           0 :                 ++nRow;
    2776             :             else
    2777           0 :                 ++nCol;
    2778             :         }
    2779           0 :     }
    2780             :     OSL_ENSURE(!(!bReady && nEndRow > nRow && nEndCol > nCol), "should not be possible");
    2781           0 :     return !bReady;
    2782             : }
    2783             : 
    2784           0 : bool ScXMLExport::IsMatrix (const ScAddress& aCell,
    2785             :                             table::CellRangeAddress& aCellAddress, bool& bIsFirst) const
    2786             : {
    2787           0 :     bIsFirst = false;
    2788             : 
    2789           0 :     ScRange aMatrixRange;
    2790             : 
    2791           0 :     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           0 :     return false;
    2811             : }
    2812             : 
    2813           0 : void ScXMLExport::WriteTable(sal_Int32 nTable, const Reference<sheet::XSpreadsheet>& xTable)
    2814             : {
    2815           0 :     if (!xTable.is())
    2816           0 :         return;
    2817             : 
    2818           0 :     xCurrentTable.set(xTable);
    2819           0 :     xCurrentTableCellRange.set(xTable, uno::UNO_QUERY);
    2820           0 :     uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
    2821           0 :     if (!xName.is())
    2822           0 :         return;
    2823             : 
    2824           0 :     nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
    2825           0 :     OUString sOUTableName(xName->getName());
    2826           0 :     AddAttribute(sAttrName, sOUTableName);
    2827           0 :     AddAttribute(sAttrStyleName, aTableStyles[nTable]);
    2828             : 
    2829           0 :     uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
    2830           0 :     ScTableProtection* pProtect = NULL;
    2831           0 :     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           0 :     OUString sPrintRanges;
    2875           0 :     table::CellRangeAddress aColumnHeaderRange;
    2876             :     bool bHasColumnHeader;
    2877           0 :     GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
    2878           0 :     if( !sPrintRanges.isEmpty() )
    2879           0 :         AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT_RANGES, sPrintRanges );
    2880           0 :     else if (!pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
    2881           0 :         AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT, XML_FALSE);
    2882           0 :     SvXMLElementExport aElemT(*this, sElemTab, true, true);
    2883             : 
    2884           0 :     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           0 :     CheckAttrList();
    2898             : 
    2899           0 :     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           0 :     WriteTableSource();
    2909           0 :     WriteScenario();
    2910           0 :     uno::Reference<drawing::XDrawPage> xDrawPage;
    2911           0 :     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           0 :     if (pSharedData->HasDrawPage())
    2920             :     {
    2921           0 :         GetShapeExport()->seekShapes(uno::Reference<drawing::XShapes>(pSharedData->GetDrawPage(nTable), uno::UNO_QUERY));
    2922           0 :         WriteTableShapes();
    2923             :     }
    2924           0 :     table::CellRangeAddress aRange(GetEndAddress(xTable, nTable));
    2925           0 :     pSharedData->SetLastColumn(nTable, aRange.EndColumn);
    2926           0 :     pSharedData->SetLastRow(nTable, aRange.EndRow);
    2927           0 :     mpCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
    2928           0 :     pGroupColumns->NewTable();
    2929           0 :     pGroupRows->NewTable();
    2930           0 :     FillColumnRowGroups();
    2931           0 :     if (bHasColumnHeader)
    2932           0 :         pSharedData->SetLastColumn(nTable, aColumnHeaderRange.EndColumn);
    2933           0 :     bRowHeaderOpen = false;
    2934           0 :     if (bHasRowHeader)
    2935           0 :         pSharedData->SetLastRow(nTable, aRowHeaderRange.EndRow);
    2936             :     pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
    2937           0 :         pSharedData->GetLastColumn(nTable), pCellStyles, pDoc);
    2938           0 :     pRowFormatRanges->SetColDefaults(pDefaults->GetColDefaults());
    2939           0 :     pCellStyles->SetColDefaults(pDefaults->GetColDefaults());
    2940           0 :     ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
    2941           0 :     bool bIsFirst(true);
    2942           0 :     sal_Int32 nEqualCells(0);
    2943           0 :     ScMyCell aCell;
    2944           0 :     ScMyCell aPrevCell;
    2945           0 :     while (mpCellsItr->GetNext(aCell, pCellStyles))
    2946             :     {
    2947           0 :         if (bIsFirst)
    2948             :         {
    2949           0 :             ExportFormatRanges(0, 0, aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
    2950           0 :             aPrevCell = aCell;
    2951           0 :             bIsFirst = false;
    2952             :         }
    2953             :         else
    2954             :         {
    2955           0 :             if ((aPrevCell.aCellAddress.Row == aCell.aCellAddress.Row) &&
    2956           0 :                 (aPrevCell.aCellAddress.Column + nEqualCells + 1 == aCell.aCellAddress.Column))
    2957             :             {
    2958           0 :                 if(IsCellEqual(aPrevCell, aCell))
    2959           0 :                     ++nEqualCells;
    2960             :                 else
    2961             :                 {
    2962           0 :                     WriteCell(aPrevCell, nEqualCells);
    2963           0 :                     nEqualCells = 0;
    2964           0 :                     aPrevCell = aCell;
    2965             :                 }
    2966             :             }
    2967             :             else
    2968             :             {
    2969           0 :                 WriteCell(aPrevCell, nEqualCells);
    2970           0 :                 ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
    2971           0 :                     aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
    2972           0 :                 nEqualCells = 0;
    2973           0 :                 aPrevCell = aCell;
    2974             :             }
    2975             :         }
    2976             :     }
    2977           0 :     if (!bIsFirst)
    2978             :     {
    2979           0 :         WriteCell(aPrevCell, nEqualCells);
    2980           0 :         ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
    2981           0 :             pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
    2982             :     }
    2983             :     else
    2984           0 :         ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
    2985             : 
    2986           0 :     CloseRow(pSharedData->GetLastRow(nTable));
    2987           0 :     nEqualCells = 0;
    2988             : 
    2989           0 :     if (pDoc)
    2990             :     {
    2991             :         // Export sheet-local named ranges.
    2992           0 :         ScRangeName* pRangeName = pDoc->GetRangeName(nTable);
    2993           0 :         if (pRangeName && !pRangeName->empty())
    2994             :         {
    2995           0 :             WriteNamedRange(pRangeName);
    2996             :         }
    2997             : 
    2998           0 :         if(getDefaultVersion() > SvtSaveOptions::ODFVER_012)
    2999             :         {
    3000             :             //export new conditional format information
    3001           0 :             ExportConditionalFormat(nTable);
    3002             :         }
    3003             : 
    3004           0 :     }
    3005             : }
    3006             : 
    3007             : namespace {
    3008             : 
    3009           0 : void writeContent(
    3010             :     ScXMLExport& rExport, const OUString& rStyleName, const OUString& rContent, const SvxFieldData* pField )
    3011             : {
    3012           0 :     boost::scoped_ptr<SvXMLElementExport> pElem;
    3013           0 :     if (!rStyleName.isEmpty())
    3014             :     {
    3015             :         // Formatted section with automatic style.
    3016           0 :         rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, rStyleName);
    3017           0 :         OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
    3018           0 :             XML_NAMESPACE_TEXT, GetXMLToken(XML_SPAN));
    3019           0 :         pElem.reset(new SvXMLElementExport(rExport, aElemName, false, false));
    3020             :     }
    3021             : 
    3022           0 :     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           0 :         rExport.Characters(rContent);
    3095           0 : }
    3096             : 
    3097           0 : 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           0 :     OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
    3104           0 :         XML_NAMESPACE_TEXT, GetXMLToken(XML_P));
    3105           0 :     SvXMLElementExport aElemP(rExport, aElemName, false, false);
    3106             : 
    3107           0 :     for (; it != itEnd; ++it)
    3108             :     {
    3109           0 :         const editeng::Section& rSec = *it;
    3110             : 
    3111           0 :         const sal_Unicode* pBeg = rParaText.getStr();
    3112           0 :         std::advance(pBeg, rSec.mnStart);
    3113           0 :         const sal_Unicode* pEnd = pBeg;
    3114           0 :         std::advance(pEnd, rSec.mnEnd-rSec.mnStart);
    3115             : 
    3116           0 :         OUString aContent(pBeg, pEnd-pBeg);
    3117             : 
    3118           0 :         std::vector<XMLPropertyState> aPropStates;
    3119           0 :         const SvxFieldData* pField = toXMLPropertyStates(aPropStates, rSec.maAttributes, xMapper, rAttrMap);
    3120           0 :         OUString aStyleName = xStylePool->Find(XML_STYLE_FAMILY_TEXT_TEXT, OUString(), aPropStates);
    3121           0 :         writeContent(rExport, aStyleName, aContent, pField);
    3122           0 :     }
    3123           0 : }
    3124             : 
    3125             : }
    3126             : 
    3127           0 : void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
    3128             : {
    3129             :     // nEqualCellCount is the number of additional cells
    3130           0 :     SetRepeatAttribute(nEqualCellCount, (aCell.nType != table::CellContentType_EMPTY));
    3131             : 
    3132           0 :     ScAddress aCellPos;
    3133           0 :     ScUnoConversion::FillScAddress( aCellPos, aCell.aCellAddress );
    3134           0 :     if (aCell.nStyleIndex != -1)
    3135           0 :         AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(aCell.nStyleIndex, aCell.bIsAutoStyle));
    3136           0 :     if (aCell.nValidationIndex > -1)
    3137           0 :         AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(aCell.nValidationIndex));
    3138           0 :     bool bIsMatrix(aCell.bIsMatrixBase || aCell.bIsMatrixCovered);
    3139           0 :     bool bIsFirstMatrixCell(aCell.bIsMatrixBase);
    3140           0 :     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           0 :     bool bIsEmpty(false);
    3152           0 :     switch (aCell.nType)
    3153             :     {
    3154             :         case table::CellContentType_EMPTY :
    3155             :             {
    3156           0 :                 bIsEmpty = true;
    3157             :             }
    3158           0 :             break;
    3159             :         case table::CellContentType_VALUE :
    3160             :             {
    3161             :                 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
    3162           0 :                     aCell.nNumberFormat, aCell.maBaseCell.mfValue);
    3163           0 :                 if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
    3164             :                     GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
    3165           0 :                             aCell.nNumberFormat, aCell.maBaseCell.mfValue, false, XML_NAMESPACE_CALC_EXT, false);
    3166             :             }
    3167           0 :             break;
    3168             :         case table::CellContentType_TEXT :
    3169             :             {
    3170           0 :                 OUString sFormattedString(lcl_GetFormattedString(pDoc, aCellPos));
    3171           0 :                 OUString sCellString = aCell.maBaseCell.getString(pDoc);
    3172             :                 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
    3173           0 :                         sCellString, sFormattedString, true, true);
    3174           0 :                 if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
    3175             :                     GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
    3176           0 :                             sCellString, sFormattedString, false, true, XML_NAMESPACE_CALC_EXT);
    3177             :             }
    3178           0 :             break;
    3179             :         case table::CellContentType_FORMULA :
    3180             :             {
    3181           0 :                 if (aCell.maBaseCell.meType == CELLTYPE_FORMULA)
    3182             :                 {
    3183           0 :                     ScFormulaCell* pFormulaCell = aCell.maBaseCell.mpFormula;
    3184           0 :                     if (!bIsMatrix || (bIsMatrix && bIsFirstMatrixCell))
    3185             :                     {
    3186           0 :                         if (!mpCompileFormulaCxt)
    3187             :                         {
    3188           0 :                             const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
    3189           0 :                             mpCompileFormulaCxt.reset(new sc::CompileFormulaContext(pDoc, eGrammar));
    3190             :                         }
    3191             : 
    3192           0 :                         OUString aFormula = pFormulaCell->GetFormula(*mpCompileFormulaCxt);
    3193             :                         sal_uInt16 nNamespacePrefix =
    3194           0 :                             (mpCompileFormulaCxt->getGrammar() == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
    3195             : 
    3196           0 :                         if (!bIsMatrix)
    3197             :                         {
    3198           0 :                             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           0 :                         }
    3204             :                     }
    3205           0 :                     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           0 :                     else if (pFormulaCell->IsValue())
    3216             :                     {
    3217             :                         bool bIsStandard;
    3218           0 :                         OUString sCurrency;
    3219           0 :                         GetNumberFormatAttributesExportHelper()->GetCellType(aCell.nNumberFormat, sCurrency, bIsStandard);
    3220           0 :                         if (pDoc)
    3221             :                         {
    3222             :                             GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
    3223           0 :                                     aCell.nNumberFormat, pDoc->GetValue( aCellPos ));
    3224           0 :                             if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
    3225             :                             {
    3226             :                                 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
    3227           0 :                                         aCell.nNumberFormat, pDoc->GetValue( aCellPos ), false, XML_NAMESPACE_CALC_EXT, false );
    3228             :                             }
    3229           0 :                         }
    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           0 :             break;
    3246             :         default:
    3247           0 :             break;
    3248             :     }
    3249           0 :     OUString* pCellString(&sElemCell);
    3250           0 :     if (aCell.bIsCovered)
    3251             :     {
    3252           0 :         pCellString = &sElemCoveredCell;
    3253             :     }
    3254             :     else
    3255             :     {
    3256           0 :         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           0 :     SvXMLElementExport aElemC(*this, *pCellString, true, true);
    3269           0 :     CheckAttrList();
    3270           0 :     WriteAreaLink(aCell);
    3271           0 :     WriteAnnotation(aCell);
    3272           0 :     WriteDetective(aCell);
    3273             : 
    3274           0 :     if (!bIsEmpty)
    3275             :     {
    3276           0 :         if (aCell.maBaseCell.meType == CELLTYPE_EDIT)
    3277             :         {
    3278           0 :             WriteEditCell(aCell.maBaseCell.mpEditText);
    3279             :         }
    3280           0 :         else if (aCell.maBaseCell.meType == CELLTYPE_FORMULA && aCell.maBaseCell.mpFormula->IsMultilineResult())
    3281             :         {
    3282           0 :             WriteMultiLineFormulaResult(aCell.maBaseCell.mpFormula);
    3283             :         }
    3284             :         else
    3285             :         {
    3286           0 :             SvXMLElementExport aElemP(*this, sElemP, true, false);
    3287           0 :             bool bPrevCharWasSpace(true);
    3288           0 :             GetTextParagraphExport()->exportText(aCell.maBaseCell.getString(pDoc), bPrevCharWasSpace);
    3289             :         }
    3290             :     }
    3291           0 :     WriteShapes(aCell);
    3292           0 :     if (!bIsEmpty)
    3293           0 :         IncrementProgressBar(false);
    3294           0 : }
    3295             : 
    3296           0 : void ScXMLExport::WriteEditCell(const EditTextObject* pText)
    3297             : {
    3298           0 :     UniReference<XMLPropertySetMapper> xMapper = GetTextParagraphExport()->GetTextPropMapper()->getPropertySetMapper();
    3299           0 :     UniReference<SvXMLAutoStylePoolP> xStylePool = GetAutoStylePool();
    3300           0 :     const ScXMLEditAttributeMap& rAttrMap = GetEditAttributeMap();
    3301             : 
    3302             :     // Get raw paragraph texts first.
    3303           0 :     std::vector<OUString> aParaTexts;
    3304           0 :     sal_Int32 nParaCount = pText->GetParagraphCount();
    3305           0 :     aParaTexts.reserve(nParaCount);
    3306           0 :     for (sal_Int32 i = 0; i < nParaCount; ++i)
    3307           0 :         aParaTexts.push_back(pText->GetText(i));
    3308             : 
    3309             :     // Get all section data and iterate through them.
    3310           0 :     std::vector<editeng::Section> aAttrs;
    3311           0 :     pText->GetAllSections(aAttrs);
    3312           0 :     std::vector<editeng::Section>::const_iterator itSec = aAttrs.begin(), itSecEnd = aAttrs.end();
    3313           0 :     std::vector<editeng::Section>::const_iterator itPara = itSec;
    3314           0 :     sal_Int32 nCurPara = 0; // current paragraph
    3315           0 :     for (; itSec != itSecEnd; ++itSec)
    3316             :     {
    3317           0 :         const editeng::Section& rSec = *itSec;
    3318           0 :         if (nCurPara == rSec.mnParagraph)
    3319             :             // Still in the same paragraph.
    3320           0 :             continue;
    3321             : 
    3322             :         // Start of a new paragraph. Flush the old paragraph.
    3323           0 :         flushParagraph(*this, aParaTexts[nCurPara], xMapper, xStylePool, rAttrMap, itPara, itSec);
    3324           0 :         nCurPara = rSec.mnParagraph;
    3325           0 :         itPara = itSec;
    3326             :     }
    3327             : 
    3328           0 :     flushParagraph(*this, aParaTexts[nCurPara], xMapper, xStylePool, rAttrMap, itPara, itSecEnd);
    3329           0 : }
    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           0 : void ScXMLExport::ExportShape(const uno::Reference < drawing::XShape >& xShape, awt::Point* pPoint)
    3368             : {
    3369           0 :     uno::Reference < beans::XPropertySet > xShapeProps ( xShape, uno::UNO_QUERY );
    3370           0 :     bool bIsChart( false );
    3371           0 :     OUString sPropCLSID ("CLSID");
    3372           0 :     OUString sPropModel ("Model");
    3373           0 :     OUString sPersistName ("PersistName");
    3374           0 :     if (xShapeProps.is())
    3375             :     {
    3376           0 :         sal_Int32 nZOrder = 0;
    3377           0 :         if (xShapeProps->getPropertyValue("ZOrder") >>= nZOrder)
    3378             :         {
    3379           0 :             OUStringBuffer sBuffer;
    3380           0 :             ::sax::Converter::convertNumber(sBuffer, nZOrder);
    3381           0 :             AddAttribute(XML_NAMESPACE_DRAW, XML_ZINDEX, sBuffer.makeStringAndClear());
    3382             :         }
    3383           0 :         uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xShapeProps->getPropertySetInfo();
    3384           0 :         if( xPropSetInfo->hasPropertyByName( sPropCLSID ) )
    3385             :         {
    3386           0 :             OUString sCLSID;
    3387           0 :             if (xShapeProps->getPropertyValue( sPropCLSID ) >>= sCLSID)
    3388             :             {
    3389           0 :                 if ( sCLSID.equalsIgnoreAsciiCase(GetChartExport()->getChartCLSID()) )
    3390             :                 {
    3391             :                     // we have a chart
    3392           0 :                     OUString sRanges;
    3393           0 :                     if ( pDoc )
    3394             :                     {
    3395           0 :                         OUString aChartName;
    3396           0 :                         xShapeProps->getPropertyValue( sPersistName ) >>= aChartName;
    3397           0 :                         ScChartListenerCollection* pCollection = pDoc->GetChartListenerCollection();
    3398           0 :                         if (pCollection)
    3399             :                         {
    3400           0 :                             ScChartListener* pListener = pCollection->findByName(aChartName);
    3401           0 :                             if (pListener)
    3402             :                             {
    3403           0 :                                 const ScRangeListRef& rRangeList = pListener->GetRangeList();
    3404           0 :                                 if ( rRangeList.Is() )
    3405             :                                 {
    3406           0 :                                     ScRangeStringConverter::GetStringFromRangeList( sRanges, rRangeList, pDoc, FormulaGrammar::CONV_OOO );
    3407           0 :                                     if ( !sRanges.isEmpty() )
    3408             :                                     {
    3409           0 :                                         bIsChart = true;
    3410           0 :                                         SvXMLAttributeList* pAttrList = new SvXMLAttributeList();
    3411           0 :                                         if ( pAttrList )
    3412             :                                         {
    3413             :                                             pAttrList->AddAttribute(
    3414           0 :                                                 GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken( XML_NOTIFY_ON_UPDATE_OF_RANGES ) ), sRanges );
    3415             :                                         }
    3416           0 :                                         GetShapeExport()->exportShape( xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList );
    3417             :                                     }
    3418           0 :                                 }
    3419             :                             }
    3420           0 :                         }
    3421             :                     }
    3422             : 
    3423           0 :                     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           0 :                     }
    3454             :                 }
    3455           0 :             }
    3456           0 :         }
    3457             :     }
    3458           0 :     if (!bIsChart)
    3459             :     {
    3460             :         // #i66550 HLINK_FOR_SHAPES
    3461           0 :         OUString sHlink;
    3462             :         try
    3463             :         {
    3464           0 :             uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
    3465           0 :             if ( xProps.is() )
    3466           0 :                 xProps->getPropertyValue( OUString( SC_UNONAME_HYPERLINK ) ) >>= sHlink;
    3467             :         }
    3468           0 :         catch ( const beans::UnknownPropertyException& )
    3469             :         {
    3470             :             // no hyperlink property
    3471             :         }
    3472             : 
    3473           0 :         boost::scoped_ptr< SvXMLElementExport > pDrawA;
    3474             :         // enlose shapes with <draw:a> element only if sHlink contains something
    3475           0 :         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           0 :         GetShapeExport()->exportShape(xShape, SEF_DEFAULT, pPoint);
    3493             :     }
    3494           0 :     IncrementProgressBar(false);
    3495           0 : }
    3496             : 
    3497           0 : void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
    3498             : {
    3499           0 :     if( rMyCell.bHasShape && !rMyCell.aShapeList.empty() && pDoc )
    3500             :     {
    3501           0 :         awt::Point aPoint;
    3502             :         Rectangle aRect = pDoc->GetMMRect(static_cast<SCCOL>(rMyCell.aCellAddress.Column), static_cast<SCROW>(rMyCell.aCellAddress.Row),
    3503           0 :             static_cast<SCCOL>(rMyCell.aCellAddress.Column), static_cast<SCROW>(rMyCell.aCellAddress.Row), static_cast<SCTAB>(rMyCell.aCellAddress.Sheet));
    3504           0 :         bool bNegativePage(pDoc->IsNegativePage(rMyCell.aCellAddress.Sheet));
    3505           0 :         if (bNegativePage)
    3506           0 :             aPoint.X = aRect.Right();
    3507             :         else
    3508           0 :             aPoint.X = aRect.Left();
    3509           0 :         aPoint.Y = aRect.Top();
    3510           0 :         ScMyShapeList::const_iterator aItr = rMyCell.aShapeList.begin();
    3511           0 :         ScMyShapeList::const_iterator aEndItr(rMyCell.aShapeList.end());
    3512           0 :         while (aItr != aEndItr)
    3513             :         {
    3514           0 :             if (aItr->xShape.is())
    3515             :             {
    3516           0 :                 if (bNegativePage)
    3517           0 :                     aPoint.X = 2 * aItr->xShape->getPosition().X + aItr->xShape->getSize().Width - aPoint.X;
    3518           0 :                 if ( !aItr->xShape->getShapeType().equals(sCaptionShape) )
    3519             :                 {
    3520           0 :                     OUString sEndAddress;
    3521           0 :                     ScRangeStringConverter::GetStringFromAddress(sEndAddress, aItr->aEndAddress, pDoc, FormulaGrammar::CONV_OOO);
    3522           0 :                     AddAttribute(XML_NAMESPACE_TABLE, XML_END_CELL_ADDRESS, sEndAddress);
    3523           0 :                     OUStringBuffer sBuffer;
    3524           0 :                     GetMM100UnitConverter().convertMeasureToXML(
    3525           0 :                             sBuffer, aItr->nEndX);
    3526           0 :                     AddAttribute(XML_NAMESPACE_TABLE, XML_END_X, sBuffer.makeStringAndClear());
    3527           0 :                     GetMM100UnitConverter().convertMeasureToXML(
    3528           0 :                             sBuffer, aItr->nEndY);
    3529           0 :                     AddAttribute(XML_NAMESPACE_TABLE, XML_END_Y, sBuffer.makeStringAndClear());
    3530             :                 }
    3531           0 :                 ExportShape(aItr->xShape, &aPoint);
    3532             :             }
    3533           0 :             ++aItr;
    3534             :         }
    3535             :     }
    3536           0 : }
    3537             : 
    3538           0 : void ScXMLExport::WriteTableShapes()
    3539             : {
    3540           0 :     ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
    3541           0 :     if (pTableShapes && !(*pTableShapes)[nCurrentTable].empty())
    3542             :     {
    3543             :         OSL_ENSURE(pTableShapes->size() > static_cast<size_t>(nCurrentTable), "wrong Table");
    3544           0 :         SvXMLElementExport aShapesElem(*this, XML_NAMESPACE_TABLE, XML_SHAPES, true, false);
    3545           0 :         ScMyTableXShapes::iterator aItr((*pTableShapes)[nCurrentTable].begin());
    3546           0 :         ScMyTableXShapes::iterator aEndItr((*pTableShapes)[nCurrentTable].end());
    3547           0 :         while (aItr != aEndItr)
    3548             :         {
    3549           0 :             if (aItr->is())
    3550             :             {
    3551           0 :                 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           0 :                     ExportShape(*aItr, NULL);
    3561             :             }
    3562           0 :             aItr = (*pTableShapes)[nCurrentTable].erase(aItr);
    3563           0 :         }
    3564             :     }
    3565           0 : }
    3566             : 
    3567           0 : void ScXMLExport::WriteAreaLink( const ScMyCell& rMyCell )
    3568             : {
    3569           0 :     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           0 : }
    3592             : 
    3593           0 : void ScXMLExport::exportAnnotationMeta( const uno::Reference < drawing::XShape >& xShape)
    3594             : {
    3595           0 :     ScAddress aCellPos;
    3596           0 :     ScUnoConversion::FillScAddress( aCellPos, pCurrentCell->aCellAddress );
    3597             : 
    3598           0 :     ScPostIt* pNote = pCurrentCell->pNote;
    3599             : 
    3600           0 :     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           0 :         SdrCaptionObj* pNoteCaption = pNote->GetOrCreateCaption(aCellPos);
    3606           0 :         Reference<drawing::XShape> xCurrentShape( pNoteCaption->getUnoShape(), uno::UNO_QUERY );
    3607           0 :         if (xCurrentShape.get()!=xShape.get())
    3608           0 :             return;
    3609             : 
    3610           0 :         OUString sAuthor(pNote->GetAuthor());
    3611           0 :         if (!sAuthor.isEmpty())
    3612             :         {
    3613             :             SvXMLElementExport aCreatorElem( *this, XML_NAMESPACE_DC,
    3614             :                                                 XML_CREATOR, true,
    3615           0 :                                                 false );
    3616           0 :             Characters(sAuthor);
    3617             :         }
    3618             : 
    3619           0 :         OUString aDate(pNote->GetDate());
    3620           0 :         if (pDoc)
    3621             :         {
    3622           0 :             SvNumberFormatter* pNumForm = pDoc->GetFormatTable();
    3623             :             double fDate;
    3624           0 :             sal_uInt32 nfIndex = pNumForm->GetFormatIndex(NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
    3625           0 :             if (pNumForm->IsNumberFormat(aDate, nfIndex, fDate))
    3626             :             {
    3627           0 :                 OUStringBuffer sBuf;
    3628           0 :                 GetMM100UnitConverter().convertDateTime(sBuf, fDate,true);
    3629             :                 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_DC,
    3630             :                                                 XML_DATE, true,
    3631           0 :                                                 false );
    3632           0 :                 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           0 :         }
    3649             :     }
    3650             : }
    3651             : 
    3652           0 : void ScXMLExport::WriteAnnotation(ScMyCell& rMyCell)
    3653             : {
    3654             : 
    3655           0 :     ScAddress aCellPos;
    3656           0 :     ScUnoConversion::FillScAddress( aCellPos, rMyCell.aCellAddress );
    3657             : 
    3658           0 :     ScPostIt* pNote = pDoc->GetNote(aCellPos);
    3659           0 :     if (pNote)
    3660             :     {
    3661           0 :         if (pNote->IsCaptionShown())
    3662           0 :             AddAttribute(XML_NAMESPACE_OFFICE, XML_DISPLAY, XML_TRUE);
    3663             : 
    3664           0 :         pCurrentCell = &rMyCell;
    3665             : 
    3666           0 :         SdrCaptionObj* pNoteCaption = pNote->GetOrCreateCaption(aCellPos);
    3667           0 :         Reference<drawing::XShape> xShape( pNoteCaption->getUnoShape(), uno::UNO_QUERY );
    3668             : 
    3669           0 :         GetShapeExport()->exportShape(xShape, SEF_DEFAULT|SEF_EXPORT_ANNOTATION, NULL);
    3670             : 
    3671           0 :         pCurrentCell = NULL;
    3672             : 
    3673             :     }
    3674           0 : }
    3675             : 
    3676           0 : void ScXMLExport::WriteDetective( const ScMyCell& rMyCell )
    3677             : {
    3678           0 :     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           0 : }
    3725             : 
    3726           0 : void ScXMLExport::SetRepeatAttribute(sal_Int32 nEqualCellCount, bool bIncProgress)
    3727             : {
    3728             :     // nEqualCellCount is additional cells, so the attribute value is nEqualCellCount+1
    3729           0 :     if (nEqualCellCount > 0)
    3730             :     {
    3731           0 :         sal_Int32 nTemp(nEqualCellCount + 1);
    3732           0 :         OUString sOUEqualCellCount(OUString::number(nTemp));
    3733           0 :         AddAttribute(sAttrColumnsRepeated, sOUEqualCellCount);
    3734           0 :         if (bIncProgress)
    3735           0 :             IncrementProgressBar(false, nEqualCellCount);
    3736             :     }
    3737           0 : }
    3738             : 
    3739           0 : bool ScXMLExport::IsCellTypeEqual (const ScMyCell& aCell1, const ScMyCell& aCell2) const
    3740             : {
    3741           0 :     return (aCell1.nType == aCell2.nType);
    3742             : }
    3743             : 
    3744           0 : bool ScXMLExport::IsEditCell(ScMyCell& rCell) const
    3745             : {
    3746           0 :     return rCell.maBaseCell.meType == CELLTYPE_EDIT;
    3747             : }
    3748             : 
    3749           0 : bool ScXMLExport::IsCellEqual (ScMyCell& aCell1, ScMyCell& aCell2)
    3750             : {
    3751           0 :     ScAddress aCellPos1;
    3752           0 :     ScUnoConversion::FillScAddress( aCellPos1, aCell1.aCellAddress );
    3753           0 :     ScAddress aCellPos2;
    3754           0 :     ScUnoConversion::FillScAddress( aCellPos2, aCell2.aCellAddress );
    3755           0 :     bool bIsEqual = false;
    3756           0 :     if( !aCell1.bIsMergedBase && !aCell2.bIsMergedBase &&
    3757           0 :         aCell1.bIsCovered == aCell2.bIsCovered &&
    3758           0 :         !aCell1.bIsMatrixBase && !aCell2.bIsMatrixBase &&
    3759           0 :         aCell1.bIsMatrixCovered == aCell2.bIsMatrixCovered &&
    3760           0 :         aCell1.bHasAnnotation == aCell2.bHasAnnotation &&
    3761           0 :         !aCell1.bHasShape && !aCell2.bHasShape &&
    3762           0 :         aCell1.bHasAreaLink == aCell2.bHasAreaLink &&
    3763           0 :         !aCell1.bHasDetectiveObj && !aCell2.bHasDetectiveObj)
    3764             :     {
    3765           0 :         if( (aCell1.bHasAreaLink &&
    3766           0 :             (aCell1.aAreaLink.GetColCount() == 1) &&
    3767           0 :             (aCell2.aAreaLink.GetColCount() == 1) &&
    3768           0 :             aCell1.aAreaLink.Compare( aCell2.aAreaLink ) ) ||
    3769           0 :             !aCell1.bHasAreaLink )
    3770             :         {
    3771           0 :             if (!aCell1.bHasAnnotation || (aCell1.bHasAnnotation && false/*IsAnnotationEqual(aCell1.xCell, aCell2.xCell)*/)) // no longer compareable
    3772             :             {
    3773           0 :                 if ((((aCell1.nStyleIndex == aCell2.nStyleIndex) && (aCell1.bIsAutoStyle == aCell2.bIsAutoStyle)) ||
    3774           0 :                      ((aCell1.nStyleIndex == aCell2.nStyleIndex) && (aCell1.nStyleIndex == -1))) &&
    3775           0 :                     (aCell1.nValidationIndex == aCell2.nValidationIndex) &&
    3776           0 :                     IsCellTypeEqual(aCell1, aCell2))
    3777             :                 {
    3778           0 :                     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           0 :                             bIsEqual = (aCell1.nNumberFormat == aCell2.nNumberFormat) &&
    3790           0 :                                        (aCell1.maBaseCell.mfValue == aCell2.maBaseCell.mfValue);
    3791             :                         }
    3792           0 :                         break;
    3793             :                     case table::CellContentType_TEXT :
    3794             :                         {
    3795           0 :                             if (IsEditCell(aCell1) || IsEditCell(aCell2))
    3796           0 :                                 bIsEqual = false;
    3797             :                             else
    3798             :                             {
    3799           0 :                                 bIsEqual = (aCell1.maBaseCell.getString(pDoc) == aCell2.maBaseCell.getString(pDoc));
    3800             :                             }
    3801             :                         }
    3802           0 :                         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           0 :     return bIsEqual;
    3819             : }
    3820             : 
    3821           0 : void ScXMLExport::WriteCalculationSettings(const uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc)
    3822             : {
    3823           0 :     uno::Reference<beans::XPropertySet> xPropertySet(xSpreadDoc, uno::UNO_QUERY);
    3824           0 :     if (xPropertySet.is())
    3825             :     {
    3826           0 :         bool bCalcAsShown (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_CALCASSHOWN)) ));
    3827           0 :         bool bIgnoreCase (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_IGNORECASE)) ));
    3828           0 :         bool bLookUpLabels (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_LOOKUPLABELS)) ));
    3829           0 :         bool bMatchWholeCell (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_MATCHWHOLE)) ));
    3830           0 :         bool bUseRegularExpressions (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_REGEXENABLED)) ));
    3831           0 :         bool bIsIterationEnabled (::cppu::any2bool( xPropertySet->getPropertyValue(OUString(SC_UNO_ITERENABLED)) ));
    3832           0 :         sal_uInt16 nYear2000 (pDoc ? pDoc->GetDocOptions().GetYear2000() : 0);
    3833           0 :         sal_Int32 nIterationCount(100);
    3834           0 :         xPropertySet->getPropertyValue( OUString(SC_UNO_ITERCOUNT)) >>= nIterationCount;
    3835           0 :         double fIterationEpsilon = 0;
    3836           0 :         xPropertySet->getPropertyValue( OUString(SC_UNO_ITEREPSILON)) >>= fIterationEpsilon;
    3837           0 :         util::Date aNullDate;
    3838           0 :         xPropertySet->getPropertyValue( OUString(SC_UNO_NULLDATE)) >>= aNullDate;
    3839           0 :         if (bCalcAsShown || bIgnoreCase || !bLookUpLabels || !bMatchWholeCell || !bUseRegularExpressions ||
    3840           0 :             bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001) ||
    3841           0 :             aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899 || nYear2000 != 1930)
    3842             :         {
    3843           0 :             if (bIgnoreCase)
    3844           0 :                 AddAttribute(XML_NAMESPACE_TABLE, XML_CASE_SENSITIVE, XML_FALSE);
    3845           0 :             if (bCalcAsShown)
    3846           0 :                 AddAttribute(XML_NAMESPACE_TABLE, XML_PRECISION_AS_SHOWN, XML_TRUE);
    3847           0 :             if (!bMatchWholeCell)
    3848           0 :                 AddAttribute(XML_NAMESPACE_TABLE, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL, XML_FALSE);
    3849           0 :             if (!bLookUpLabels)
    3850           0 :                 AddAttribute(XML_NAMESPACE_TABLE, XML_AUTOMATIC_FIND_LABELS, XML_FALSE);
    3851           0 :             if (!bUseRegularExpressions)
    3852           0 :                 AddAttribute(XML_NAMESPACE_TABLE, XML_USE_REGULAR_EXPRESSIONS, XML_FALSE);
    3853           0 :             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           0 :             SvXMLElementExport aCalcSettings(*this, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, true, true);
    3860             :             {
    3861           0 :                 if (aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899)
    3862             :                 {
    3863           0 :                     OUStringBuffer sDate;
    3864           0 :                     GetMM100UnitConverter().convertDateTime(sDate, 0.0, aNullDate);
    3865           0 :                     AddAttribute(XML_NAMESPACE_TABLE, XML_DATE_VALUE, sDate.makeStringAndClear());
    3866           0 :                     SvXMLElementExport aElemNullDate(*this, XML_NAMESPACE_TABLE, XML_NULL_DATE, true, true);
    3867             :                 }
    3868           0 :                 if (bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001))
    3869             :                 {
    3870           0 :                     OUStringBuffer sBuffer;
    3871           0 :                     if (bIsIterationEnabled)
    3872           0 :                         AddAttribute(XML_NAMESPACE_TABLE, XML_STATUS, XML_ENABLE);
    3873           0 :                     if (nIterationCount != 100)
    3874             :                     {
    3875             :                         ::sax::Converter::convertNumber(sBuffer,
    3876           0 :                                 nIterationCount);
    3877           0 :                         AddAttribute(XML_NAMESPACE_TABLE, XML_STEPS, sBuffer.makeStringAndClear());
    3878             :                     }
    3879           0 :                     if (!::rtl::math::approxEqual(fIterationEpsilon, 0.001))
    3880             :                     {
    3881             :                         ::sax::Converter::convertDouble(sBuffer,
    3882           0 :                                 fIterationEpsilon);
    3883           0 :                         AddAttribute(XML_NAMESPACE_TABLE, XML_MAXIMUM_DIFFERENCE, sBuffer.makeStringAndClear());
    3884             :                     }
    3885           0 :                     SvXMLElementExport aElemIteration(*this, XML_NAMESPACE_TABLE, XML_ITERATION, true, true);
    3886             :                 }
    3887           0 :             }
    3888             :         }
    3889           0 :     }
    3890           0 : }
    3891             : 
    3892           0 : void ScXMLExport::WriteTableSource()
    3893             : {
    3894           0 :     uno::Reference <sheet::XSheetLinkable> xLinkable (xCurrentTable, uno::UNO_QUERY);
    3895           0 :     if (xLinkable.is() && GetModel().is())
    3896             :     {
    3897           0 :         sheet::SheetLinkMode nMode (xLinkable->getLinkMode());
    3898           0 :         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           0 :     }
    3958           0 : }
    3959             : 
    3960             : // core implementation
    3961           0 : void ScXMLExport::WriteScenario()
    3962             : {
    3963           0 :     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           0 : }
    3994             : 
    3995           0 : void ScXMLExport::WriteTheLabelRanges( const uno::Reference< sheet::XSpreadsheetDocument >& xSpreadDoc )
    3996             : {
    3997           0 :     uno::Reference< beans::XPropertySet > xDocProp( xSpreadDoc, uno::UNO_QUERY );
    3998           0 :     if( !xDocProp.is() ) return;
    3999             : 
    4000           0 :     sal_Int32 nCount(0);
    4001           0 :     uno::Reference< container::XIndexAccess > xColRangesIAccess(xDocProp->getPropertyValue( OUString( SC_UNO_COLLABELRNG ) ), uno::UNO_QUERY);
    4002           0 :     if( xColRangesIAccess.is() )
    4003           0 :         nCount += xColRangesIAccess->getCount();
    4004             : 
    4005           0 :     uno::Reference< container::XIndexAccess > xRowRangesIAccess(xDocProp->getPropertyValue( OUString( SC_UNO_ROWLABELRNG ) ), uno::UNO_QUERY);
    4006           0 :     if( xRowRangesIAccess.is() )
    4007           0 :         nCount += xRowRangesIAccess->getCount();
    4008             : 
    4009           0 :     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           0 :     }
    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           0 : void ScXMLExport::WriteNamedExpressions()
    4041             : {
    4042           0 :     if (!pDoc)
    4043           0 :         return;
    4044           0 :     ScRangeName* pNamedRanges = pDoc->GetRangeName();
    4045           0 :     WriteNamedRange(pNamedRanges);
    4046             : }
    4047             : 
    4048           0 : void ScXMLExport::WriteDataStream()
    4049             : {
    4050           0 :     if (!pDoc)
    4051           0 :         return;
    4052             : 
    4053           0 :     SvtMiscOptions aMiscOptions;
    4054           0 :     if (!aMiscOptions.IsExperimentalMode())
    4055             :         // Export this only in experimental mode.
    4056           0 :         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           0 : void ScXMLExport::WriteNamedRange(ScRangeName* pRangeName)
    4092             : {
    4093             :     //write a global or local ScRangeName
    4094           0 :     SvXMLElementExport aElemNEs(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSIONS, true, true);
    4095           0 :     for (ScRangeName::iterator it = pRangeName->begin(); it != pRangeName->end(); ++it)
    4096             :     {
    4097           0 :         AddAttribute(sAttrName, it->second->GetName());
    4098             : 
    4099           0 :         OUString sBaseCellAddress;
    4100           0 :         it->second->ValidateTabRefs();
    4101           0 :         ScRangeStringConverter::GetStringFromAddress( sBaseCellAddress, it->second->GetPos(), pDoc,
    4102           0 :                             FormulaGrammar::CONV_OOO, ' ', false, SCA_ABS_3D);
    4103           0 :         AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, sBaseCellAddress);
    4104             : 
    4105           0 :         OUString sSymbol;
    4106           0 :         it->second->GetSymbol(sSymbol, pDoc->GetStorageGrammar());
    4107           0 :         OUString sTempSymbol(sSymbol);
    4108           0 :         ScRange aRange;
    4109           0 :         if (it->second->IsReference(aRange))
    4110             :         {
    4111             : 
    4112           0 :             OUString sContent(sTempSymbol.copy(1, sTempSymbol.getLength() -2 ));
    4113           0 :             AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sContent);
    4114             : 
    4115           0 :             sal_Int32 nRangeType = it->second->GetUnoType();
    4116           0 :             OUStringBuffer sBufferRangeType;
    4117           0 :             if ((nRangeType & sheet::NamedRangeFlag::COLUMN_HEADER) == sheet::NamedRangeFlag::COLUMN_HEADER)
    4118           0 :                 sBufferRangeType.append(GetXMLToken(XML_REPEAT_COLUMN));
    4119           0 :             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           0 :             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           0 :             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           0 :             OUString sRangeType = sBufferRangeType.makeStringAndClear();
    4138           0 :             if (!sRangeType.isEmpty())
    4139           0 :                 AddAttribute(XML_NAMESPACE_TABLE, XML_RANGE_USABLE_AS, sRangeType);
    4140           0 :             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           0 :     }
    4149           0 : }
    4150             : 
    4151             : namespace {
    4152             : 
    4153           0 : OUString getCondFormatEntryType(const ScColorScaleEntry& rEntry, bool bFirst = true)
    4154             : {
    4155           0 :     switch(rEntry.GetType())
    4156             :     {
    4157             :         case COLORSCALE_MIN:
    4158           0 :             return OUString("minimum");
    4159             :         case COLORSCALE_MAX:
    4160           0 :             return OUString("maximum");
    4161             :         case COLORSCALE_PERCENT:
    4162           0 :             return OUString("percent");
    4163             :         case COLORSCALE_PERCENTILE:
    4164           0 :             return OUString("percentile");
    4165             :         case COLORSCALE_FORMULA:
    4166           0 :             return OUString("formula");
    4167             :         case COLORSCALE_VALUE:
    4168           0 :             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           0 : void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
    4233             : {
    4234           0 :     ScConditionalFormatList* pCondFormatList = pDoc->GetCondFormList(nTab);
    4235           0 :     if(pCondFormatList)
    4236             :     {
    4237           0 :         if(pCondFormatList && !pCondFormatList->size())
    4238           0 :             return;
    4239             : 
    4240           0 :         SvXMLElementExport aElementCondFormats(*this, XML_NAMESPACE_CALC_EXT, XML_CONDITIONAL_FORMATS, true, true);
    4241             : 
    4242           0 :         if(pCondFormatList)
    4243             :         {
    4244           0 :             for(ScConditionalFormatList::const_iterator itr = pCondFormatList->begin();
    4245           0 :                     itr != pCondFormatList->end(); ++itr)
    4246             :             {
    4247           0 :                 OUString sRanges;
    4248           0 :                 const ScRangeList& rRangeList = itr->GetRange();
    4249           0 :                 ScRangeStringConverter::GetStringFromRangeList( sRanges, &rRangeList, pDoc, formula::FormulaGrammar::CONV_OOO );
    4250           0 :                 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TARGET_RANGE_ADDRESS, sRanges);
    4251           0 :                 SvXMLElementExport aElementCondFormat(*this, XML_NAMESPACE_CALC_EXT, XML_CONDITIONAL_FORMAT, true, true);
    4252           0 :                 size_t nEntries = itr->size();
    4253           0 :                 for(size_t i = 0; i < nEntries; ++i)
    4254             :                 {
    4255           0 :                     const ScFormatEntry* pFormatEntry = itr->GetEntry(i);
    4256           0 :                     if(pFormatEntry->GetType()==condformat::CONDITION)
    4257             :                     {
    4258           0 :                         const ScCondFormatEntry* pEntry = static_cast<const ScCondFormatEntry*>(pFormatEntry);
    4259           0 :                         OUStringBuffer aCond;
    4260           0 :                         ScAddress aPos = pEntry->GetSrcPos();
    4261           0 :                         switch(pEntry->GetOperation())
    4262             :                         {
    4263             :                             case SC_COND_EQUAL:
    4264           0 :                                 aCond.append('=');
    4265           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4266           0 :                                 break;
    4267             :                             case SC_COND_LESS:
    4268           0 :                                 aCond.append('<');
    4269           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4270           0 :                                 break;
    4271             :                             case SC_COND_GREATER:
    4272           0 :                                 aCond.append('>');
    4273           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4274           0 :                                 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           0 :                                 aCond.append(">=");
    4281           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4282           0 :                                 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           0 :                                 aCond.append("between(");
    4289           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4290           0 :                                 aCond.append(',');
    4291           0 :                                 aCond.append(pEntry->GetExpression(aPos, 1, 0, formula::FormulaGrammar::GRAM_ODFF));
    4292           0 :                                 aCond.append(')');
    4293           0 :                                 break;
    4294             :                             case SC_COND_NOTBETWEEN:
    4295           0 :                                 aCond.append("not-between(");
    4296           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4297           0 :                                 aCond.append(',');
    4298           0 :                                 aCond.append(pEntry->GetExpression(aPos, 1, 0, formula::FormulaGrammar::GRAM_ODFF));
    4299           0 :                                 aCond.append(')');
    4300           0 :                                 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           0 :                                 aCond.append("formula-is(");
    4309           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4310           0 :                                 aCond.append(')');
    4311           0 :                                 break;
    4312             :                             case SC_COND_TOP10:
    4313           0 :                                 aCond.append("top-elements(");
    4314           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4315           0 :                                 aCond.append(")");
    4316           0 :                                 break;
    4317             :                             case SC_COND_BOTTOM10:
    4318           0 :                                 aCond.append("bottom-elements(");
    4319           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4320           0 :                                 aCond.append(")");
    4321           0 :                                 break;
    4322             :                             case SC_COND_TOP_PERCENT:
    4323           0 :                                 aCond.append("top-percent(");
    4324           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4325           0 :                                 aCond.append(")");
    4326           0 :                                 break;
    4327             :                             case SC_COND_BOTTOM_PERCENT:
    4328           0 :                                 aCond.append("bottom-percent(");
    4329           0 :                                 aCond.append(pEntry->GetExpression(aPos, 0, 0, formula::FormulaGrammar::GRAM_ODFF));
    4330           0 :                                 aCond.append(")");
    4331           0 :                                 break;
    4332             :                             case SC_COND_ABOVE_AVERAGE:
    4333           0 :                                 aCond.append("above-average");
    4334           0 :                                 break;
    4335             :                             case SC_COND_BELOW_AVERAGE:
    4336           0 :                                 aCond.append("below-average");
    4337           0 :                                 break;
    4338             :                             case SC_COND_ABOVE_EQUAL_AVERAGE:
    4339           0 :                                 aCond.append("above-equal-average");
    4340           0 :                                 break;
    4341             :                             case SC_COND_BELOW_EQUAL_AVERAGE:
    4342           0 :                                 aCond.append("below-equal-average");
    4343           0 :                                 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           0 :                         OUString sStyle = ScStyleNameConversion::DisplayToProgrammaticName(pEntry->GetStyle(), SFX_STYLE_FAMILY_PARA);
    4376           0 :                         AddAttribute(XML_NAMESPACE_CALC_EXT, XML_APPLY_STYLE_NAME, sStyle);
    4377           0 :                         AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, aCond.makeStringAndClear());
    4378             : 
    4379           0 :                         OUString sBaseAddress;
    4380           0 :                         ScRangeStringConverter::GetStringFromAddress( sBaseAddress, aPos, pDoc,formula::FormulaGrammar::CONV_ODF );
    4381           0 :                         AddAttribute(XML_NAMESPACE_CALC_EXT, XML_BASE_CELL_ADDRESS, sBaseAddress);
    4382           0 :                         SvXMLElementExport aElementCondEntry(*this, XML_NAMESPACE_CALC_EXT, XML_CONDITION, true, true);
    4383             :                     }
    4384           0 :                     else if(pFormatEntry->GetType() == condformat::COLORSCALE)
    4385             :                     {
    4386           0 :                         SvXMLElementExport aElementColorScale(*this, XML_NAMESPACE_CALC_EXT, XML_COLOR_SCALE, true, true);
    4387           0 :                         const ScColorScaleFormat& mrColorScale = static_cast<const ScColorScaleFormat&>(*pFormatEntry);
    4388           0 :                         for(ScColorScaleFormat::const_iterator it = mrColorScale.begin();
    4389           0 :                                 it != mrColorScale.end(); ++it)
    4390             :                         {
    4391           0 :                             if(it->GetType() == COLORSCALE_FORMULA)
    4392             :                             {
    4393           0 :                                 OUString sFormula = it->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
    4394           0 :                                 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
    4395             :                             }
    4396             :                             else
    4397           0 :                                 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, OUString::number(it->GetValue()));
    4398             : 
    4399           0 :                             AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*it));
    4400           0 :                             OUStringBuffer aBuffer;
    4401           0 :                             ::sax::Converter::convertColor(aBuffer, it->GetColor().GetColor());
    4402           0 :                             AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLOR, aBuffer.makeStringAndClear());
    4403           0 :                             SvXMLElementExport aElementColorScaleEntry(*this, XML_NAMESPACE_CALC_EXT, XML_COLOR_SCALE_ENTRY, true, true);
    4404           0 :                         }
    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           0 :             }
    4509           0 :         }
    4510             :     }
    4511             : }
    4512             : 
    4513           0 : void ScXMLExport::WriteExternalRefCaches()
    4514             : {
    4515           0 :     if (!pDoc)
    4516           0 :         return;
    4517             : 
    4518           0 :     ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
    4519           0 :     pRefMgr->resetSrcFileData(GetOrigFileName());
    4520           0 :     sal_uInt16 nCount = pRefMgr->getExternalFileCount();
    4521           0 :     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           0 : void ScXMLExport::WriteConsolidation()
    4720             : {
    4721           0 :     if (pDoc)
    4722             :     {
    4723           0 :         const ScConsolidateParam* pCons(pDoc->GetConsolidateDlgData());
    4724           0 :         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           0 : }
    4753             : 
    4754           0 : SvXMLAutoStylePoolP* ScXMLExport::CreateAutoStylePool()
    4755             : {
    4756           0 :     return new ScXMLAutoStylePoolP(*this);
    4757             : }
    4758             : 
    4759           0 : XMLPageExport* ScXMLExport::CreatePageExport()
    4760             : {
    4761           0 :     return new XMLTableMasterPageExport( *this );
    4762             : }
    4763             : 
    4764           0 : void ScXMLExport::GetChangeTrackViewSettings(uno::Sequence<beans::PropertyValue>& rProps)
    4765             : {
    4766           0 :     ScChangeViewSettings* pViewSettings(GetDocument() ? GetDocument()->GetChangeViewSettings() : NULL);
    4767           0 :     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           0 : }
    4816             : 
    4817           0 : void ScXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>& rProps)
    4818             : {
    4819           0 :     rProps.realloc(4);
    4820           0 :     beans::PropertyValue* pProps(rProps.getArray());
    4821           0 :     if(pProps)
    4822             :     {
    4823           0 :         if (GetModel().is())
    4824             :         {
    4825           0 :             ScModelObj* pDocObj(ScModelObj::getImplementation( GetModel() ));
    4826           0 :             if (pDocObj)
    4827             :             {
    4828           0 :                 SfxObjectShell* pEmbeddedObj = pDocObj->GetEmbeddedObject();
    4829           0 :                 if (pEmbeddedObj)
    4830             :                 {
    4831           0 :                     Rectangle aRect(pEmbeddedObj->GetVisArea());
    4832           0 :                     sal_uInt16 i(0);
    4833           0 :                     pProps[i].Name = "VisibleAreaTop";
    4834           0 :                     pProps[i].Value <<= static_cast<sal_Int32>(aRect.getY());
    4835           0 :                     pProps[++i].Name = "VisibleAreaLeft";
    4836           0 :                     pProps[i].Value <<= static_cast<sal_Int32>(aRect.getX());
    4837           0 :                     pProps[++i].Name = "VisibleAreaWidth";
    4838           0 :                     pProps[i].Value <<= static_cast<sal_Int32>(aRect.getWidth());
    4839           0 :                     pProps[++i].Name = "VisibleAreaHeight";
    4840           0 :                     pProps[i].Value <<= static_cast<sal_Int32>(aRect.getHeight());
    4841             :                 }
    4842             :             }
    4843             :         }
    4844             :     }
    4845           0 :     GetChangeTrackViewSettings(rProps);
    4846           0 : }
    4847             : 
    4848             : 
    4849           0 : void ScXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>& rProps)
    4850             : {
    4851           0 :     if (GetModel().is())
    4852             :     {
    4853           0 :         uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
    4854           0 :         if (xMultiServiceFactory.is())
    4855             :         {
    4856           0 :             uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance("com.sun.star.comp.SpreadsheetSettings"), uno::UNO_QUERY);
    4857           0 :             if (xProperties.is())
    4858           0 :                 SvXMLUnitConverter::convertPropertySet(rProps, xProperties);
    4859             : 
    4860           0 :             sal_Int32 nPropsToAdd = 0;
    4861           0 :             OUStringBuffer aTrackedChangesKey;
    4862           0 :             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           0 :             bool bVBACompat = false;
    4871           0 :             uno::Reference <container::XNameAccess> xCodeNameAccess;
    4872             :             OSL_ENSURE( pDoc, "ScXMLExport::GetConfigurationSettings - no ScDocument!" );
    4873           0 :             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           0 :             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           0 :             }
    4909           0 :         }
    4910             :     }
    4911           0 : }
    4912             : 
    4913           0 : XMLShapeExport* ScXMLExport::CreateShapeExport()
    4914             : {
    4915           0 :     return new ScXMLShapeExport(*this);
    4916             : }
    4917             : 
    4918           0 : void ScXMLExport::CreateSharedData(const sal_Int32 nTableCount)
    4919             : {
    4920           0 :     pSharedData = new ScMySharedData(nTableCount);
    4921           0 : }
    4922             : 
    4923           0 : XMLNumberFormatAttributesExportHelper* ScXMLExport::GetNumberFormatAttributesExportHelper()
    4924             : {
    4925           0 :     if (!pNumberFormatAttributesExportHelper)
    4926           0 :         pNumberFormatAttributesExportHelper = new XMLNumberFormatAttributesExportHelper(GetNumberFormatsSupplier(), *this );
    4927           0 :     return pNumberFormatAttributesExportHelper;
    4928             : }
    4929             : 
    4930           0 : void ScXMLExport::CollectUserDefinedNamespaces(const SfxItemPool* pPool, sal_uInt16 nAttrib)
    4931             : {
    4932             :     const SfxPoolItem* pItem;
    4933           0 :     sal_uInt32 nItems(pPool->GetItemCount2( nAttrib ));
    4934           0 :     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           0 :     _GetNamespaceMap().Add(
    4962           0 :         GetXMLToken( XML_NP_PRESENTATION ),
    4963           0 :         GetXMLToken( XML_N_PRESENTATION ),
    4964           0 :         XML_NAMESPACE_PRESENTATION );
    4965           0 : }
    4966             : 
    4967           0 : void ScXMLExport::IncrementProgressBar(bool bFlush, sal_Int32 nInc)
    4968             : {
    4969           0 :     nProgressCount += nInc;
    4970           0 :     if (bFlush || nProgressCount > 100)
    4971             :     {
    4972           0 :         GetProgressBarHelper()->Increment(nProgressCount);
    4973           0 :         nProgressCount = 0;
    4974             :     }
    4975           0 : }
    4976             : 
    4977           0 : sal_uInt32 ScXMLExport::exportDoc( enum XMLTokenEnum eClass )
    4978             : {
    4979           0 :     if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES|
    4980             :                              EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
    4981             :     {
    4982           0 :         if (GetDocument())
    4983             :         {
    4984             :             // if source doc was Excel then
    4985           0 :             uno::Reference< frame::XModel > xModel = GetModel();
    4986           0 :             if ( xModel.is() )
    4987             :             {
    4988           0 :                 uno::Reference< lang::XUnoTunnel >  xObjShellTunnel( xModel, uno::UNO_QUERY );
    4989           0 :                 SfxObjectShell* pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel.is() ? xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()) : 0 );
    4990           0 :                 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           0 :                 }
    4997             :             }
    4998           0 :             CollectUserDefinedNamespaces(GetDocument()->GetPool(), ATTR_USERDEF);
    4999           0 :             CollectUserDefinedNamespaces(GetDocument()->GetEditPool(), EE_PARA_XMLATTRIBS);
    5000           0 :             CollectUserDefinedNamespaces(GetDocument()->GetEditPool(), EE_CHAR_XMLATTRIBS);
    5001           0 :             ScDrawLayer* pDrawLayer = GetDocument()->GetDrawLayer();
    5002           0 :             if (pDrawLayer)
    5003             :             {
    5004           0 :                 CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), EE_PARA_XMLATTRIBS);
    5005           0 :                 CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), EE_CHAR_XMLATTRIBS);
    5006           0 :                 CollectUserDefinedNamespaces(&pDrawLayer->GetItemPool(), SDRATTR_XMLATTRIBUTES);
    5007             :             }
    5008             : 
    5009             :             // sheet events use officeooo namespace
    5010           0 :             if( (getExportFlags() & EXPORT_CONTENT) != 0 &&
    5011           0 :                 getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
    5012             :             {
    5013           0 :                 bool bAnySheetEvents = false;
    5014           0 :                 SCTAB nTabCount = pDoc->GetTableCount();
    5015           0 :                 for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
    5016           0 :                     if (pDoc->GetSheetEvents(nTab))
    5017           0 :                         bAnySheetEvents = true;
    5018           0 :                 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           0 :             }
    5024             :         }
    5025             :     }
    5026           0 :     return SvXMLExport::exportDoc( eClass );
    5027             : }
    5028             : 
    5029             : // XExporter
    5030           0 : void SAL_CALL ScXMLExport::setSourceDocument( const uno::Reference<lang::XComponent>& xComponent )
    5031             :                             throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
    5032             : {
    5033           0 :     SolarMutexGuard aGuard;
    5034           0 :     SvXMLExport::setSourceDocument( xComponent );
    5035             : 
    5036           0 :     pDoc = ScXMLConverter::GetScDocument( GetModel() );
    5037             :     OSL_ENSURE( pDoc, "ScXMLExport::setSourceDocument - no ScDocument!" );
    5038           0 :     if (!pDoc)
    5039           0 :         throw lang::IllegalArgumentException();
    5040             : 
    5041             :     // create ScChangeTrackingExportHelper after document is known
    5042           0 :     pChangeTrackingExportHelper = new ScChangeTrackingExportHelper(*this);
    5043             : 
    5044             :     // Set the document's storage grammar corresponding to the ODF version that
    5045             :     // is to be written.
    5046           0 :     SvtSaveOptions::ODFDefaultVersion meODFDefaultVersion = getDefaultVersion();
    5047           0 :     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           0 :             pDoc->SetStorageGrammar( formula::FormulaGrammar::GRAM_ODFF);
    5056           0 :     }
    5057           0 : }
    5058             : 
    5059             : // XFilter
    5060           0 : 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           0 :     SolarMutexGuard aGuard;
    5064           0 :     if (pDoc)
    5065           0 :         pDoc->EnableIdle(false);
    5066           0 :     bool bReturn(SvXMLExport::filter(aDescriptor));
    5067           0 :     if (pDoc)
    5068           0 :         pDoc->EnableIdle(true);
    5069           0 :     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           0 : 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           0 :     SolarMutexGuard aGuard;
    5086           0 :     SvXMLExport::initialize(aArguments);
    5087           0 : }
    5088             : 
    5089             : // XUnoTunnel
    5090           0 : 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           0 :     SolarMutexGuard aGuard;
    5094           0 :     return SvXMLExport::getSomething(aIdentifier);
    5095             : }
    5096             : 
    5097           0 : void ScXMLExport::DisposingModel()
    5098             : {
    5099           0 :     SvXMLExport::DisposingModel();
    5100           0 :     pDoc = NULL;
    5101           0 :     xCurrentTable = 0;
    5102           0 : }
    5103             : 
    5104             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10