[Libreoffice-commits] .: 18 commits - sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Mar 11 13:05:16 PST 2011


 sc/inc/address.hxx                   |    2 
 sc/inc/compiler.hxx                  |    7 
 sc/inc/document.hxx                  |    1 
 sc/inc/table.hxx                     |    4 
 sc/inc/token.hxx                     |   16 +
 sc/inc/tokenarray.hxx                |    1 
 sc/source/core/data/documen3.cxx     |    8 
 sc/source/core/data/table1.cxx       |    2 
 sc/source/core/data/table2.cxx       |    7 
 sc/source/core/tool/address.cxx      |    8 
 sc/source/core/tool/compiler.cxx     |   45 ++
 sc/source/core/tool/token.cxx        |   50 ++-
 sc/source/filter/excel/excform.cxx   |    8 
 sc/source/filter/excel/excform8.cxx  |   26 +
 sc/source/filter/excel/frmbase.cxx   |   95 ++----
 sc/source/filter/excel/impop.cxx     |   10 
 sc/source/filter/excel/tokstack.cxx  |   54 ++-
 sc/source/filter/excel/xeformula.cxx |    7 
 sc/source/filter/excel/xename.cxx    |   80 +++--
 sc/source/filter/excel/xiname.cxx    |   12 
 sc/source/filter/inc/formel.hxx      |   31 --
 sc/source/filter/inc/tokstack.hxx    |    9 
 sc/source/filter/inc/xename.hxx      |    2 
 sc/source/filter/xml/xmlbodyi.cxx    |    5 
 sc/source/filter/xml/xmlexprt.cxx    |  530 ++++++++++++++++++-----------------
 sc/source/filter/xml/xmlexprt.hxx    |    1 
 sc/source/filter/xml/xmlimprt.cxx    |   50 +--
 sc/source/filter/xml/xmlimprt.hxx    |   11 
 sc/source/filter/xml/xmlnexpi.cxx    |  106 +++++--
 sc/source/filter/xml/xmlnexpi.hxx    |   75 ++++
 sc/source/filter/xml/xmltabi.cxx     |   17 +
 31 files changed, 819 insertions(+), 461 deletions(-)

New commits:
commit f2763830af871e98581d3ca0ad6df06dcb24f836
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Mar 11 16:01:01 2011 -0500

    A little cleanup.

diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx
index 390b0a2..8debff0 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -178,8 +178,10 @@ private:
      */
     sal_uInt16          FindNamedExpIndex( SCTAB nTab, sal_uInt16 nScIdx );
 
-    /** Finds the index of a NAME record from the passed Calc index in the specified map. */
-    sal_uInt16          FindNameIdx( const XclExpIndexMap& rMap, USHORT nScIdx ) const;
+    /**
+     * Find the index of a NAME record from Calc's database range index.
+     */
+    sal_uInt16          FindDBNameIdx( USHORT nScIdx ) const;
     /** Returns the index of an existing built-in NAME record with the passed definition, otherwise 0. */
     sal_uInt16          FindBuiltInNameIdx( const String& rName,
                             const XclTokenArray& rTokArr, bool bDBRange ) const;
@@ -412,7 +414,7 @@ sal_uInt16 XclExpNameManagerImpl::InsertName( SCTAB nTab, USHORT nScNameIdx )
 
 sal_uInt16 XclExpNameManagerImpl::InsertDBRange( USHORT nScDBRangeIdx )
 {
-    sal_uInt16 nNameIdx = FindNameIdx( maDBRangeMap, nScDBRangeIdx );
+    sal_uInt16 nNameIdx = FindDBNameIdx( nScDBRangeIdx );
     if( nNameIdx == 0 )
         if( const ScDBData* pDBData = GetDatabaseRanges().FindIndex( nScDBRangeIdx ) )
             nNameIdx = CreateName( *pDBData );
@@ -512,10 +514,10 @@ sal_uInt16 XclExpNameManagerImpl::FindNamedExpIndex( SCTAB nTab, sal_uInt16 nScI
     return (itr == maNamedExpMap.end()) ? 0 : itr->second;
 }
 
-sal_uInt16 XclExpNameManagerImpl::FindNameIdx( const XclExpIndexMap& rMap, USHORT nScIdx ) const
+sal_uInt16 XclExpNameManagerImpl::FindDBNameIdx( USHORT nScIdx ) const
 {
-    XclExpIndexMap::const_iterator aIt = rMap.find( nScIdx );
-    return (aIt == rMap.end()) ? 0 : aIt->second;
+    XclExpIndexMap::const_iterator aIt = maDBRangeMap.find( nScIdx );
+    return (aIt == maDBRangeMap.end()) ? 0 : aIt->second;
 }
 
 sal_uInt16 XclExpNameManagerImpl::FindBuiltInNameIdx(
@@ -723,7 +725,7 @@ void XclExpNameManagerImpl::CreateDatabaseNames()
         const ScDBData* pDBData = rDBRanges[ nDBIdx ];
         DBG_ASSERT( pDBData, "XclExpNameManagerImpl::CreateDatabaseNames - missing database range" );
         // skip hidden "unnamed" range
-        if( pDBData && (pDBData->GetName() != maUnnamedDBName) && !FindNameIdx( maDBRangeMap, pDBData->GetIndex() ) )
+        if( pDBData && (pDBData->GetName() != maUnnamedDBName) && !FindDBNameIdx( pDBData->GetIndex() ) )
             CreateName( *pDBData );
     }
 }
commit 0a0258ad178891b3f03f480b2a155fd8813872d8
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Mar 11 15:52:40 2011 -0500

    Properly export sheet local range names to XLS.

diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx
index bf7adbd..56ae9ef 100644
--- a/sc/source/filter/excel/xeformula.cxx
+++ b/sc/source/filter/excel/xeformula.cxx
@@ -2049,8 +2049,13 @@ void XclExpFmlaCompImpl::ProcessExternalRangeRef( const XclExpScToken& rTokData
 
 void XclExpFmlaCompImpl::ProcessDefinedName( const XclExpScToken& rTokData )
 {
+    SCTAB nTab = SCTAB_GLOBAL;
+    bool bGlobal = static_cast<bool>(rTokData.mpScToken->GetByte());
+    if (!bGlobal && mxData->mpScBasePos)
+        nTab = mxData->mpScBasePos->Tab();
+
     XclExpNameManager& rNameMgr = GetNameManager();
-    sal_uInt16 nNameIdx = rNameMgr.InsertName( rTokData.mpScToken->GetIndex() );
+    sal_uInt16 nNameIdx = rNameMgr.InsertName(nTab, rTokData.mpScToken->GetIndex());
     if( nNameIdx != 0 )
     {
         // global names always with tName token, local names dependent on config
diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx
index e60983b..390b0a2 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -136,7 +136,7 @@ public:
     void                Initialize();
 
     /** Inserts the Calc name with the passed index and returns the Excel NAME index. */
-    sal_uInt16          InsertName( USHORT nScNameIdx );
+    sal_uInt16          InsertName( SCTAB nTab, USHORT nScNameIdx );
     /** Inserts the Calc database range with the passed index and returns the Excel NAME index. */
     sal_uInt16          InsertDBRange( USHORT nScDBRangeIdx );
 
@@ -167,7 +167,17 @@ private:
     typedef XclExpNameList::RecordRefType       XclExpNameRef;
     typedef ::std::map< USHORT, sal_uInt16 >    XclExpIndexMap;
 
+    typedef ::std::map< ::std::pair<SCTAB, sal_uInt16>, sal_uInt16> NamedExpIndexMap;
+
 private:
+    /**
+     * @param nTab 0-based table index, or SCTAB_GLOBAL for global names.
+     * @param nScIdx calc's name index.
+     *
+     * @return excel's name index.
+     */
+    sal_uInt16          FindNamedExpIndex( SCTAB nTab, sal_uInt16 nScIdx );
+
     /** Finds the index of a NAME record from the passed Calc index in the specified map. */
     sal_uInt16          FindNameIdx( const XclExpIndexMap& rMap, USHORT nScIdx ) const;
     /** Returns the index of an existing built-in NAME record with the passed definition, otherwise 0. */
@@ -181,7 +191,7 @@ private:
     sal_uInt16          Append( XclExpNameRef xName );
     /** Creates a new NAME record for the passed user-defined name.
         @return  The 1-based NAME record index used elsewhere in the Excel file. */
-    sal_uInt16          CreateName( const ScRangeData& rRangeData );
+    sal_uInt16          CreateName( SCTAB nTab, const ScRangeData& rRangeData );
     /** Creates a new NAME record for the passed database range.
         @return  The 1-based NAME record index used elsewhere in the Excel file. */
     sal_uInt16          CreateName( const ScDBData& rDBData );
@@ -194,8 +204,13 @@ private:
     void                CreateDatabaseNames();
 
 private:
+    /**
+     * Maps Calc's named range to Excel's NAME records.  Global names use
+     * -1 as their table index, whereas sheet-local names have 0-based table
+     *  index.
+     */
+    NamedExpIndexMap    maNamedExpMap;
     XclExpNameList      maNameList;         /// List of NAME records.
-    XclExpIndexMap      maNameMap;          /// Maps Calc defined names to Excel NAME records.
     XclExpIndexMap      maDBRangeMap;       /// Maps Calc database ranges to Excel NAME records.
     String              maUnnamedDBName;    /// Name of the hidden unnamed database range.
     size_t              mnFirstUserIdx;     /// List index of first user-defined NAME record.
@@ -378,12 +393,20 @@ void XclExpNameManagerImpl::Initialize()
     CreateDatabaseNames();
 }
 
-sal_uInt16 XclExpNameManagerImpl::InsertName( USHORT nScNameIdx )
+sal_uInt16 XclExpNameManagerImpl::InsertName( SCTAB nTab, USHORT nScNameIdx )
 {
-    sal_uInt16 nNameIdx = FindNameIdx( maNameMap, nScNameIdx );
-    if( nNameIdx == 0 )
-        if( const ScRangeData* pRangeData = GetNamedRanges().findByIndex( nScNameIdx ) )
-            nNameIdx = CreateName( *pRangeData );
+    sal_uInt16 nNameIdx = FindNamedExpIndex( nTab, nScNameIdx );
+    if (nNameIdx)
+        return nNameIdx;
+
+    const ScRangeData* pData = NULL;
+    ScRangeName* pRN = (nTab == SCTAB_GLOBAL) ? GetDoc().GetRangeName() : GetDoc().GetRangeName(nTab);
+    if (pRN)
+        pData = pRN->findByIndex(nScNameIdx);
+
+    if (pData)
+        nNameIdx = CreateName(nTab, *pData);
+
     return nNameIdx;
 }
 
@@ -482,6 +505,13 @@ void XclExpNameManagerImpl::SaveXml( XclExpXmlStream& rStrm )
 
 // private --------------------------------------------------------------------
 
+sal_uInt16 XclExpNameManagerImpl::FindNamedExpIndex( SCTAB nTab, sal_uInt16 nScIdx )
+{
+    NamedExpIndexMap::key_type key = NamedExpIndexMap::key_type(nTab, nScIdx);
+    NamedExpIndexMap::const_iterator itr = maNamedExpMap.find(key);
+    return (itr == maNamedExpMap.end()) ? 0 : itr->second;
+}
+
 sal_uInt16 XclExpNameManagerImpl::FindNameIdx( const XclExpIndexMap& rMap, USHORT nScIdx ) const
 {
     XclExpIndexMap::const_iterator aIt = rMap.find( nScIdx );
@@ -542,7 +572,7 @@ sal_uInt16 XclExpNameManagerImpl::Append( XclExpNameRef xName )
     return static_cast< sal_uInt16 >( maNameList.GetSize() );  // 1-based
 }
 
-sal_uInt16 XclExpNameManagerImpl::CreateName( const ScRangeData& rRangeData )
+sal_uInt16 XclExpNameManagerImpl::CreateName( SCTAB nTab, const ScRangeData& rRangeData )
 {
     const String& rName = rRangeData.GetName();
 
@@ -551,9 +581,12 @@ sal_uInt16 XclExpNameManagerImpl::CreateName( const ScRangeData& rRangeData )
         with the same defined name will not find it and will create it again. */
     size_t nOldListSize = maNameList.GetSize();
     XclExpNameRef xName( new XclExpName( GetRoot(), rName ) );
+    if (nTab != SCTAB_GLOBAL)
+        xName->SetLocalTab(nTab);
     sal_uInt16 nNameIdx = Append( xName );
     // store the index of the NAME record in the lookup map
-    maNameMap[ rRangeData.GetIndex() ] = nNameIdx;
+    NamedExpIndexMap::key_type key = NamedExpIndexMap::key_type(nTab, rRangeData.GetIndex());
+    maNamedExpMap[key] = nNameIdx;
 
     /*  Create the definition formula.
         This may cause recursive creation of other defined names. */
@@ -578,7 +611,8 @@ sal_uInt16 XclExpNameManagerImpl::CreateName( const ScRangeData& rRangeData )
             while( maNameList.GetSize() > nOldListSize )
                 maNameList.RemoveRecord( maNameList.GetSize() - 1 );
             // use index of the found built-in NAME record
-            maNameMap[ rRangeData.GetIndex() ] = nNameIdx = nBuiltInIdx;
+            key = NamedExpIndexMap::key_type(nTab, rRangeData.GetIndex());
+            maNamedExpMap[key] = nNameIdx = nBuiltInIdx;
         }
     }
 
@@ -676,8 +710,8 @@ void XclExpNameManagerImpl::CreateUserNames()
     for (; itr != itrEnd; ++itr)
     {
         // skip definitions of shared formulas
-        if (!itr->HasType(RT_SHARED) && !FindNameIdx(maNameMap, itr->GetIndex()))
-            CreateName(*itr);
+        if (!itr->HasType(RT_SHARED) && !FindNamedExpIndex(SCTAB_GLOBAL, itr->GetIndex()))
+            CreateName(SCTAB_GLOBAL, *itr);
     }
 }
 
