[Libreoffice-commits] core.git: Branch 'libreoffice-5-2' - sc/inc sc/source

Bartosz Kosiorek gang65 at poczta.onet.pl
Fri Dec 2 13:09:28 UTC 2016


 sc/inc/address.hxx                  |   26 ++++++++++++++++++++++++--
 sc/source/core/tool/address.cxx     |   10 +++++-----
 sc/source/filter/excel/xestream.cxx |    6 ++++--
 sc/source/filter/excel/xetable.cxx  |    5 ++++-
 sc/source/filter/inc/xestream.hxx   |    2 +-
 5 files changed, 38 insertions(+), 11 deletions(-)

New commits:
commit 3cd0184306825c52da237815a8e782ce4c80253a
Author: Bartosz Kosiorek <gang65 at poczta.onet.pl>
Date:   Fri Nov 18 12:36:21 2016 +0100

    OOXML: Write dimension range in full address notation
    
    In every sheet.xml there is information about dimensions, like:
    <dimension ref="A1:AMJ177"/>. During export by LibreOffice to .xlsx,
    when row or column has maximum value, the dimension was
    truncated. For example given "A1:AMJ177" it's saves <dimension ref="1:177"/>.
    It was caused problems with Office 2007 import.
    This patch is fixing that by always using full address notation
    for dimension range,  and allow open documents exported by LO
    properly by MS Office.
    
    Change-Id: Idda1455d1f9db08ade0871110fe40be2667c176c
    Reviewed-on: https://gerrit.libreoffice.org/30960
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    (cherry picked from commit 71862564df1422f84340e421bbef9060c4e41a71)
    Reviewed-on: https://gerrit.libreoffice.org/31526
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index b2c41cc..52d6505 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -543,8 +543,30 @@ public:
                                         const css::uno::Sequence<css::sheet::ExternalLinkInfo>* pExternalLinks = nullptr,
                                         const OUString* pErrRef = nullptr );
 
-    SC_DLLPUBLIC OUString Format(ScRefFlags nFlags = ScRefFlags::ZERO, const ScDocument* pDocument = nullptr,
-                                 const ScAddress::Details& rDetails = ScAddress::detailsOOOa1) const;
+    /** Returns string with formatted cell range from aStart to aEnd,
+        according to provided address convention.
+        @param nFlags
+            Cell reference flags
+        @param pDocument
+            Pointer to document which is used for example to get tab names.
+        @param rDetails
+            Provide information about required address convention.
+            Supported address conventions are:
+                CONV_OOO      'doc'#sheet.A1:sheet2.B2
+                CONV_XL_A1,   [doc]sheet:sheet2!A1:B2
+                CONV_XL_OOX,  [#]sheet:sheet2!A1:B2
+                CONV_XL_R1C1, [doc]sheet:sheet2!R1C1:R2C2
+        @param bFullAddressNotation
+            If TRUE, the full address notation will be used.
+            For example in case all columns are used, "A1:AMJ177" is full address notation
+            and "1:177" is shortened address notation.
+        @returns
+            String contains formatted cell range in address convention
+     */
+    SC_DLLPUBLIC OUString Format( ScRefFlags nFlags = ScRefFlags::ZERO,
+                                  const ScDocument* pDocument = nullptr,
+                                  const ScAddress::Details& rDetails = ScAddress::detailsOOOa1,
+                                  bool bFullAddressNotation = false ) const;
 
     inline void GetVars( SCCOL& nCol1, SCROW& nRow1, SCTAB& nTab1,
                          SCCOL& nCol2, SCROW& nRow2, SCTAB& nTab2 ) const;
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 134067c..62ad16e 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -2166,7 +2166,7 @@ static inline bool lcl_RowAbsFlagDiffer(const ScRefFlags nFlags)
 }
 
 OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
