[Libreoffice-commits] .: Branch 'feature/dp-named-range-source' - sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Jan 21 20:39:38 PST 2011


 sc/inc/dpshttab.hxx                |    2 -
 sc/source/filter/excel/read.cxx    |    1 
 sc/source/filter/excel/xipivot.cxx |   65 +++++++++++++++++++++++++++++--------
 sc/source/filter/inc/xipivot.hxx   |   10 +++++
 4 files changed, 64 insertions(+), 14 deletions(-)

New commits:
commit 9f49336d7df0b051cd60217fe9e929125650da4d
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jan 21 23:39:01 2011 -0500

    Take care of importing pivot tables with range name from xls docs.

diff --git a/sc/inc/dpshttab.hxx b/sc/inc/dpshttab.hxx
index c1ce6c0..d08984f 100644
--- a/sc/inc/dpshttab.hxx
+++ b/sc/inc/dpshttab.hxx
@@ -70,7 +70,7 @@ public:
      * @return source range.
      */
     SC_DLLPUBLIC const ScRange& GetSourceRange() const;
-    void SetRangeName(const ::rtl::OUString& rName);
+    SC_DLLPUBLIC void SetRangeName(const ::rtl::OUString& rName);
     const ::rtl::OUString& GetRangeName() const;
     bool HasRangeName() const;
     void SetQueryParam(const ScQueryParam& rParam);
diff --git a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx
index 2a299d4..1ed46a3 100644
--- a/sc/source/filter/excel/read.cxx
+++ b/sc/source/filter/excel/read.cxx
@@ -1020,6 +1020,7 @@ FltError ImportExcel8::Read( void )
                     case EXC_ID_SXIDSTM:        rPTableMgr.ReadSxidstm( maStrm );   break;
                     case EXC_ID_SXVS:           rPTableMgr.ReadSxvs( maStrm );      break;
                     case EXC_ID_DCONREF:        rPTableMgr.ReadDconref( maStrm );   break;
+                    case EXC_ID_DCONNAME:       rPTableMgr.ReadDConName( maStrm );  break;
                 }
 
             }
diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx
index 16109c2..a860353 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -659,6 +659,22 @@ void XclImpPivotCache::ReadDconref( XclImpStream& rStrm )
         GetAddressConverter().ConvertRange( maSrcRange, aXclRange, 0, 0, true );
 }
 
+void XclImpPivotCache::ReadDConName( XclImpStream& rStrm )
+{
+    maSrcRangeName = rStrm.ReadUniString();
+
+    // This 2-byte value equals the length of string that follows, or if 0 it
+    // indicates that the name has a workbook scope.  For now, we only support
+    // internal defined name with a workbook scope.
+    sal_uInt16 nFlag;
+    rStrm >> nFlag;
+    mbSelfRef = (nFlag == 0);
+
+    if (!mbSelfRef)
+        // External name is not supported yet.
+        maSrcRangeName = OUString();
+}
+
 void XclImpPivotCache::ReadPivotCacheStream( XclImpStream& rStrm )
 {
     if( (mnSrcType != EXC_SXVS_SHEET) && (mnSrcType != EXC_SXVS_EXTERN) )
@@ -672,18 +688,21 @@ void XclImpPivotCache::ReadPivotCacheStream( XclImpStream& rStrm )
 
     if( mbSelfRef )
     {
-        // try to find internal sheet containing the source data
-        nScTab = GetTabInfo().GetScTabFromXclName( maTabName );
-        if( rDoc.HasTable( nScTab ) )
+        if (!maSrcRangeName.getLength())
         {
-            // set sheet index to source range
-            maSrcRange.aStart.SetTab( nScTab );
-            maSrcRange.aEnd.SetTab( nScTab );
-        }
-        else
-        {
-            // create dummy sheet for deleted internal sheet
-            bGenerateSource = true;
+            // try to find internal sheet containing the source data
+            nScTab = GetTabInfo().GetScTabFromXclName( maTabName );
+            if( rDoc.HasTable( nScTab ) )
+            {
+                // set sheet index to source range
+                maSrcRange.aStart.SetTab( nScTab );
+                maSrcRange.aEnd.SetTab( nScTab );
+            }
+            else
+            {
+                // create dummy sheet for deleted internal sheet
+                bGenerateSource = true;
+            }
         }
     }
     else
@@ -856,6 +875,14 @@ bool XclImpPivotCache::IsRefreshOnLoad() const
     return static_cast<bool>(maPCInfo.mnFlags & 0x0004);
 }
 