@@ -711,9 +745,9 @@ void XclExpNameManager::Initialize()
     mxImpl->Initialize();
 }
 
-sal_uInt16 XclExpNameManager::InsertName( USHORT nScNameIdx )
+sal_uInt16 XclExpNameManager::InsertName( SCTAB nTab, USHORT nScNameIdx )
 {
-    return mxImpl->InsertName( nScNameIdx );
+    return mxImpl->InsertName( nTab, nScNameIdx );
 }
 
 sal_uInt16 XclExpNameManager::InsertDBRange( USHORT nScDBRangeIdx )
diff --git a/sc/source/filter/inc/xename.hxx b/sc/source/filter/inc/xename.hxx
index 2b6a4c4..5111d22 100644
--- a/sc/source/filter/inc/xename.hxx
+++ b/sc/source/filter/inc/xename.hxx
@@ -51,7 +51,7 @@ public:
     void                Initialize();
 
     /** Inserts the Calc name with the passed index and returns the Excel NAME index. */
-    sal_uInt16          InsertName( USHORT nScNameIdx );
+    sal_uInt16          InsertName( SCTAB nTab, USHORT nScNameIdx );
     /** Inserts the Calc database range with the passed index and returns the Excel NAME index. */
     sal_uInt16          InsertDBRange( USHORT nScDBRangeIdx );
 
commit 679f9612c86d5606a103d58a0adf28016d0c8ece
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Mar 11 11:19:05 2011 -0500

    For now, we only import normal named expressions in sheet local scope.

diff --git a/sc/source/filter/xml/xmlnexpi.cxx b/sc/source/filter/xml/xmlnexpi.cxx
index fd3c082..8d5e040 100644
--- a/sc/source/filter/xml/xmlnexpi.cxx
+++ b/sc/source/filter/xml/xmlnexpi.cxx
@@ -67,6 +67,10 @@ void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpressio
 
     ::boost::scoped_ptr<ScMyNamedExpression> p(pExp);
 
+    if (p->sRangeType.getLength() > 0)
+        // For now, we only accept normal named expressions.
+        return;
+
     if (mpDoc && !mrRangeName.findByName(p->sName))
     {
         // Insert a new name.
commit b5b6f3075243adc8eef95d9e6930641b6c1c1e3b
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Mar 11 01:19:53 2011 -0500

    Use boost::ptr_list for list containing heap objects.

diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index f953520..3301353 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -2791,7 +2791,7 @@ void ScXMLImport::SetNamedRanges()
     {
         sal_Int32 nOffset = 0;
         bool bSuccess = ScRangeStringConverter::GetAddressFromString(
-            aCellAddress, (*aItr)->sBaseCellAddress, GetDocument(), FormulaGrammar::CONV_OOO, nOffset);
+            aCellAddress, aItr->sBaseCellAddress, GetDocument(), FormulaGrammar::CONV_OOO, nOffset);
 
         if (!bSuccess)
             // Conversion of base cell address failed.  Skip this.
@@ -2800,7 +2800,7 @@ void ScXMLImport::SetNamedRanges()
         try
         {
             xNamedRanges->addNewByName(
-                (*aItr)->sName, sTempContent, aCellAddress, GetRangeType((*aItr)->sRangeType));
+                aItr->sName, sTempContent, aCellAddress, GetRangeType(aItr->sRangeType));
         }
         catch( uno::RuntimeException& )
         {
@@ -2811,7 +2811,7 @@ void ScXMLImport::SetNamedRanges()
                 sal_Int32 nMax = xIndex->getCount();
                 bool bInserted = false;
                 sal_Int32 nCount = 1;
-                OUStringBuffer sName((*aItr)->sName);
+                OUStringBuffer sName(aItr->sName);
                 sName.append(sal_Unicode('_'));
                 while (!bInserted && nCount <= nMax)
                 {
@@ -2821,7 +2821,7 @@ void ScXMLImport::SetNamedRanges()
                     {
                         xNamedRanges->addNewByName(
                             sTemp.makeStringAndClear(), sTempContent, aCellAddress,
-                            GetRangeType((*aItr)->sRangeType));
+                            GetRangeType(aItr->sRangeType));
                         bInserted = true;
                     }
                     catch( uno::RuntimeException& )
@@ -2839,24 +2839,23 @@ void ScXMLImport::SetNamedRanges()
     {
         sal_Int32 nOffset(0);
         if (ScRangeStringConverter::GetAddressFromString(
-            aCellAddress, (*aItr)->sBaseCellAddress, GetDocument(), FormulaGrammar::CONV_OOO, nOffset ))
+            aCellAddress, aItr->sBaseCellAddress, GetDocument(), FormulaGrammar::CONV_OOO, nOffset ))
         {
-            uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName((*aItr)->sName), uno::UNO_QUERY);
+            uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName(aItr->sName), uno::UNO_QUERY);
             if (xNamedRange.is())
             {
                 ScXMLImport::MutexGuard aGuard(*this);
                 ScNamedRangeObj* pNamedRangeObj = ScNamedRangeObj::getImplementation( xNamedRange);
                 if (pNamedRangeObj)
                 {
-                    sTempContent = (*aItr)->sContent;
+                    sTempContent = aItr->sContent;
                     // Get rid of leading sheet dots in simple ranges.
-                    if (!(*aItr)->bIsExpression)
+                    if (!aItr->bIsExpression)
                         ScXMLConverter::ParseFormula( sTempContent, false);
-                    pNamedRangeObj->SetContentWithGrammar( sTempContent, (*aItr)->eGrammar);
+                    pNamedRangeObj->SetContentWithGrammar( sTempContent, aItr->eGrammar);
                 }
             }
         }
-        delete *aItr;
         aItr = pNamedExpressions->erase(aItr);
     }
 }
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index dd71ee3..599fa44 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -54,6 +54,7 @@
 
 #include <vector>
 #include <boost/unordered_map.hpp>
+#include <boost/ptr_container/ptr_list.hpp>
 
 class ScRangeList;
 class ScMyStyleNumberFormats;
@@ -632,7 +633,7 @@ struct ScMyNamedExpression
     sal_Bool           bIsExpression;
 };
 