-                          const ScAddress::Details& rDetails ) const
+                          const ScAddress::Details& rDetails, bool bFullAddressNotation ) const
 {
     if( !( nFlags & ScRefFlags::VALID ) )
     {
@@ -2201,14 +2201,14 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
     case formula::FormulaGrammar::CONV_XL_A1:
     case formula::FormulaGrammar::CONV_XL_OOX:
         lcl_ScRange_Format_XL_Header( r, *this, nFlags, pDoc, rDetails );
-        if( aStart.Col() == 0 && aEnd.Col() >= MAXCOL )
+        if( aStart.Col() == 0 && aEnd.Col() >= MAXCOL && !bFullAddressNotation )
         {
             // Full col refs always require 2 rows (2:2)
             lcl_a1_append_r( r, aStart.Row(), (nFlags & ScRefFlags::ROW_ABS) != ScRefFlags::ZERO );
             r.append(":");
             lcl_a1_append_r( r, aEnd.Row(), (nFlags & ScRefFlags::ROW2_ABS) != ScRefFlags::ZERO );
         }
-        else if( aStart.Row() == 0 && aEnd.Row() >= MAXROW )
+        else if( aStart.Row() == 0 && aEnd.Row() >= MAXROW && !bFullAddressNotation )
         {
             // Full row refs always require 2 cols (A:A)
             lcl_a1_append_c( r, aStart.Col(), (nFlags & ScRefFlags::COL_ABS) != ScRefFlags::ZERO );
@@ -2232,7 +2232,7 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
 
     case formula::FormulaGrammar::CONV_XL_R1C1:
         lcl_ScRange_Format_XL_Header( r, *this, nFlags, pDoc, rDetails );
-        if( aStart.Col() == 0 && aEnd.Col() >= MAXCOL )
+        if( aStart.Col() == 0 && aEnd.Col() >= MAXCOL && !bFullAddressNotation )
         {
             lcl_r1c1_append_r( r, aStart.Row(), (nFlags & ScRefFlags::ROW_ABS) != ScRefFlags::ZERO, rDetails );
             if( aStart.Row() != aEnd.Row() ||
@@ -2241,7 +2241,7 @@ OUString ScRange::Format( ScRefFlags nFlags, const ScDocument* pDoc,
                 lcl_r1c1_append_r( r, aEnd.Row(), (nFlags & ScRefFlags::ROW2_ABS) != ScRefFlags::ZERO, rDetails );
             }
         }
-        else if( aStart.Row() == 0 && aEnd.Row() >= MAXROW )
+        else if( aStart.Row() == 0 && aEnd.Row() >= MAXROW && !bFullAddressNotation )
         {
             lcl_r1c1_append_c( r, aStart.Col(), (nFlags & ScRefFlags::COL_ABS) != ScRefFlags::ZERO, rDetails );
             if( aStart.Col() != aEnd.Col() ||
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index 171479c..406b138 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -726,9 +726,11 @@ OString XclXmlUtils::ToOString( const ScfUInt16Vec& rBuffer )
         RTL_TEXTENCODING_UTF8);
 }
 
-OString XclXmlUtils::ToOString( const ScRange& rRange )
+OString XclXmlUtils::ToOString( const ScRange& rRange, bool bFullAddressNotation )
 {
-    OUString sRange(rRange.Format(ScRefFlags::VALID, nullptr, ScAddress::Details( FormulaGrammar::CONV_XL_A1)));
+    OUString sRange(rRange.Format( ScRefFlags::VALID, nullptr,
+                                   ScAddress::Details( FormulaGrammar::CONV_XL_A1 ),
+                                   bFullAddressNotation ) );
     return ToOString( sRange );
 }
 
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index f539b92..636183e 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1526,7 +1526,10 @@ void XclExpDimensions::SaveXml( XclExpXmlStream& rStrm )
     }
 
     rStrm.GetCurrentStream()->singleElement( XML_dimension,
-            XML_ref, XclXmlUtils::ToOString( aRange ).getStr(),
+            // To be compatible with MS Office 2007,
+            // we need full address notation format
+            // e.g. "A1:AMJ177" and not partial like: "1:177".
+            XML_ref, XclXmlUtils::ToOString( aRange, true ).getStr(),
             FSEND );
 }
 
diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx
index 0d14f36..e2d4e88 100644
--- a/sc/source/filter/inc/xestream.hxx
+++ b/sc/source/filter/inc/xestream.hxx
@@ -260,7 +260,7 @@ public:
     static OString ToOString( const OUString& s );
     static OString ToOString( const ScfUInt16Vec& rBuffer );
     static OStringBuffer& ToOString( OStringBuffer& s, const ScAddress& rRange );
-    static OString ToOString( const ScRange& rRange );
+    static OString ToOString( const ScRange& rRange, bool bFullAddressNotation = false );
     static OString ToOString( const ScRangeList& rRangeList );
     static OStringBuffer& ToOString( OStringBuffer& s, const XclAddress& rAddress );
     static OString ToOString( const XclExpString& s );


More information about the Libreoffice-commits mailing list