+bool XclImpPivotCache::IsValid() const
+{
+    if (maSrcRangeName.getLength())
+        return true;
+
+    return maSrcRange.IsValid();
+}
+
 // ============================================================================
 // Pivot table
 // ============================================================================
@@ -1346,7 +1373,7 @@ void XclImpPivotTable::ReadSxViewEx9( XclImpStream& rStrm )
 
 void XclImpPivotTable::Convert()
 {
-    if( !mxPCache || !mxPCache->GetSourceRange().IsValid() )
+    if( !mxPCache || !mxPCache->IsValid() )
         return;
 
     ScDPSaveData aSaveData;
@@ -1396,7 +1423,13 @@ void XclImpPivotTable::Convert()
 
     // create source descriptor
     ScSheetSourceDesc aDesc(GetDocPtr());
-    aDesc.SetSourceRange(mxPCache->GetSourceRange());
+    const OUString& rSrcName = mxPCache->GetSourceRangeName();
+    if (rSrcName.getLength())
+        // Range name is the data source.
+        aDesc.SetRangeName(rSrcName);
+    else
+        // Normal cell range.
+        aDesc.SetSourceRange(mxPCache->GetSourceRange());
 
     // adjust output range to include the page fields
     ScRange aOutRange( maOutScRange );
@@ -1558,6 +1591,12 @@ void XclImpPivotTableManager::ReadDconref( XclImpStream& rStrm )
         maPCaches.back()->ReadDconref( rStrm );
 }
 
+void XclImpPivotTableManager::ReadDConName( XclImpStream& rStrm )
+{
+    if( !maPCaches.empty() )
+        maPCaches.back()->ReadDConName( rStrm );
+}
+
 // pivot table records --------------------------------------------------------
 
 void XclImpPivotTableManager::ReadSxview( XclImpStream& rStrm )
diff --git a/sc/source/filter/inc/xipivot.hxx b/sc/source/filter/inc/xipivot.hxx
index 9b26509..e4ad832 100644
--- a/sc/source/filter/inc/xipivot.hxx
+++ b/sc/source/filter/inc/xipivot.hxx
@@ -169,6 +169,8 @@ public:
     /** Returns the data source range read from the DCONREF record. */
     inline const ScRange& GetSourceRange() const { return maSrcRange; }
 
+    const ::rtl::OUString& GetSourceRangeName() const { return maSrcRangeName; }
+
     /** Returns the number of pivot cache fields. */
     sal_uInt16          GetFieldCount() const;
     /** Returns read-only access to a pivot cache field. */
@@ -182,10 +184,16 @@ public:
     void                ReadSxvs( XclImpStream& rStrm );
     /** Reads a DCONREF record containing the source range of the pivot cache. */
     void                ReadDconref( XclImpStream& rStrm );
+    /**
+     * Read DECONNAME record which contains the defined name of the source
+     * range.
+     */
+    void                ReadDConName( XclImpStream& rStrm );
     /** Reads the entire pivot cache stream. Uses decrypter from passed stream. */
     void                ReadPivotCacheStream( XclImpStream& rStrm );
 
     bool                IsRefreshOnLoad() const;
+    bool                IsValid() const;
 
 private:
     typedef ::std::vector< XclImpPCFieldRef > XclImpPCFieldVec;
@@ -195,6 +203,7 @@ private:
     ScRange             maSrcRange;         /// Source range in the spreadsheet.
     String              maUrl;              /// URL of the source data.
     String              maTabName;          /// Sheet name of the source data.
+    ::rtl::OUString     maSrcRangeName;     /// Name of the source data range.
     sal_uInt16          mnStrmId;           /// Pivot cache stream identifier.
     sal_uInt16          mnSrcType;          /// Source data type.
     bool                mbSelfRef;          /// true = Source data from own document.
@@ -413,6 +422,7 @@ public:
     void                ReadSxvs( XclImpStream& rStrm );
     /** Reads a DCONREF record containing the source range of a pivot cache. */
     void                ReadDconref( XclImpStream& rStrm );
+    void                ReadDConName( XclImpStream& rStrm );
 
     // pivot table records ----------------------------------------------------
 


More information about the Libreoffice-commits mailing list