-typedef std::list<const ScMyNamedExpression*> ScMyNamedExpressions;
+typedef ::boost::ptr_list<ScMyNamedExpression> ScMyNamedExpressions;
 
 struct ScMyLabelRange
 {
@@ -908,10 +909,13 @@ public:
     const SvXMLTokenMap& GetDataPilotMemberAttrTokenMap();
     const SvXMLTokenMap& GetConsolidationAttrTokenMap();
 
-    void	AddNamedExpression(const ScMyNamedExpression* pMyNamedExpression) {
+    void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression)
+    {
         if (!pMyNamedExpressions)
             pMyNamedExpressions = new ScMyNamedExpressions();
-        pMyNamedExpressions->push_back(pMyNamedExpression); }
+        pMyNamedExpressions->push_back(pMyNamedExpression);
+    }
+
     ScMyNamedExpressions* GetNamedExpressions() { return pMyNamedExpressions; }
 
     void    AddLabelRange(const ScMyLabelRange* pMyLabelRange) {
diff --git a/sc/source/filter/xml/xmlnexpi.cxx b/sc/source/filter/xml/xmlnexpi.cxx
index bfee5e7..fd3c082 100644
--- a/sc/source/filter/xml/xmlnexpi.cxx
+++ b/sc/source/filter/xml/xmlnexpi.cxx
@@ -77,6 +77,10 @@ void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpressio
 
         if (bSuccess)
         {
+            ::rtl::OUString aContent = p->sContent;
+            if (!p->bIsExpression)
+                ScXMLConverter::ParseFormula(aContent, false);
+
             ScRangeData* pData = new ScRangeData(
                 mpDoc, p->sName, p->sContent, aPos, RT_NAME, p->eGrammar);
             pData->SetIndex(-1);
commit 60808f575c2863ccc48f16291994bd1f61f61a56
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Mar 11 01:05:08 2011 -0500

    Pick up sheet local named expressions during ODS import.

diff --git a/sc/source/filter/xml/xmlbodyi.cxx b/sc/source/filter/xml/xmlbodyi.cxx
index ec5bac0..c8f00d5 100644
--- a/sc/source/filter/xml/xmlbodyi.cxx
+++ b/sc/source/filter/xml/xmlbodyi.cxx
@@ -201,8 +201,9 @@ SvXMLImportContext *ScXMLBodyContext::CreateChildContext( USHORT nPrefix,
         }
         break;
     case XML_TOK_BODY_NAMED_EXPRESSIONS:
-        pContext = new ScXMLNamedExpressionsContext ( GetScImport(), nPrefix, rLocalName,
-                                                        xAttrList );
+        pContext = new ScXMLNamedExpressionsContext (
+            GetScImport(), nPrefix, rLocalName, xAttrList,
+            new ScXMLNamedExpressionsContext::GlobalInserter(GetScImport()) );
         break;
     case XML_TOK_BODY_DATABASE_RANGES:
         pContext = new ScXMLDatabaseRangesContext ( GetScImport(), nPrefix, rLocalName,
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index e53dfbd..f953520 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -638,21 +638,22 @@ const SvXMLTokenMap& ScXMLImport::GetTableElemTokenMap()
     {
         static SvXMLTokenMapEntry aTableTokenMap[] =
         {
-            { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMN_GROUP, 		XML_TOK_TABLE_COL_GROUP		},
-            { XML_NAMESPACE_TABLE,	XML_TABLE_HEADER_COLUMNS,		XML_TOK_TABLE_HEADER_COLS	},
-            { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMNS,				XML_TOK_TABLE_COLS			},
-            { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMN,				XML_TOK_TABLE_COL			},
-            { XML_NAMESPACE_TABLE,  XML_TABLE_PROTECTION,           XML_TOK_TABLE_PROTECTION    },
-            { XML_NAMESPACE_TABLE,	XML_TABLE_ROW_GROUP,			XML_TOK_TABLE_ROW_GROUP		},
-            { XML_NAMESPACE_TABLE,	XML_TABLE_HEADER_ROWS,			XML_TOK_TABLE_HEADER_ROWS	},
-            { XML_NAMESPACE_TABLE,	XML_TABLE_ROWS, 				XML_TOK_TABLE_ROWS			},
-            { XML_NAMESPACE_TABLE,	XML_TABLE_ROW,					XML_TOK_TABLE_ROW			},
-            { XML_NAMESPACE_TABLE,	XML_TABLE_SOURCE,				XML_TOK_TABLE_SOURCE		},
-            { XML_NAMESPACE_TABLE,	XML_SCENARIO,					XML_TOK_TABLE_SCENARIO		},
-            { XML_NAMESPACE_TABLE,	XML_SHAPES, 					XML_TOK_TABLE_SHAPES		},
-            { XML_NAMESPACE_OFFICE,	XML_FORMS,						XML_TOK_TABLE_FORMS			},
-            { XML_NAMESPACE_OFFICE, XML_EVENT_LISTENERS,            XML_TOK_TABLE_EVENT_LISTENERS },
-            { XML_NAMESPACE_OFFICE_EXT, XML_EVENT_LISTENERS,        XML_TOK_TABLE_EVENT_LISTENERS_EXT },
+            { XML_NAMESPACE_TABLE,  XML_NAMED_EXPRESSIONS,    XML_TOK_TABLE_NAMED_EXPRESSIONS },
+            { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMN_GROUP,   XML_TOK_TABLE_COL_GROUP		},
+            { XML_NAMESPACE_TABLE,	XML_TABLE_HEADER_COLUMNS, XML_TOK_TABLE_HEADER_COLS	},
+            { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMNS,		  XML_TOK_TABLE_COLS			},
+            { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMN,		  XML_TOK_TABLE_COL			},
+            { XML_NAMESPACE_TABLE,  XML_TABLE_PROTECTION,     XML_TOK_TABLE_PROTECTION    },
+            { XML_NAMESPACE_TABLE,	XML_TABLE_ROW_GROUP,	  XML_TOK_TABLE_ROW_GROUP		},
+            { XML_NAMESPACE_TABLE,	XML_TABLE_HEADER_ROWS,	  XML_TOK_TABLE_HEADER_ROWS	},
+            { XML_NAMESPACE_TABLE,	XML_TABLE_ROWS, 		  XML_TOK_TABLE_ROWS			},
+            { XML_NAMESPACE_TABLE,	XML_TABLE_ROW,			  XML_TOK_TABLE_ROW			},
+            { XML_NAMESPACE_TABLE,	XML_TABLE_SOURCE,		  XML_TOK_TABLE_SOURCE		},
+            { XML_NAMESPACE_TABLE,	XML_SCENARIO,			  XML_TOK_TABLE_SCENARIO		},
+            { XML_NAMESPACE_TABLE,	XML_SHAPES, 			  XML_TOK_TABLE_SHAPES		},
+            { XML_NAMESPACE_OFFICE,	XML_FORMS,				  XML_TOK_TABLE_FORMS			},
+            { XML_NAMESPACE_OFFICE, XML_EVENT_LISTENERS,      XML_TOK_TABLE_EVENT_LISTENERS },
+            { XML_NAMESPACE_OFFICE_EXT, XML_EVENT_LISTENERS,  XML_TOK_TABLE_EVENT_LISTENERS_EXT },
             XML_TOKEN_MAP_END
         };
 
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index e460901..dd71ee3 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -164,6 +164,7 @@ enum ScXMLLabelRangeAttrTokens
 
 enum ScXMLTableTokens
 {
+    XML_TOK_TABLE_NAMED_EXPRESSIONS,
     XML_TOK_TABLE_COL_GROUP,
     XML_TOK_TABLE_HEADER_COLS,
     XML_TOK_TABLE_COLS,
diff --git a/sc/source/filter/xml/xmlnexpi.cxx b/sc/source/filter/xml/xmlnexpi.cxx
index 1c85de1..bfee5e7 100644
--- a/sc/source/filter/xml/xmlnexpi.cxx
+++ b/sc/source/filter/xml/xmlnexpi.cxx
@@ -39,20 +39,58 @@
 #include "global.hxx"
 #include "document.hxx"
 #include "XMLConverter.hxx"
+#include "rangeutl.hxx"
 
 #include <xmloff/xmltkmap.hxx>
 #include <xmloff/nmspmap.hxx>
 
+#include <boost/scoped_ptr.hpp>
+
 using namespace com::sun::star;
 
 //------------------------------------------------------------------
 
-ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext( ScXMLImport& rImport,
-                                      USHORT nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
-    SvXMLImportContext( rImport, nPrfx, rLName )
+ScXMLNamedExpressionsContext::GlobalInserter::GlobalInserter(ScXMLImport& rImport) : mrImport(rImport) {}
+
+void ScXMLNamedExpressionsContext::GlobalInserter::insert(ScMyNamedExpression* pExp)
+{
+    if (pExp)
+        mrImport.AddNamedExpression(pExp);
+}
+
+ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(
+    ScDocument* pDoc, ScRangeName& rRangeName) : mpDoc(pDoc), mrRangeName(rRangeName) {}
+
+void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpression* pExp)
+{
+    using namespace formula;
+
+    ::boost::scoped_ptr<ScMyNamedExpression> p(pExp);
+
+    if (mpDoc && !mrRangeName.findByName(p->sName))
+    {
+        // Insert a new name.
+        ScAddress aPos;
+        sal_Int32 nOffset = 0;
+        bool bSuccess = ScRangeStringConverter::GetAddressFromString(
+            aPos, p->sBaseCellAddress, mpDoc, FormulaGrammar::CONV_OOO, nOffset);
+
+        if (bSuccess)
+        {
+            ScRangeData* pData = new ScRangeData(
+                mpDoc, p->sName, p->sContent, aPos, RT_NAME, p->eGrammar);
+            pData->SetIndex(-1);
+            mrRangeName.insert(pData);
+        }
+    }
+}
+
+ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext(
+    ScXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+    const uno::Reference<xml::sax::XAttributeList>& /* xAttrList */,
+    Inserter* pInserter ) :
+    SvXMLImportContext( rImport, nPrfx, rLName ),
+    mpInserter(pInserter)
 {
     rImport.LockSolarMutex();
 }
@@ -73,16 +111,12 @@ SvXMLImportContext *ScXMLNamedExpressionsContext::CreateChildContext( USHORT nPr
     switch( rTokenMap.Get( nPrefix, rLName ) )
     {
     case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE:
-        pContext = new ScXMLNamedRangeContext( GetScImport(), nPrefix,
-                                                      rLName, xAttrList//,
-                                                      //this
-                                                      );
+        pContext = new ScXMLNamedRangeContext(
+            GetScImport(), nPrefix, rLName, xAttrList, mpInserter.get() );
         break;
     case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION:
-        pContext = new ScXMLNamedExpressionContext( GetScImport(), nPrefix,
-                                                      rLName, xAttrList//,
-                                                      //this
-                                                      );
+        pContext = new ScXMLNamedExpressionContext(
+            GetScImport(), nPrefix, rLName, xAttrList, mpInserter.get() );
         break;
     }
 
@@ -98,13 +132,18 @@ void ScXMLNamedExpressionsContext::EndElement()
     // because it has to be set after the Database Ranges
 }
 
-ScXMLNamedRangeContext::ScXMLNamedRangeContext( ScXMLImport& rImport,
-                                      USHORT nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
-    SvXMLImportContext( rImport, nPrfx, rLName )
+ScXMLNamedRangeContext::ScXMLNamedRangeContext(
+    ScXMLImport& rImport,
+    USHORT nPrfx,
+    const ::rtl::OUString& rLName,
+    const uno::Reference<xml::sax::XAttributeList>& xAttrList,
+    ScXMLNamedExpressionsContext::Inserter* pInserter ) :
+    SvXMLImportContext( rImport, nPrfx, rLName ),
+    mpInserter(pInserter)
 {
+    if (!mpInserter)
+        return;
+
     ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
     // A simple table:cell-range-address is not a formula expression, stored
     // without [] brackets but with dot, .A1
@@ -146,7 +185,7 @@ ScXMLNamedRangeContext::ScXMLNamedRangeContext( ScXMLImport& rImport,
         }
     }
     pNamedExpression->bIsExpression = sal_False;
-    GetScImport().AddNamedExpression(pNamedExpression);
+    mpInserter->insert(pNamedExpression);
 }
 
 ScXMLNamedRangeContext::~ScXMLNamedRangeContext()
@@ -165,13 +204,16 @@ void ScXMLNamedRangeContext::EndElement()
 {
 }
 
-ScXMLNamedExpressionContext::ScXMLNamedExpressionContext( ScXMLImport& rImport,
-                                      USHORT nPrfx,
-                                      const ::rtl::OUString& rLName,
-                                      const ::com::sun::star::uno::Reference<
-                                      ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
-    SvXMLImportContext( rImport, nPrfx, rLName )
+ScXMLNamedExpressionContext::ScXMLNamedExpressionContext(
+    ScXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+    const uno::Reference<xml::sax::XAttributeList>& xAttrList,
+    ScXMLNamedExpressionsContext::Inserter* pInserter ) :
+    SvXMLImportContext( rImport, nPrfx, rLName ),
+    mpInserter(pInserter)
 {
+    if (!mpInserter)
+        return;
+
     ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
@@ -205,7 +247,7 @@ ScXMLNamedExpressionContext::ScXMLNamedExpressionContext( ScXMLImport& rImport,
         }
     }
     pNamedExpression->bIsExpression = sal_True;
-    GetScImport().AddNamedExpression(pNamedExpression);
+    mpInserter->insert(pNamedExpression);
 }
 
 ScXMLNamedExpressionContext::~ScXMLNamedExpressionContext()
diff --git a/sc/source/filter/xml/xmlnexpi.hxx b/sc/source/filter/xml/xmlnexpi.hxx
index 2d6bc01..e024e47 100644
--- a/sc/source/filter/xml/xmlnexpi.hxx
+++ b/sc/source/filter/xml/xmlnexpi.hxx
@@ -31,7 +31,12 @@
 #include <xmloff/xmlictxt.hxx>
 #include <xmloff/xmlimp.hxx>
 
+#include <boost/shared_ptr.hpp>
+
 class ScXMLImport;
+struct ScMyNamedExpression;
+class ScRangeName;
+class ScDocument;
 
 class ScXMLNamedExpressionsContext : public SvXMLImportContext
 {
@@ -40,10 +45,45 @@ class ScXMLNamedExpressionsContext : public SvXMLImportContext
 
 public:
 
-    ScXMLNamedExpressionsContext( ScXMLImport& rImport, USHORT nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    class Inserter
+    {
+    public:
+        virtual void insert(ScMyNamedExpression* pExp) = 0;
+    };
+
+    /**
+     * Global named expressions are inserted into ScXMLImport, which does the
+     * bulk insertion at the end of the import.
+     */
+    class GlobalInserter : public Inserter
+    {
+    public:
+        GlobalInserter(ScXMLImport& rImport);
+        virtual void insert(ScMyNamedExpression* pExp);
+    private:
+        ScXMLImport& mrImport;
+    };
+
+    /**
+     * Sheet local named expressions are inserted directly into ScRangeName
+     * instance of that sheet.  TODO: the global ones should be inserted the
+     * same way for efficiency.
+     */
+    class SheetLocalInserter : public Inserter
+    {
+    public:
+        SheetLocalInserter(ScDocument* pDoc, ScRangeName& rRangeName);
+        virtual void insert(ScMyNamedExpression* pExp);
+    private:
+        ScDocument* mpDoc;
+        ScRangeName& mrRangeName;
+    };
+
+    ScXMLNamedExpressionsContext(
+        ScXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+        const ::com::sun::star::uno::Reference<
+            ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
+        Inserter* pInserter );
 
     virtual ~ScXMLNamedExpressionsContext();
 
@@ -53,6 +93,9 @@ public:
                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
 
     virtual void EndElement();
+
+private:
+    ::boost::shared_ptr<Inserter> mpInserter;
 };
 
 class ScXMLNamedRangeContext : public SvXMLImportContext
@@ -62,10 +105,11 @@ class ScXMLNamedRangeContext : public SvXMLImportContext
 
 public:
 
-    ScXMLNamedRangeContext( ScXMLImport& rImport, USHORT nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    ScXMLNamedRangeContext(
+        ScXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+        const ::com::sun::star::uno::Reference<
+            ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
+        ScXMLNamedExpressionsContext::Inserter* pInserter );
 
     virtual ~ScXMLNamedRangeContext();
 
@@ -75,6 +119,9 @@ public:
                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
 
     virtual void EndElement();
+
+private:
+    ScXMLNamedExpressionsContext::Inserter* mpInserter;
 };
 
 class ScXMLNamedExpressionContext : public SvXMLImportContext
@@ -84,10 +131,11 @@ class ScXMLNamedExpressionContext : public SvXMLImportContext
 
 public:
 
-    ScXMLNamedExpressionContext( ScXMLImport& rImport, USHORT nPrfx,
-                        const ::rtl::OUString& rLName,
-                        const ::com::sun::star::uno::Reference<
-                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    ScXMLNamedExpressionContext(
+        ScXMLImport& rImport, USHORT nPrfx, const ::rtl::OUString& rLName,
+        const ::com::sun::star::uno::Reference<
+            ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
+        ScXMLNamedExpressionsContext::Inserter* pInserter );
 
     virtual ~ScXMLNamedExpressionContext();
 
@@ -97,6 +145,9 @@ public:
                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
 
     virtual void EndElement();
+
+private:
+    ScXMLNamedExpressionsContext::Inserter* mpInserter;
 };
 
 #endif
diff --git a/sc/source/filter/xml/xmltabi.cxx b/sc/source/filter/xml/xmltabi.cxx
index 8e97e8a..e2942cc 100644
--- a/sc/source/filter/xml/xmltabi.cxx
+++ b/sc/source/filter/xml/xmltabi.cxx
@@ -39,6 +39,7 @@
 #include "xmlcoli.hxx"
 #include "xmlsceni.hxx"
 #include "xmlexternaltabi.hxx"
+#include "xmlnexpi.hxx"
 #include "document.hxx"
 #include "docuno.hxx"
 #include "olinetab.hxx"
@@ -279,6 +280,22 @@ SvXMLImportContext *ScXMLTableContext::CreateChildContext( USHORT nPrefix,
 
     switch (nToken)
     {
+    case XML_TOK_TABLE_NAMED_EXPRESSIONS:
+    {
+        ScDocument* pDoc = GetScImport().GetDocument();
+        if (pDoc)
+        {
+            sal_Int32 nTab = GetScImport().GetTables().GetCurrentSheet();
+            ScRangeName* pRN = pDoc->GetRangeName(static_cast<SCTAB>(nTab));
+            if (pRN)
+            {
+                pContext = new ScXMLNamedExpressionsContext( 
+                    GetScImport(), nPrefix, rLName, xAttrList,
+                    new ScXMLNamedExpressionsContext::SheetLocalInserter(pDoc, *pRN));
+            }
+        }
+    }
+        break;
     case XML_TOK_TABLE_COL_GROUP:
         pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
                                                    rLName, xAttrList,
commit 74c019898e5d7e0d57eac3616eaa3a5bf9211997
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Mar 10 01:01:44 2011 -0500

    Export sheet-local range names to ODS.

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index cf4ed99..bb530eb 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -329,6 +329,8 @@ public:
                   const ::com::sun::star::uno::Sequence<
                     const ::com::sun::star::sheet::ExternalLinkInfo > * pExternalLinks = NULL );
 
+    SC_DLLPUBLIC void Format( rtl::OUString&, USHORT = 0, ScDocument* = NULL,
+                 const Details& rDetails = detailsOOOa1) const;
     SC_DLLPUBLIC void Format( String&, USHORT = 0, ScDocument* = NULL,
                  const Details& rDetails = detailsOOOa1) const;
 
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 1d6ecf9..cc0a92a 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -1627,6 +1627,14 @@ getFileNameFromDoc( const ScDocument* pDoc )
     return sFileName;
 }
 
+void ScAddress::Format( OUString& r, USHORT nFlags, ScDocument* pDoc,
+                        const Details& rDetails) const
+{
+    String aStr;
+    Format(aStr, nFlags, pDoc, rDetails);
+    r = aStr;
+}
+
 void ScAddress::Format( String& r, USHORT nFlags, ScDocument* pDoc,
                         const Details& rDetails) const
 {
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 9974abb..1089e1b 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2828,6 +2828,36 @@ void ScXMLExport::WriteTable(sal_Int32 nTable, const Reference<sheet::XSpreadshe
 
     CloseRow(pSharedData->GetLastRow(nTable));
     nEqualCells = 0;
+
+    if (pDoc)
+    {
+        // Export sheet-local named ranges.
+        ScRangeName* pRN = pDoc->GetRangeName(nTable);
+        if (pRN && !pRN->empty())
+        {
+            SvXMLElementExport aElemNEs(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSIONS, sal_True, sal_True);
+            ScRangeName::const_iterator itr = pRN->begin(), itrEnd = pRN->end();
+            for (; itr != itrEnd; ++itr)
+            {
+                CheckAttrList();
+
+                // name
+                OUString aStr = itr->GetName();
+                AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, aStr);
+
+                // base cell
+                ScAddress aPos = itr->GetPos();
+                aPos.Format(aStr, SCA_ABS_3D, pDoc, FormulaGrammar::CONV_OOO);
+                AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, aStr);
+
+                // expression
+                itr->GetSymbol(aStr, pDoc->GetStorageGrammar());
+                AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, aStr);
+
+                SvXMLElementExport aElemNR(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, sal_True, sal_True);
+            }
+        }
+    }
 }
 
 void ScXMLExport::WriteCell (ScMyCell& aCell)
commit 216523ec3bec47fe8fb1eeee952d7ec1c07dea01
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 23:26:18 2011 -0500

    Reduced indent levels again.

diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index b2cb556..9974abb 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2654,179 +2654,180 @@ sal_Bool ScXMLExport::GetCellText (ScMyCell& rMyCell, const ScAddress& aPos) con
 
 void ScXMLExport::WriteTable(sal_Int32 nTable, const Reference<sheet::XSpreadsheet>& xTable)
 {
-    if (xTable.is())
+    if (!xTable.is())
+        return;
+
+    xCurrentTable.set(xTable);
+    xCurrentTableCellRange.set(xTable, uno::UNO_QUERY);
+    uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
+    if (!xName.is())
+        return;
+
+    nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
+    rtl::OUString sOUTableName(xName->getName());
+    AddAttribute(sAttrName, sOUTableName);
+    AddAttribute(sAttrStyleName, aTableStyles[nTable]);
+
+    uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
+    ScTableProtection* pProtect = NULL;
+    if (xProtectable.is() && xProtectable->isProtected())
     {
-        xCurrentTable.set(xTable);
-        xCurrentTableCellRange.set(xTable, uno::UNO_QUERY);
-        uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
-        if ( xName.is() )
+        AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
+        if (pDoc)
         {
-            nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
-            rtl::OUString sOUTableName(xName->getName());
-            AddAttribute(sAttrName, sOUTableName);
-            AddAttribute(sAttrStyleName, aTableStyles[nTable]);
-
-            uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
-            ScTableProtection* pProtect = NULL;
-            if (xProtectable.is() && xProtectable->isProtected())
+            pProtect = pDoc->GetTabProtection(nTable);
+            if (pProtect)
             {
-                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
-                if (pDoc)
+                rtl::OUStringBuffer aBuffer;
+                ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
+                if (pProtect->hasPasswordHash(PASSHASH_SHA1))
+                {
+                    SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_SHA1));
+                    eHashUsed = PASSHASH_SHA1;
+                }
+                else if (pProtect->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
                 {
-                    pProtect = pDoc->GetTabProtection(nTable);
-                    if (pProtect)
+                    // Double-hash this by SHA1 on top of the legacy xls hash.
+                    uno::Sequence<sal_Int8> aHash = pProtect->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
+                    SvXMLUnitConverter::encodeBase64(aBuffer, aHash);
+                    eHashUsed = PASSHASH_XL;
+                }
+                if (aBuffer.getLength())
+                {
+                    AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
+                    if (eHashUsed == PASSHASH_XL)
                     {
-                        rtl::OUStringBuffer aBuffer;
-                        ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
-                        if (pProtect->hasPasswordHash(PASSHASH_SHA1))
-                        {
-                            SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_SHA1));
-                            eHashUsed = PASSHASH_SHA1;
-                        }
-                        else if (pProtect->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
-                        {
-                            // Double-hash this by SHA1 on top of the legacy xls hash.
-                            uno::Sequence<sal_Int8> aHash = pProtect->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
-                            SvXMLUnitConverter::encodeBase64(aBuffer, aHash);
-                            eHashUsed = PASSHASH_XL;
-                        }
-                        if (aBuffer.getLength())
-                        {
-                            AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
-                            if (eHashUsed == PASSHASH_XL)
-                            {
-                                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
-                                             ScPassHashHelper::getHashURI(PASSHASH_XL));
-                                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
-                                             ScPassHashHelper::getHashURI(PASSHASH_SHA1));
-                            }
-                            else if (eHashUsed == PASSHASH_SHA1)
-                                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
-                                             ScPassHashHelper::getHashURI(PASSHASH_SHA1));
-                        }
+                        AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
+                                     ScPassHashHelper::getHashURI(PASSHASH_XL));
+                        AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
+                                     ScPassHashHelper::getHashURI(PASSHASH_SHA1));
                     }
+                    else if (eHashUsed == PASSHASH_SHA1)
+                        AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
+                                     ScPassHashHelper::getHashURI(PASSHASH_SHA1));
                 }
             }
