Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hello,

this patch removes entries like #REF! A1:A3 for named ranges when the sheet
referenced by the named range is no longer there. I implemented Regina's
first suggestion because I don't see a way to implement the other version
with our current formula api.

All in all this should be quite a save fix since I only added checks that
the ScTokenArray contains no error and that the reference is valid.

Regards,
Markus
From dd98777c8916ff0e9b955295338a2fea0f390759 Mon Sep 17 00:00:00 2001
From: Markus Mohrhard <markus.mohrhard@googlemail.com>
Date: Tue, 9 Aug 2011 04:31:35 +0200
Subject: [PATCH] fix for fdo#37391: don't write invalid references to file

---
 sc/inc/rangenam.hxx               |    2 +-
 sc/source/core/tool/rangenam.cxx  |    2 +-
 sc/source/filter/xml/xmlexprt.cxx |   25 ++++++++++++++++++++++---
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index 5d3ff49..543d727 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -119,7 +119,7 @@ public:
     sal_uInt16    GetIndex() const                { return nIndex; }
     ScTokenArray*   GetCode()                       { return pCode; }
     const ScTokenArray* GetCode() const             { return pCode; }
-    sal_uInt16          GetErrCode();
+    sal_uInt16          GetErrCode() const;
     sal_Bool            HasReferences() const;
     void            SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
     ScDocument*     GetDocument() const             { return pDoc; }
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 9b19fbf..c79457a 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -521,7 +521,7 @@ SCCOL ScRangeData::GetMaxCol() const
 }
 
 
-sal_uInt16 ScRangeData::GetErrCode()
+sal_uInt16 ScRangeData::GetErrCode() const
 {
     return pCode ? pCode->GetCodeError() : 0;
 }
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 5ef06cf..c8123e8 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2856,8 +2856,16 @@ void ScXMLExport::WriteTable(sal_Int32 nTable, const 
Reference<sheet::XSpreadshe
                 AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, aStr);
 
                 // expression
-                itr->GetSymbol(aStr, pDoc->GetStorageGrammar());
-                AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, aStr);
+                if (itr->GetErrCode())
+                {
+                    aStr = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[#REF!]"));
+                    AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, aStr);
+                }
+                else
+                {
+                    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);
             }
@@ -3808,7 +3816,18 @@ void ScXMLExport::WriteNamedExpressions(const com::sun::star::uno::Reference 
<co
         }
         else
         {
-            AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, sOUTempContent);
+            ScRange aRange;
+            if (pNamedRange->GetErrCode() || !pNamedRange->IsValidReference(aRange))
+            {
+                rtl::OUString aStr(RTL_CONSTASCII_USTRINGPARAM("[#REF!]"));
+                AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, aStr);
+            }
+            else
+            {
+                rtl::OUString aStr;
+                pNamedRange->GetSymbol(aStr, pDoc->GetStorageGrammar());
+                AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, aStr);
+            }
             SvXMLElementExport aElemNE(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, sal_True, 
sal_True);
         }
     }
-- 
1.7.3.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.