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

Generated by: LCOV version 1.11