-            rtl::OUString sPrintRanges;
-            table::CellRangeAddress aColumnHeaderRange;
-            sal_Bool bHasColumnHeader;
-            GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
-            if( sPrintRanges.getLength() )
-                AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT_RANGES, sPrintRanges );
-            else if (!pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
-                AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT, XML_FALSE);
-            SvXMLElementExport aElemT(*this, sElemTab, sal_True, sal_True);
-
-            if (pProtect && pProtect->isProtected())
-            {
-                if (pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS))
-                    AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_PROTECTED_CELLS, XML_TRUE);
-                if (pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS))
-                    AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_UNPROTECTED_CELLS, XML_TRUE);
+        }
+    }
+    rtl::OUString sPrintRanges;
+    table::CellRangeAddress aColumnHeaderRange;
+    sal_Bool bHasColumnHeader;
+    GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
+    if( sPrintRanges.getLength() )
+        AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT_RANGES, sPrintRanges );
+    else if (!pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
+        AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT, XML_FALSE);
+    SvXMLElementExport aElemT(*this, sElemTab, sal_True, sal_True);
+
+    if (pProtect && pProtect->isProtected())
+    {
+        if (pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS))
+            AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_PROTECTED_CELLS, XML_TRUE);
+        if (pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS))
+            AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_UNPROTECTED_CELLS, XML_TRUE);
 
-                rtl::OUString aElemName = GetNamespaceMap().GetQNameByKey(
-                    XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_PROTECTION));
+        rtl::OUString aElemName = GetNamespaceMap().GetQNameByKey(
+            XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_PROTECTION));
 
-                SvXMLElementExport aElemProtected(*this, aElemName, true, true);
-            }
+        SvXMLElementExport aElemProtected(*this, aElemName, true, true);
+    }
 
-            CheckAttrList();
+    CheckAttrList();
 
-            if ( pDoc && pDoc->GetSheetEvents( static_cast<SCTAB>(nTable) ) &&
-                 getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST )
-            {
-                // store sheet events
-                uno::Reference<document::XEventsSupplier> xSupplier(xTable, uno::UNO_QUERY);
-                uno::Reference<container::XNameAccess> xEvents(xSupplier->getEvents(), uno::UNO_QUERY);
-                GetEventExport().ExportExt( xEvents );
-            }
+    if ( pDoc && pDoc->GetSheetEvents( static_cast<SCTAB>(nTable) ) &&
+         getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST )
+    {
+        // store sheet events
+        uno::Reference<document::XEventsSupplier> xSupplier(xTable, uno::UNO_QUERY);
+        uno::Reference<container::XNameAccess> xEvents(xSupplier->getEvents(), uno::UNO_QUERY);
+        GetEventExport().ExportExt( xEvents );
+    }
 
-            WriteTableSource();
-            WriteScenario();
-            uno::Reference<drawing::XDrawPage> xDrawPage;
-            if (pSharedData->HasForm(nTable, xDrawPage) && xDrawPage.is())
-            {
-                ::xmloff::OOfficeFormsExport aForms(*this);
-                GetFormExport()->exportForms( xDrawPage );
-                sal_Bool bRet(GetFormExport()->seekPage( xDrawPage ));
-                DBG_ASSERT( bRet, "OFormLayerXMLExport::seekPage failed!" );
-                (void)bRet;     // avoid warning in product version
-            }
-            if (pSharedData->HasDrawPage())
-            {
-                GetShapeExport()->seekShapes(uno::Reference<drawing::XShapes>(pSharedData->GetDrawPage(nTable), uno::UNO_QUERY));
-                WriteTableShapes();
-            }
-            table::CellRangeAddress aRange(GetEndAddress(xTable, nTable));
-            pSharedData->SetLastColumn(nTable, aRange.EndColumn);
-            pSharedData->SetLastRow(nTable, aRange.EndRow);
-            pCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
-            pGroupColumns->NewTable();
-            pGroupRows->NewTable();
-            FillColumnRowGroups();
-            if (bHasColumnHeader)
-                pSharedData->SetLastColumn(nTable, aColumnHeaderRange.EndColumn);
-            bRowHeaderOpen = sal_False;
-            if (bHasRowHeader)
-                pSharedData->SetLastRow(nTable, aRowHeaderRange.EndRow);
-            pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
-                pSharedData->GetLastColumn(nTable), pCellStyles, pDoc);
-            pRowFormatRanges->SetRowDefaults(pDefaults->GetRowDefaults());
-            pRowFormatRanges->SetColDefaults(pDefaults->GetColDefaults());
-            pCellStyles->SetRowDefaults(pDefaults->GetRowDefaults());
-            pCellStyles->SetColDefaults(pDefaults->GetColDefaults());
-            ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
-            sal_Bool bIsFirst(sal_True);
-            sal_Int32 nEqualCells(0);
-            ScMyCell aCell;
-            ScMyCell aPrevCell;
-            while(pCellsItr->GetNext(aCell, pCellStyles))
+    WriteTableSource();
+    WriteScenario();
+    uno::Reference<drawing::XDrawPage> xDrawPage;
+    if (pSharedData->HasForm(nTable, xDrawPage) && xDrawPage.is())
+    {
+        ::xmloff::OOfficeFormsExport aForms(*this);
+        GetFormExport()->exportForms( xDrawPage );
+        sal_Bool bRet(GetFormExport()->seekPage( xDrawPage ));
+        DBG_ASSERT( bRet, "OFormLayerXMLExport::seekPage failed!" );
+        (void)bRet;     // avoid warning in product version
+    }
+    if (pSharedData->HasDrawPage())
+    {
+        GetShapeExport()->seekShapes(uno::Reference<drawing::XShapes>(pSharedData->GetDrawPage(nTable), uno::UNO_QUERY));
+        WriteTableShapes();
+    }
+    table::CellRangeAddress aRange(GetEndAddress(xTable, nTable));
+    pSharedData->SetLastColumn(nTable, aRange.EndColumn);
+    pSharedData->SetLastRow(nTable, aRange.EndRow);
+    pCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
+    pGroupColumns->NewTable();
+    pGroupRows->NewTable();
+    FillColumnRowGroups();
+    if (bHasColumnHeader)
+        pSharedData->SetLastColumn(nTable, aColumnHeaderRange.EndColumn);
+    bRowHeaderOpen = sal_False;
+    if (bHasRowHeader)
+        pSharedData->SetLastRow(nTable, aRowHeaderRange.EndRow);
+    pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
+        pSharedData->GetLastColumn(nTable), pCellStyles, pDoc);
+    pRowFormatRanges->SetRowDefaults(pDefaults->GetRowDefaults());
+    pRowFormatRanges->SetColDefaults(pDefaults->GetColDefaults());
+    pCellStyles->SetRowDefaults(pDefaults->GetRowDefaults());
+    pCellStyles->SetColDefaults(pDefaults->GetColDefaults());
+    ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
+    sal_Bool bIsFirst(sal_True);
+    sal_Int32 nEqualCells(0);
+    ScMyCell aCell;
+    ScMyCell aPrevCell;
+    while(pCellsItr->GetNext(aCell, pCellStyles))
+    {
+        if (bIsFirst)
+        {
+            ExportFormatRanges(0, 0, aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
+            aPrevCell = aCell;
+            bIsFirst = sal_False;
+        }
+        else
+        {
+            if ((aPrevCell.aCellAddress.Row == aCell.aCellAddress.Row) &&
+                (aPrevCell.aCellAddress.Column + nEqualCells + 1 == aCell.aCellAddress.Column))
             {
-                if (bIsFirst)
-                {
-                    ExportFormatRanges(0, 0, aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
-                    aPrevCell = aCell;
-                    bIsFirst = sal_False;
-                }
+                if(IsCellEqual(aPrevCell, aCell))
+                    ++nEqualCells;
                 else
                 {
-                    if ((aPrevCell.aCellAddress.Row == aCell.aCellAddress.Row) &&
-                        (aPrevCell.aCellAddress.Column + nEqualCells + 1 == aCell.aCellAddress.Column))
-                    {
-                        if(IsCellEqual(aPrevCell, aCell))
-                            ++nEqualCells;
-                        else
-                        {
-                            SetRepeatAttribute(nEqualCells);
-                            WriteCell(aPrevCell);
-                            nEqualCells = 0;
-                            aPrevCell = aCell;
-                        }
-                    }
-                    else
-                    {
-                        SetRepeatAttribute(nEqualCells);
-                        WriteCell(aPrevCell);
-                        ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
-                            aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
-                        nEqualCells = 0;
-                        aPrevCell = aCell;
-                    }
+                    SetRepeatAttribute(nEqualCells);
+                    WriteCell(aPrevCell);
+                    nEqualCells = 0;
+                    aPrevCell = aCell;
                 }
             }
-            if (!bIsFirst)
+            else
             {
                 SetRepeatAttribute(nEqualCells);
                 WriteCell(aPrevCell);
                 ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
-                    pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
+                    aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
+                nEqualCells = 0;
+                aPrevCell = aCell;
             }
-            else
-                ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
-            CloseRow(pSharedData->GetLastRow(nTable));
-            nEqualCells = 0;
         }
     }
+    if (!bIsFirst)
+    {
+        SetRepeatAttribute(nEqualCells);
+        WriteCell(aPrevCell);
+        ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
+            pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
+    }
+    else
+        ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
+
+    CloseRow(pSharedData->GetLastRow(nTable));
+    nEqualCells = 0;
 }
 
 void ScXMLExport::WriteCell (ScMyCell& aCell)
commit 139c00d5634cb1caf1e2cef5d8c463064f12afa0
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 23:24:35 2011 -0500

    Extracted a method from a giant, mega method.

diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index b2d32cd..b2cb556 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -1722,179 +1722,7 @@ void ScXMLExport::_ExportContent()
             else
             {
                 uno::Reference<sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
-                if (xTable.is())
-                {
-                    xCurrentTable.set(xTable);
-                    xCurrentTableCellRange.set(xTable, uno::UNO_QUERY);
-                    uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
-                    if ( xName.is() )
-                    {
-                        nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
-                        rtl::OUString sOUTableName(xName->getName());
-                        AddAttribute(sAttrName, sOUTableName);
-                        AddAttribute(sAttrStyleName, aTableStyles[nTable]);
-
-                        uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
-                        ScTableProtection* pProtect = NULL;
-                        if (xProtectable.is() && xProtectable->isProtected())
-                        {
-                            AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
-                            if (pDoc)
-                            {
-                                pProtect = pDoc->GetTabProtection(nTable);
-                                if (pProtect)
-                                {
-                                    rtl::OUStringBuffer aBuffer;
-                                    ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
-                                    if (pProtect->hasPasswordHash(PASSHASH_SHA1))
-                                    {
-                                        SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_SHA1));
-                                        eHashUsed = PASSHASH_SHA1;
-                                    }
-                                    else if (pProtect->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
-                                    {
-                                        // Double-hash this by SHA1 on top of the legacy xls hash.
-                                        uno::Sequence<sal_Int8> aHash = pProtect->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
-                                        SvXMLUnitConverter::encodeBase64(aBuffer, aHash);
-                                        eHashUsed = PASSHASH_XL;
-                                    }
-                                    if (aBuffer.getLength())
-                                    {
-                                        AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
-                                        if (eHashUsed == PASSHASH_XL)
-                                        {
-                                            AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
-                                                         ScPassHashHelper::getHashURI(PASSHASH_XL));
-                                            AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
-                                                         ScPassHashHelper::getHashURI(PASSHASH_SHA1));
-                                        }
-                                        else if (eHashUsed == PASSHASH_SHA1)
-                                            AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
-                                                         ScPassHashHelper::getHashURI(PASSHASH_SHA1));
-                                    }
-                                }
-                            }
-                        }
-                        rtl::OUString sPrintRanges;
-                        table::CellRangeAddress aColumnHeaderRange;
-                        sal_Bool bHasColumnHeader;
-                        GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
-                        if( sPrintRanges.getLength() )
-                            AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT_RANGES, sPrintRanges );
-                        else if (!pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
-                            AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT, XML_FALSE);
-                        SvXMLElementExport aElemT(*this, sElemTab, sal_True, sal_True);
-
-                        if (pProtect && pProtect->isProtected())
-                        {
-                            if (pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS))
-                                AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_PROTECTED_CELLS, XML_TRUE);
-                            if (pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS))
-                                AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_UNPROTECTED_CELLS, XML_TRUE);
-
-                            rtl::OUString aElemName = GetNamespaceMap().GetQNameByKey(
-                                XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_PROTECTION));
-
-                            SvXMLElementExport aElemProtected(*this, aElemName, true, true);
-                        }
-
-                        CheckAttrList();
-
-                        if ( pDoc && pDoc->GetSheetEvents( static_cast<SCTAB>(nTable) ) &&
-                             getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST )
-                        {
-                            // store sheet events
-                            uno::Reference<document::XEventsSupplier> xSupplier(xTable, uno::UNO_QUERY);
-                            uno::Reference<container::XNameAccess> xEvents(xSupplier->getEvents(), uno::UNO_QUERY);
-                            GetEventExport().ExportExt( xEvents );
-                        }
-
-                        WriteTableSource();
-                        WriteScenario();
-                        uno::Reference<drawing::XDrawPage> xDrawPage;
-                        if (pSharedData->HasForm(nTable, xDrawPage) && xDrawPage.is())
-                        {
-                            ::xmloff::OOfficeFormsExport aForms(*this);
-                            GetFormExport()->exportForms( xDrawPage );
-                            sal_Bool bRet(GetFormExport()->seekPage( xDrawPage ));
-                            DBG_ASSERT( bRet, "OFormLayerXMLExport::seekPage failed!" );
-                            (void)bRet;     // avoid warning in product version
-                        }
-                        if (pSharedData->HasDrawPage())
-                        {
-                            GetShapeExport()->seekShapes(uno::Reference<drawing::XShapes>(pSharedData->GetDrawPage(nTable), uno::UNO_QUERY));
-                            WriteTableShapes();
-                        }
-                        table::CellRangeAddress aRange(GetEndAddress(xTable, nTable));
-                        pSharedData->SetLastColumn(nTable, aRange.EndColumn);
-                        pSharedData->SetLastRow(nTable, aRange.EndRow);
-                        pCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
-                        pGroupColumns->NewTable();
-                        pGroupRows->NewTable();
-                        FillColumnRowGroups();
-                        if (bHasColumnHeader)
-                            pSharedData->SetLastColumn(nTable, aColumnHeaderRange.EndColumn);
-                        bRowHeaderOpen = sal_False;
-                        if (bHasRowHeader)
-                            pSharedData->SetLastRow(nTable, aRowHeaderRange.EndRow);
-                        pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
-                            pSharedData->GetLastColumn(nTable), pCellStyles, pDoc);
-                        pRowFormatRanges->SetRowDefaults(pDefaults->GetRowDefaults());
-                        pRowFormatRanges->SetColDefaults(pDefaults->GetColDefaults());
-                        pCellStyles->SetRowDefaults(pDefaults->GetRowDefaults());
-                        pCellStyles->SetColDefaults(pDefaults->GetColDefaults());
-                        ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
-                        sal_Bool bIsFirst(sal_True);
-                        sal_Int32 nEqualCells(0);
-                        ScMyCell aCell;
-                        ScMyCell aPrevCell;
-                        while(pCellsItr->GetNext(aCell, pCellStyles))
-                        {
-                            if (bIsFirst)
-                            {
-                                ExportFormatRanges(0, 0, aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
-                                aPrevCell = aCell;
-                                bIsFirst = sal_False;
-                            }
-                            else
-                            {
-                                if ((aPrevCell.aCellAddress.Row == aCell.aCellAddress.Row) &&
-                                    (aPrevCell.aCellAddress.Column + nEqualCells + 1 == aCell.aCellAddress.Column))
-                                {
-                                    if(IsCellEqual(aPrevCell, aCell))
-                                        ++nEqualCells;
-                                    else
-                                    {
-                                        SetRepeatAttribute(nEqualCells);
-                                        WriteCell(aPrevCell);
-                                        nEqualCells = 0;
-                                        aPrevCell = aCell;
-                                    }
-                                }
-                                else
-                                {
-                                    SetRepeatAttribute(nEqualCells);
-                                    WriteCell(aPrevCell);
-                                    ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
-                                        aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
-                                    nEqualCells = 0;
-                                    aPrevCell = aCell;
-                                }
-                            }
-                        }
-                        if (!bIsFirst)
-                        {
-                            SetRepeatAttribute(nEqualCells);
-                            WriteCell(aPrevCell);
-                            ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
-                                pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
-                        }
-                        else
-                            ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
-                        CloseRow(pSharedData->GetLastRow(nTable));
-                        nEqualCells = 0;
-                    }
-                }
+                WriteTable(nTable, xTable);
             }
             IncrementProgressBar(sal_False);
         }
@@ -2824,6 +2652,183 @@ sal_Bool ScXMLExport::GetCellText (ScMyCell& rMyCell, const ScAddress& aPos) con
     }
 }
 
+void ScXMLExport::WriteTable(sal_Int32 nTable, const Reference<sheet::XSpreadsheet>& xTable)
+{
+    if (xTable.is())
+    {
+        xCurrentTable.set(xTable);
+        xCurrentTableCellRange.set(xTable, uno::UNO_QUERY);
+        uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
+        if ( xName.is() )
+        {
+            nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
+            rtl::OUString sOUTableName(xName->getName());
+            AddAttribute(sAttrName, sOUTableName);
+            AddAttribute(sAttrStyleName, aTableStyles[nTable]);
+
+            uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
+            ScTableProtection* pProtect = NULL;
+            if (xProtectable.is() && xProtectable->isProtected())
+            {
+                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
+                if (pDoc)
+                {
+                    pProtect = pDoc->GetTabProtection(nTable);
+                    if (pProtect)
+                    {
+                        rtl::OUStringBuffer aBuffer;
+                        ScPasswordHash eHashUsed = PASSHASH_UNSPECIFIED;
+                        if (pProtect->hasPasswordHash(PASSHASH_SHA1))
+                        {
+                            SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_SHA1));
+                            eHashUsed = PASSHASH_SHA1;
+                        }
+                        else if (pProtect->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
+                        {
+                            // Double-hash this by SHA1 on top of the legacy xls hash.
+                            uno::Sequence<sal_Int8> aHash = pProtect->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
+                            SvXMLUnitConverter::encodeBase64(aBuffer, aHash);
+                            eHashUsed = PASSHASH_XL;
+                        }
+                        if (aBuffer.getLength())
+                        {
+                            AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
+                            if (eHashUsed == PASSHASH_XL)
+                            {
+                                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
+                                             ScPassHashHelper::getHashURI(PASSHASH_XL));
+                                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM_2,
+                                             ScPassHashHelper::getHashURI(PASSHASH_SHA1));
+                            }
+                            else if (eHashUsed == PASSHASH_SHA1)
+                                AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
+                                             ScPassHashHelper::getHashURI(PASSHASH_SHA1));
+                        }
+                    }
+                }
+            }
+            rtl::OUString sPrintRanges;
+            table::CellRangeAddress aColumnHeaderRange;
+            sal_Bool bHasColumnHeader;
+            GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
+            if( sPrintRanges.getLength() )
+                AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT_RANGES, sPrintRanges );
+            else if (!pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
+                AddAttribute( XML_NAMESPACE_TABLE, XML_PRINT, XML_FALSE);
+            SvXMLElementExport aElemT(*this, sElemTab, sal_True, sal_True);
+
+            if (pProtect && pProtect->isProtected())
+            {
+                if (pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS))
+                    AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_PROTECTED_CELLS, XML_TRUE);
+                if (pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS))
+                    AddAttribute(XML_NAMESPACE_TABLE, XML_SELECT_UNPROTECTED_CELLS, XML_TRUE);
+
+                rtl::OUString aElemName = GetNamespaceMap().GetQNameByKey(
+                    XML_NAMESPACE_TABLE, GetXMLToken(XML_TABLE_PROTECTION));
+
+                SvXMLElementExport aElemProtected(*this, aElemName, true, true);
+            }
+
+            CheckAttrList();
+
+            if ( pDoc && pDoc->GetSheetEvents( static_cast<SCTAB>(nTable) ) &&
+                 getDefaultVersion() == SvtSaveOptions::ODFVER_LATEST )
+            {
+                // store sheet events
+                uno::Reference<document::XEventsSupplier> xSupplier(xTable, uno::UNO_QUERY);
+                uno::Reference<container::XNameAccess> xEvents(xSupplier->getEvents(), uno::UNO_QUERY);
+                GetEventExport().ExportExt( xEvents );
+            }
+
+            WriteTableSource();
+            WriteScenario();
+            uno::Reference<drawing::XDrawPage> xDrawPage;
+            if (pSharedData->HasForm(nTable, xDrawPage) && xDrawPage.is())
+            {
+                ::xmloff::OOfficeFormsExport aForms(*this);
+                GetFormExport()->exportForms( xDrawPage );
+                sal_Bool bRet(GetFormExport()->seekPage( xDrawPage ));
+                DBG_ASSERT( bRet, "OFormLayerXMLExport::seekPage failed!" );
+                (void)bRet;     // avoid warning in product version
+            }
+            if (pSharedData->HasDrawPage())
+            {
+                GetShapeExport()->seekShapes(uno::Reference<drawing::XShapes>(pSharedData->GetDrawPage(nTable), uno::UNO_QUERY));
+                WriteTableShapes();
+            }
+            table::CellRangeAddress aRange(GetEndAddress(xTable, nTable));
+            pSharedData->SetLastColumn(nTable, aRange.EndColumn);
+            pSharedData->SetLastRow(nTable, aRange.EndRow);
+            pCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
+            pGroupColumns->NewTable();
+            pGroupRows->NewTable();
+            FillColumnRowGroups();
+            if (bHasColumnHeader)
+                pSharedData->SetLastColumn(nTable, aColumnHeaderRange.EndColumn);
+            bRowHeaderOpen = sal_False;
+            if (bHasRowHeader)
+                pSharedData->SetLastRow(nTable, aRowHeaderRange.EndRow);
+            pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
+                pSharedData->GetLastColumn(nTable), pCellStyles, pDoc);
+            pRowFormatRanges->SetRowDefaults(pDefaults->GetRowDefaults());
+            pRowFormatRanges->SetColDefaults(pDefaults->GetColDefaults());
+            pCellStyles->SetRowDefaults(pDefaults->GetRowDefaults());
+            pCellStyles->SetColDefaults(pDefaults->GetColDefaults());
+            ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
+            sal_Bool bIsFirst(sal_True);
+            sal_Int32 nEqualCells(0);
+            ScMyCell aCell;
+            ScMyCell aPrevCell;
+            while(pCellsItr->GetNext(aCell, pCellStyles))
+            {
+                if (bIsFirst)
+                {
+                    ExportFormatRanges(0, 0, aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
+                    aPrevCell = aCell;
+                    bIsFirst = sal_False;
+                }
+                else
+                {
+                    if ((aPrevCell.aCellAddress.Row == aCell.aCellAddress.Row) &&
+                        (aPrevCell.aCellAddress.Column + nEqualCells + 1 == aCell.aCellAddress.Column))
+                    {
+                        if(IsCellEqual(aPrevCell, aCell))
+                            ++nEqualCells;
+                        else
+                        {
+                            SetRepeatAttribute(nEqualCells);
+                            WriteCell(aPrevCell);
+                            nEqualCells = 0;
+                            aPrevCell = aCell;
+                        }
+                    }
+                    else
+                    {
+                        SetRepeatAttribute(nEqualCells);
+                        WriteCell(aPrevCell);
+                        ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
+                            aCell.aCellAddress.Column - 1, aCell.aCellAddress.Row, nTable);
+                        nEqualCells = 0;
+                        aPrevCell = aCell;
+                    }
+                }
+            }
+            if (!bIsFirst)
+            {
+                SetRepeatAttribute(nEqualCells);
+                WriteCell(aPrevCell);
+                ExportFormatRanges(aPrevCell.aCellAddress.Column + nEqualCells + 1, aPrevCell.aCellAddress.Row,
+                    pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
+            }
+            else
+                ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
+            CloseRow(pSharedData->GetLastRow(nTable));
+            nEqualCells = 0;
+        }
+    }
+}
+
 void ScXMLExport::WriteCell (ScMyCell& aCell)
 {
     ScAddress aCellPos;
diff --git a/sc/source/filter/xml/xmlexprt.hxx b/sc/source/filter/xml/xmlexprt.hxx
index 49bc92e..2fb3ac4 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -181,6 +181,7 @@ class ScXMLExport : public SvXMLExport
 
     sal_Bool GetCellText (ScMyCell& rMyCell, const ScAddress& aPos) const;
 
+    void WriteTable(sal_Int32 nTable, const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet>& xTable);
     void WriteCell (ScMyCell& aCell);
     void WriteAreaLink(const ScMyCell& rMyCell);
     void WriteAnnotation(ScMyCell& rMyCell);
commit 9160df2cf05fc2537e6ffe50f47ce4a17d79d2ab
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 23:16:06 2011 -0500

    Removed unnecessary static cast.

diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 9f3ef07..b2d32cd 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -1741,7 +1741,7 @@ void ScXMLExport::_ExportContent()
                             AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
                             if (pDoc)
                             {
-                                pProtect = pDoc->GetTabProtection(static_cast<SCTAB>(nTable));
+                                pProtect = pDoc->GetTabProtection(nTable);
                                 if (pProtect)
                                 {
                                     rtl::OUStringBuffer aBuffer;
commit e3b9b8fe998e011dc81c397e6916a45b9dceb6b4
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 23:01:50 2011 -0500

    Reduced indent levels by early bail outs.

diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 5a71055..9f3ef07 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3690,85 +3690,85 @@ void ScXMLExport::WriteLabelRanges( const uno::Reference< container::XIndexAcces
 void ScXMLExport::WriteNamedExpressions(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc)
 {
     uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
-    if (xPropertySet.is())
+    if (!xPropertySet.is())
+        return;
+
+    uno::Reference <sheet::XNamedRanges> xNamedRanges(xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_NAMEDRANGES))), uno::UNO_QUERY);
+    CheckAttrList();
+    if (!xNamedRanges.is())
+        return;
+
+    uno::Sequence <rtl::OUString> aRangesNames(xNamedRanges->getElementNames());
+    sal_Int32 nNamedRangesCount = aRangesNames.getLength();
+    if (nNamedRangesCount <= 0)
+        return;
+
+    if (!pDoc)
+        return;
+
+    ScRangeName* pNamedRanges = pDoc->GetRangeName();
+    SvXMLElementExport aElemNEs(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSIONS, sal_True, sal_True);
+    for (sal_Int32 i = 0; i < nNamedRangesCount; ++i)
     {
-        uno::Reference <sheet::XNamedRanges> xNamedRanges(xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_NAMEDRANGES))), uno::UNO_QUERY);
         CheckAttrList();
-        if (xNamedRanges.is())
+        rtl::OUString sNamedRange(aRangesNames[i]);
+        uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName(sNamedRange), uno::UNO_QUERY);
+        if (!xNamedRange.is())
+            continue;
+
+        uno::Reference <container::XNamed> xNamed (xNamedRange, uno::UNO_QUERY);
+        uno::Reference <sheet::XCellRangeReferrer> xCellRangeReferrer (xNamedRange, uno::UNO_QUERY);
+        if (!xNamed.is() || !xCellRangeReferrer.is())
+            continue;
+
+        rtl::OUString sOUName(xNamed->getName());
+        AddAttribute(sAttrName, sOUName);
+
+        OUString sOUBaseCellAddress;
+        ScRangeStringConverter::GetStringFromAddress( sOUBaseCellAddress,
+            xNamedRange->getReferencePosition(), pDoc, FormulaGrammar::CONV_OOO, ' ', sal_False, SCA_ABS_3D );
+        AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, sOUBaseCellAddress);
+
+        const ScRangeData* pNamedRange = pNamedRanges->findByName(sOUName);
+        String sContent;
+        pNamedRange->GetSymbol(sContent, pDoc->GetStorageGrammar());
+        rtl::OUString sOUTempContent(sContent);
+        uno::Reference <table::XCellRange> xCellRange(xCellRangeReferrer->getReferredCells());
+        if(xCellRange.is())
         {
-            uno::Sequence <rtl::OUString> aRangesNames(xNamedRanges->getElementNames());
-            sal_Int32 nNamedRangesCount(aRangesNames.getLength());
-            if (nNamedRangesCount > 0)
+            rtl::OUString sOUContent(sOUTempContent.copy(1, sOUTempContent.getLength() - 2));
+            AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sOUContent);
+            sal_Int32 nRangeType(xNamedRange->getType());
+            rtl::OUStringBuffer sBufferRangeType;
+            if ((nRangeType & sheet::NamedRangeFlag::COLUMN_HEADER) == sheet::NamedRangeFlag::COLUMN_HEADER)
+                sBufferRangeType.append(GetXMLToken(XML_REPEAT_COLUMN));
+            if ((nRangeType & sheet::NamedRangeFlag::ROW_HEADER) == sheet::NamedRangeFlag::ROW_HEADER)
             {
-                if (pDoc)
-                {
-                    ScRangeName* pNamedRanges(pDoc->GetRangeName());
-                    SvXMLElementExport aElemNEs(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSIONS, sal_True, sal_True);
-                    for (sal_Int32 i = 0; i < nNamedRangesCount; ++i)
-                    {
-                        CheckAttrList();
-                        rtl::OUString sNamedRange(aRangesNames[i]);
-                        uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName(sNamedRange), uno::UNO_QUERY);
-                        if (xNamedRange.is())
-                        {
-                            uno::Reference <container::XNamed> xNamed (xNamedRange, uno::UNO_QUERY);
-                            uno::Reference <sheet::XCellRangeReferrer> xCellRangeReferrer (xNamedRange, uno::UNO_QUERY);
-                            if (xNamed.is() && xCellRangeReferrer.is())
-                            {
-                                rtl::OUString sOUName(xNamed->getName());
-                                AddAttribute(sAttrName, sOUName);
-
-                                OUString sOUBaseCellAddress;
-                                ScRangeStringConverter::GetStringFromAddress( sOUBaseCellAddress,
-                                    xNamedRange->getReferencePosition(), pDoc, FormulaGrammar::CONV_OOO, ' ', sal_False, SCA_ABS_3D );
-                                AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, sOUBaseCellAddress);
-
-                                const ScRangeData* pNamedRange = pNamedRanges->findByName(sOUName);
-                                String sContent;
-                                pNamedRange->GetSymbol(sContent, pDoc->GetStorageGrammar());
-                                rtl::OUString sOUTempContent(sContent);
-                                uno::Reference <table::XCellRange> xCellRange(xCellRangeReferrer->getReferredCells());
-                                if(xCellRange.is())
-                                {
-                                    rtl::OUString sOUContent(sOUTempContent.copy(1, sOUTempContent.getLength() - 2));
-                                    AddAttribute(XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, sOUContent);
-                                    sal_Int32 nRangeType(xNamedRange->getType());
-                                    rtl::OUStringBuffer sBufferRangeType;
-                                    if ((nRangeType & sheet::NamedRangeFlag::COLUMN_HEADER) == sheet::NamedRangeFlag::COLUMN_HEADER)
-                                        sBufferRangeType.append(GetXMLToken(XML_REPEAT_COLUMN));
-                                    if ((nRangeType & sheet::NamedRangeFlag::ROW_HEADER) == sheet::NamedRangeFlag::ROW_HEADER)
-                                    {
-                                        if (sBufferRangeType.getLength() > 0)
-                                            sBufferRangeType.appendAscii(" ");
-                                        sBufferRangeType.append(GetXMLToken(XML_REPEAT_ROW));
-                                    }
-                                    if ((nRangeType & sheet::NamedRangeFlag::FILTER_CRITERIA) == sheet::NamedRangeFlag::FILTER_CRITERIA)
-                                    {
-                                        if (sBufferRangeType.getLength() > 0)
-                                            sBufferRangeType.appendAscii(" ");
-                                        sBufferRangeType.append(GetXMLToken(XML_FILTER));
-                                    }
-                                    if ((nRangeType & sheet::NamedRangeFlag::PRINT_AREA) == sheet::NamedRangeFlag::PRINT_AREA)
-                                    {
-                                        if (sBufferRangeType.getLength() > 0)
-                                            sBufferRangeType.appendAscii(" ");
-                                        sBufferRangeType.append(GetXMLToken(XML_PRINT_RANGE));
-                                    }
-                                    rtl::OUString sRangeType = sBufferRangeType.makeStringAndClear();
-                                    if (sRangeType.getLength())
-                                        AddAttribute(XML_NAMESPACE_TABLE, XML_RANGE_USABLE_AS, sRangeType);
-                                    SvXMLElementExport aElemNR(*this, XML_NAMESPACE_TABLE, XML_NAMED_RANGE, sal_True, sal_True);
-                                }
-                                else
-                                {
-                                    AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, sOUTempContent);
-                                    SvXMLElementExport aElemNE(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, sal_True, sal_True);
-                                }
-                            }
-                        }
-                    }
-                }
+                if (sBufferRangeType.getLength() > 0)
+                    sBufferRangeType.appendAscii(" ");
+                sBufferRangeType.append(GetXMLToken(XML_REPEAT_ROW));
+            }
+            if ((nRangeType & sheet::NamedRangeFlag::FILTER_CRITERIA) == sheet::NamedRangeFlag::FILTER_CRITERIA)
+            {
+                if (sBufferRangeType.getLength() > 0)
+                    sBufferRangeType.appendAscii(" ");
+                sBufferRangeType.append(GetXMLToken(XML_FILTER));
             }
+            if ((nRangeType & sheet::NamedRangeFlag::PRINT_AREA) == sheet::NamedRangeFlag::PRINT_AREA)
+            {
+                if (sBufferRangeType.getLength() > 0)
+                    sBufferRangeType.appendAscii(" ");
+                sBufferRangeType.append(GetXMLToken(XML_PRINT_RANGE));
+            }
+            rtl::OUString sRangeType = sBufferRangeType.makeStringAndClear();
+            if (sRangeType.getLength())
+                AddAttribute(XML_NAMESPACE_TABLE, XML_RANGE_USABLE_AS, sRangeType);
+            SvXMLElementExport aElemNR(*this, XML_NAMESPACE_TABLE, XML_NAMED_RANGE, sal_True, sal_True);
+        }
+        else
+        {
+            AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, sOUTempContent);
+            SvXMLElementExport aElemNE(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, sal_True, sal_True);
         }
     }
 }
commit d87fb6627dd95efa2b3a68395f7f83e89fad8d54
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 19:22:55 2011 -0500

    Consistent use of types to eliminate static casting.

diff --git a/sc/source/filter/excel/frmbase.cxx b/sc/source/filter/excel/frmbase.cxx
index 5ea061f..d30253d 100644
--- a/sc/source/filter/excel/frmbase.cxx
+++ b/sc/source/filter/excel/frmbase.cxx
@@ -40,7 +40,7 @@ _ScRangeListTabs::~_ScRangeListTabs()
 }
 
 
-void _ScRangeListTabs::Append( ScSingleRefData a, SCsTAB nTab, const BOOL b )
+void _ScRangeListTabs::Append( ScSingleRefData a, SCTAB nTab, bool b )
 {
     if( b )
     {
@@ -82,7 +82,7 @@ void _ScRangeListTabs::Append( ScSingleRefData a, SCsTAB nTab, const BOOL b )
     itr->second->push_back(ScRange(a.nCol,a.nRow,a.nTab));
 }
 
-void _ScRangeListTabs::Append( ScComplexRefData a, SCsTAB nTab, const BOOL b )
+void _ScRangeListTabs::Append( ScComplexRefData a, SCTAB nTab, bool b )
 {
     if( b )
     {
@@ -155,11 +155,11 @@ void _ScRangeListTabs::Append( ScComplexRefData a, SCsTAB nTab, const BOOL b )
                 a.Ref2.nCol,a.Ref2.nRow,a.Ref2.nTab));
 }
 
-const ScRange* _ScRangeListTabs::First( const UINT16 n )
+const ScRange* _ScRangeListTabs::First( SCTAB n )
 {
     DBG_ASSERT( ValidTab(n), "-_ScRangeListTabs::First(): Und tschuessssssss!" );
 
-    TabRangeType::iterator itr = maTabRanges.find(static_cast<SCsTAB>(n));
+    TabRangeType::iterator itr = maTabRanges.find(n);
     if (itr == maTabRanges.end())
         // No range list exists for this table.
         return NULL;
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index 5e23a5d..a2e9370 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -1259,12 +1259,9 @@ void ImportExcel::PostDocLoad( void )
     {
         for( SCTAB n = 0 ; n < nLast ; n++ )
         {
-            p = pExcRoot->pPrintRanges->First( static_cast<UINT16>(n) );
+            p = pExcRoot->pPrintRanges->First(n);
             if( p )
             {
-                DBG_ASSERT( pExcRoot->pPrintRanges->HasActList(),
-                            "-ImportExcel::PostDocLoad(): Imaginaere Tabelle gefunden!" );
-
                 pD->ClearPrintRanges( n );
                 while( p )
                 {
@@ -1285,12 +1282,9 @@ void ImportExcel::PostDocLoad( void )
     {
         for( SCTAB n = 0 ; n < nLast ; n++ )
         {
-            p = pExcRoot->pPrintTitles->First( static_cast<UINT16>(n) );
+            p = pExcRoot->pPrintTitles->First(n);
             if( p )
             {
-                DBG_ASSERT( pExcRoot->pPrintTitles->HasActList(),
-                    "-ImportExcel::PostDocLoad(): Imaginaere Tabelle gefunden!" );
-
                 BOOL	bRowVirgin = TRUE;
                 BOOL	bColVirgin = TRUE;
 
diff --git a/sc/source/filter/inc/formel.hxx b/sc/source/filter/inc/formel.hxx
index 4c9c009..9ae0e38 100644
--- a/sc/source/filter/inc/formel.hxx
+++ b/sc/source/filter/inc/formel.hxx
@@ -66,7 +66,7 @@ enum FORMULA_TYPE
 class _ScRangeListTabs
 {
     typedef ::std::vector<ScRange> RangeListType;
-    typedef ::boost::ptr_map<SCsTAB, RangeListType> TabRangeType;
+    typedef ::boost::ptr_map<SCTAB, RangeListType> TabRangeType;
     TabRangeType maTabRanges;
     RangeListType::const_iterator maItrCur;
     RangeListType::const_iterator maItrCurEnd;
@@ -75,10 +75,10 @@ public:
     _ScRangeListTabs ();
     ~_ScRangeListTabs();
 
-    void Append( ScSingleRefData aSRD, SCsTAB nTab, const BOOL bLimit = TRUE );
-    void Append( ScComplexRefData aCRD, SCsTAB nTab, const BOOL bLimit = TRUE );
+    void Append( ScSingleRefData aSRD, SCTAB nTab, bool bLimit = true );
+    void Append( ScComplexRefData aCRD, SCTAB nTab, bool bLimit = true );
 
-    const ScRange* First ( const UINT16 nTab = 0 );
+    const ScRange* First ( SCTAB nTab = 0 );
     const ScRange* Next ();
 
     bool HasRanges () const { return !maTabRanges.empty(); }
commit b89365b6fc9f5513c85033dc1bd6cd3a693a7015
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 19:15:00 2011 -0500

    Simplified _ScRangeListTabs and also fixed crashers on XLS import.
    
    Importing XLS documents with custom print ranges caused crash.

diff --git a/sc/source/filter/excel/frmbase.cxx b/sc/source/filter/excel/frmbase.cxx
index 0af659f..5ea061f 100644
--- a/sc/source/filter/excel/frmbase.cxx
+++ b/sc/source/filter/excel/frmbase.cxx
@@ -33,28 +33,10 @@
 
 _ScRangeListTabs::_ScRangeListTabs()
 {
-    ppTabLists = new _ScRangeList*[ MAXTAB + 1 ];
-
-    for( UINT16 n = 0 ; n <= MAXTAB ; n++ )
-        ppTabLists[ n ] = NULL;
-
-    bHasRanges = FALSE;
-    pAct = NULL;
-    nAct = 0;
 }
 
 _ScRangeListTabs::~_ScRangeListTabs()
 {
-    if( bHasRanges )
-    {
-        for( UINT16 n = 0 ; n <= MAXTAB ; n++ )
-        {
-            if( ppTabLists[ n ] )
-                delete ppTabLists[ n ];
-        }
-    }
-
-    delete[] ppTabLists;
 }
 
 
@@ -76,22 +58,28 @@ void _ScRangeListTabs::Append( ScSingleRefData a, SCsTAB nTab, const BOOL b )
         DBG_ASSERT( ValidTab(a.nTab), "-_ScRangeListTabs::Append(): Luegen haben kurze Abstuerze!" );
     }
 
-    bHasRanges = TRUE;
-
     if( nTab == SCTAB_MAX)
         return;
     if( nTab < 0)
         nTab = a.nTab;
 
-    if( nTab >= 0 && nTab <= MAXTAB)
+    if (nTab < 0 || MAXTAB < nTab)
+        return;
+
+    TabRangeType::iterator itr = maTabRanges.find(nTab);
+    if (itr == maTabRanges.end())
     {
-        _ScRangeList*   p = ppTabLists[ nTab ];
+        // No entry for this table yet.  Insert a new one.
+        std::pair<TabRangeType::iterator, bool> r =
+            maTabRanges.insert(nTab, new RangeListType);
 
-        if( !p )
-            p = ppTabLists[ nTab ] = new _ScRangeList;
+        if (!r.second)
+            // Insertion failed.
+            return;
 
-        p->push_back(new ScRange(a.nCol,a.nRow,a.nTab));
+        itr = r.first;
     }
+    itr->second->push_back(ScRange(a.nCol,a.nRow,a.nTab));
 }
 
 void _ScRangeListTabs::Append( ScComplexRefData a, SCsTAB nTab, const BOOL b )
@@ -140,52 +128,55 @@ void _ScRangeListTabs::Append( ScComplexRefData a, SCsTAB nTab, const BOOL b )
             "+_ScRangeListTabs::Append(): 3D-Ranges werden in SC nicht unterstuetzt!" );
     }
 
-    bHasRanges = TRUE;
-
     if( nTab == SCTAB_MAX)
         return;
 
     if( nTab < -1)
         nTab = a.Ref1.nTab;
 
-    if( nTab >= 0 && nTab <= MAXTAB)
+    if (nTab < 0 || MAXTAB < nTab)
+        return;
+
+    TabRangeType::iterator itr = maTabRanges.find(nTab);
+    if (itr == maTabRanges.end())
     {
-        _ScRangeList*   p = ppTabLists[ nTab ];
+        // No entry for this table yet.  Insert a new one.
+        std::pair<TabRangeType::iterator, bool> r =
+            maTabRanges.insert(nTab, new RangeListType);
 
-        if( !p )
-            p = ppTabLists[ nTab ] = new _ScRangeList;
+        if (!r.second)
+            // Insertion failed.
+            return;
 
-        p->push_back(new ScRange(a.Ref1.nCol,a.Ref1.nRow,a.Ref1.nTab,
-                                 a.Ref2.nCol,a.Ref2.nRow,a.Ref2.nTab));
+        itr = r.first;
     }
+    itr->second->push_back(
+        ScRange(a.Ref1.nCol,a.Ref1.nRow,a.Ref1.nTab,
+                a.Ref2.nCol,a.Ref2.nRow,a.Ref2.nTab));
 }
 
 const ScRange* _ScRangeListTabs::First( const UINT16 n )
 {
     DBG_ASSERT( ValidTab(n), "-_ScRangeListTabs::First(): Und tschuessssssss!" );
 
-    if( ppTabLists[ n ] )
-    {
-        pAct = ppTabLists[ n ];
-        nAct = n;
-        pAct->iterCur = pAct->begin();
-        return &(*(pAct->iterCur));
-    }
+    TabRangeType::iterator itr = maTabRanges.find(static_cast<SCsTAB>(n));
+    if (itr == maTabRanges.end())
+        // No range list exists for this table.
+        return NULL;
 
-    pAct = NULL;
-    nAct = 0;
-    return NULL;
+    const RangeListType& rList = *itr->second;
+    maItrCur = rList.begin();
+    maItrCurEnd = rList.end();
+    return rList.empty() ? NULL : &(*maItrCur);
 }
 
 const ScRange* _ScRangeListTabs::Next ()
 {
-    if( pAct )
-    {
-        ++pAct->iterCur;
-        return &(*(pAct->iterCur));
-    }
+    ++maItrCur;
+    if (maItrCur == maItrCurEnd)
+        return NULL;
 
-    return NULL;
+    return &(*maItrCur);
 }
 
 ConverterBase::ConverterBase( UINT16 nNewBuffer ) :
diff --git a/sc/source/filter/inc/formel.hxx b/sc/source/filter/inc/formel.hxx
index 79cb2fc..4c9c009 100644
--- a/sc/source/filter/inc/formel.hxx
+++ b/sc/source/filter/inc/formel.hxx
@@ -29,8 +29,6 @@
 #ifndef SC_FORMEL_HXX
 #define SC_FORMEL_HXX
 
-#include <boost/ptr_container/ptr_vector.hpp>
-
 #include <tools/solar.h>
 #include <tools/string.hxx>
 
@@ -40,6 +38,9 @@
 #include "root.hxx"
 #include "tokstack.hxx"
 
+#include <boost/ptr_container/ptr_map.hpp>
+#include <vector>
+
 class XclImpStream;
 class ScTokenArray;
 class ScFormulaCell;
@@ -64,20 +65,14 @@ enum FORMULA_TYPE
 
 class _ScRangeListTabs
 {
-    struct _ScRangeList : public boost::ptr_vector<ScRange>
-    {
-        iterator iterCur;
-    };
-
-    BOOL						bHasRanges;
-    _ScRangeList**				ppTabLists;
-    _ScRangeList*				pAct;
-    UINT16						nAct;
+    typedef ::std::vector<ScRange> RangeListType;
+    typedef ::boost::ptr_map<SCsTAB, RangeListType> TabRangeType;
+    TabRangeType maTabRanges;
+    RangeListType::const_iterator maItrCur;
+    RangeListType::const_iterator maItrCurEnd;
 
 public:
-
     _ScRangeListTabs ();
-
     ~_ScRangeListTabs();
 
     void Append( ScSingleRefData aSRD, SCsTAB nTab, const BOOL bLimit = TRUE );
@@ -86,9 +81,7 @@ public:
     const ScRange* First ( const UINT16 nTab = 0 );
     const ScRange* Next ();
 
-    inline bool HasRanges () const { return bHasRanges; }
-
-    inline bool	HasActList () const { return pAct != NULL; }
+    bool HasRanges () const { return !maTabRanges.empty(); }
 };
 
 class ConverterBase
commit a1eaf7cb184e49c92ce0c3385e213dab7fad3e7b
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 18:28:03 2011 -0500

    Copy-n-paste error....

diff --git a/sc/source/filter/excel/tokstack.cxx b/sc/source/filter/excel/tokstack.cxx
index f4f2021..5450085 100644
--- a/sc/source/filter/excel/tokstack.cxx
+++ b/sc/source/filter/excel/tokstack.cxx
@@ -467,7 +467,7 @@ void TokenPool::GetElementRek( const UINT16 nId )
                     break;
                 case T_RN:
                 {
-                    UINT16 n = pElement[nId];
+                    UINT16 n = pElement[*pAkt];
                     if (n < maRangeNames.size())
                     {
                         const RangeName& r = maRangeNames[n];
commit 7279d186037326fb52d571f12d6a11bb97b08aaf
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 15:35:50 2011 -0500

    Search the sheet local range names as well when compiling formula.
    
    This allows a sheet-local named range to be recognized when entered
    into a cell inside a formula expression.

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index bf632f4..27b63c0 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2896,13 +2896,24 @@ BOOL ScCompiler::IsNamedRange( const String& rUpperName )
 {
     // IsNamedRange is called only from NextNewToken, with an upper-case string
 
-    // TODO: Get it to work with sheet local names.
+    // Try global named ranges first, then sheet local next.  BTW does this
+    // order matter?
+    bool bGlobal = true;
     ScRangeName* pRangeName = pDoc->GetRangeName();
     const ScRangeData* pData = pRangeName->findByUpperName(rUpperName);
+    if (!pData)
+    {
+        pRangeName = pDoc->GetRangeName(aPos.Tab());
+        if (pRangeName)
+            pData = pRangeName->findByUpperName(rUpperName);
+        if (pData)
+            bGlobal = false;
+    }
+
     if (pData)
     {
         ScRawToken aToken;
-        aToken.SetName(true, pData->GetIndex());
+        aToken.SetName(bGlobal, pData->GetIndex());
         pRawToken = aToken.Clone();
         return true;
     }
commit 0748019cc5a6804c55df7bde5644e4a6c74f0c37
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Mar 9 15:02:18 2011 -0500

    Correctly import and interpret sheet local range names from XLS.

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index a198b7c..bf632f4 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3888,7 +3888,20 @@ ScTokenArray* ScCompiler::CompileString( const String& rFormula, const String& r
 
 BOOL ScCompiler::HandleRange()
 {
-    ScRangeData* pRangeData = pDoc->GetRangeName()->findByIndex( pToken->GetIndex() );
+    ScRangeData* pRangeData = NULL;
+
+    bool bGlobal = pToken->GetByte();
+    if (bGlobal)
+        // global named range.
+        pRangeData = pDoc->GetRangeName()->findByIndex( pToken->GetIndex() );
+    else
+    {
+        // sheet local named range.
+        ScRangeName* pRN = pDoc->GetRangeName(aPos.Tab());
+        if (pRN)
+            pRangeData = pRN->findByIndex( pToken->GetIndex() );
+    }
+
     if (pRangeData)
     {
         USHORT nErr = pRangeData->GetErrCode();
@@ -5057,7 +5070,19 @@ void ScCompiler::CreateStringFromIndex(rtl::OUStringBuffer& rBuffer,FormulaToken
     {
         case ocName:
         {

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list