[PATCH] Correctly import from Excel charts with multiple ranges.

Kohei Yoshida kohei.yoshida at suse.com
Tue Aug 9 12:49:15 PDT 2011


This was "fixed" in i#107275, but the fix only worked in locales
where the range/argument separator was ';' (e.g. German locale).
This is the correct fix that works in all locales regardless of
the separator.
---
 sc/inc/reftokenhelper.hxx                     |    2 +-
 sc/source/core/tool/reftokenhelper.cxx        |    4 +-
 sc/source/filter/xml/XMLTableShapeResizer.cxx |    5 ++-
 sc/source/ui/unoobj/chart2uno.cxx             |   38 +++++++++++++++++--------
 4 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/sc/inc/reftokenhelper.hxx b/sc/inc/reftokenhelper.hxx
index 8451a16..3566fd7 100644
--- a/sc/inc/reftokenhelper.hxx
+++ b/sc/inc/reftokenhelper.hxx
@@ -55,7 +55,7 @@ public:
      */
     static void compileRangeRepresentation(
         ::std::vector<ScTokenRef>& rRefTokens, const ::rtl::OUString& rRangeStr, ScDocument* pDoc,
-        ::formula::FormulaGrammar::Grammar eGrammar = ::formula::FormulaGrammar::GRAM_ENGLISH);
+        const sal_Unicode cSep, ::formula::FormulaGrammar::Grammar eGrammar);
 
     static bool getRangeFromToken(ScRange& rRange, const ScTokenRef& pToken, bool bExternal = false);
 
diff --git a/sc/source/core/tool/reftokenhelper.cxx b/sc/source/core/tool/reftokenhelper.cxx
index e77f130..fb54280 100644
--- a/sc/source/core/tool/reftokenhelper.cxx
+++ b/sc/source/core/tool/reftokenhelper.cxx
@@ -47,9 +47,9 @@ using ::std::auto_ptr;
 using ::rtl::OUString;
 
 void ScRefTokenHelper::compileRangeRepresentation(
-    vector<ScTokenRef>& rRefTokens, const OUString& rRangeStr, ScDocument* pDoc, FormulaGrammar::Grammar eGrammar)
+    vector<ScTokenRef>& rRefTokens, const OUString& rRangeStr, ScDocument* pDoc,
+    const sal_Unicode cSep, FormulaGrammar::Grammar eGrammar)
 {
-    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
     const sal_Unicode cQuote = '\'';
 
     // #i107275# ignore parentheses
diff --git a/sc/source/filter/xml/XMLTableShapeResizer.cxx b/sc/source/filter/xml/XMLTableShapeResizer.cxx
index e0425c0..6d61b80 100644
--- a/sc/source/filter/xml/XMLTableShapeResizer.cxx
+++ b/sc/source/filter/xml/XMLTableShapeResizer.cxx
@@ -35,6 +35,7 @@
 #include "chartlis.hxx"
 #include "XMLConverter.hxx"
 #include "rangeutl.hxx"
+#include "compiler.hxx"
 #include "reftokenhelper.hxx"
 #include <tools/debug.hxx>
 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
@@ -94,7 +95,9 @@ void ScMyOLEFixer::CreateChartListener(ScDocument* pDoc,
         return;
 
     auto_ptr< vector<ScTokenRef> > pRefTokens(new vector<ScTokenRef>);
-    ScRefTokenHelper::compileRangeRepresentation(*pRefTokens, aRangeStr, pDoc);
+    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
+    ScRefTokenHelper::compileRangeRepresentation(
+        *pRefTokens, aRangeStr, pDoc, cSep, formula::FormulaGrammar::GRAM_ENGLISH);
     if (!pRefTokens->empty())
     {
         ScChartListener* pCL(new ScChartListener(rName, pDoc, pRefTokens.release()));
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 32fc54a..8c43501 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -1043,7 +1043,9 @@ void ScChart2DataProvider::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint
     }
 
     vector<ScTokenRef> aTokens;
-    ScRefTokenHelper::compileRangeRepresentation(aTokens, aRangeRepresentation, m_pDocument, m_pDocument->GetGrammar());
+    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
+    ScRefTokenHelper::compileRangeRepresentation(
+        aTokens, aRangeRepresentation, m_pDocument, cSep, m_pDocument->GetGrammar());
     return !aTokens.empty();
 }
 
@@ -1419,7 +1421,9 @@ ScChart2DataProvider::createDataSource(
     }
 
     vector<ScTokenRef> aRefTokens;
-    ScRefTokenHelper::compileRangeRepresentation(aRefTokens, aRangeRepresentation, m_pDocument, m_pDocument->GetGrammar());
+    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
+    ScRefTokenHelper::compileRangeRepresentation(
+        aRefTokens, aRangeRepresentation, m_pDocument, cSep, m_pDocument->GetGrammar());
     if (aRefTokens.empty())
         // Invalid range representation.  Bail out.
         throw lang::IllegalArgumentException();
@@ -1743,7 +1747,9 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArgum
                 {
                     bFirstCellAsLabel = true;
                     vector<ScTokenRef> aTokens;
-                    ScRefTokenHelper::compileRangeRepresentation( aTokens, xLabel->getSourceRangeRepresentation(), m_pDocument, m_pDocument->GetGrammar() );
+                    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
+                    ScRefTokenHelper::compileRangeRepresentation(
+                        aTokens, xLabel->getSourceRangeRepresentation(), m_pDocument, cSep, m_pDocument->GetGrammar());
                     aLabel.initRangeAnalyzer(aTokens);
                     vector<ScTokenRef>::const_iterator itr = aTokens.begin(), itrEnd = aTokens.end();
                     for (; itr != itrEnd; ++itr)
@@ -1760,7 +1766,9 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArgum
                 if( xValues.is())
                 {
                     vector<ScTokenRef> aTokens;
-                    ScRefTokenHelper::compileRangeRepresentation( aTokens, xValues->getSourceRangeRepresentation(), m_pDocument, m_pDocument->GetGrammar() );
+                    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
+                    ScRefTokenHelper::compileRangeRepresentation(
+                        aTokens, xValues->getSourceRangeRepresentation(), m_pDocument, cSep, m_pDocument->GetGrammar());
                     aValues.initRangeAnalyzer(aTokens);
                     vector<ScTokenRef>::const_iterator itr = aTokens.begin(), itrEnd = aTokens.end();
                     for (; itr != itrEnd; ++itr)
@@ -1967,7 +1975,9 @@ uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArgum
         return false;
 
     vector<ScTokenRef> aTokens;
-    ScRefTokenHelper::compileRangeRepresentation(aTokens, aRangeRepresentation, m_pDocument, m_pDocument->GetGrammar());
+    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
+    ScRefTokenHelper::compileRangeRepresentation(
+        aTokens, aRangeRepresentation, m_pDocument, cSep, m_pDocument->GetGrammar());
     return !aTokens.empty();
 }
 
@@ -1984,14 +1994,16 @@ uno::Reference< chart2::data::XDataSequence > SAL_CALL
     if(!m_pDocument || (aRangeRepresentation.getLength() == 0))
         return xResult;
 
-    // Note: the range representation must be in Calc A1 format.  The import 
-    // filters use this method to pass data ranges, and they have no idea what
-    // the current formula syntax is.  In the future we should add another
-    // method to allow the client code to directly pass tokens representing
-    // ranges.
+    // Note: the range representation must be in Calc A1 format, with English
+    // function names and ';' as the union operator in case of multiple
+    // ranges. The import filters use this method to pass data ranges, and
+    // they have no idea what the current formula syntax is. In the future we
+    // should add another method to allow the client code to directly pass
+    // tokens representing ranges.
 
     vector<ScTokenRef> aRefTokens;
-    ScRefTokenHelper::compileRangeRepresentation(aRefTokens, aRangeRepresentation, m_pDocument);
+    ScRefTokenHelper::compileRangeRepresentation(
+        aRefTokens, aRangeRepresentation, m_pDocument, ';', FormulaGrammar::GRAM_ENGLISH);
     if (aRefTokens.empty())
         return xResult;
 
@@ -2029,7 +2041,9 @@ rtl::OUString SAL_CALL ScChart2DataProvider::convertRangeToXML( const rtl::OUStr
         return aRet;
 
     vector<ScTokenRef> aRefTokens;
-    ScRefTokenHelper::compileRangeRepresentation(aRefTokens, sRangeRepresentation, m_pDocument, m_pDocument->GetGrammar());
+    const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
+    ScRefTokenHelper::compileRangeRepresentation(
+        aRefTokens, sRangeRepresentation, m_pDocument, cSep, m_pDocument->GetGrammar());
     if (aRefTokens.empty())
         throw lang::IllegalArgumentException();
 
-- 
1.7.3.4


--=-v6xqpJ6w3utaSUkDzp0o
Content-Type: application/x-gzip; name="chart-series-disjoint.xls.gz"
Content-Disposition: attachment; filename="chart-series-disjoint.xls.gz"
Content-Transfer-Encoding: base64

H4sICK1fQU4AA2NoYXJ0LXNlcmllcy1kaXNqb2ludC54bHMA7VtbbBRVGP7O7KW7baGnpRegUJYW
hF4k0KqQKnRRIBLCXQGlpC2whEqhpC0GfWEBSXyABOVBH0gsPmk0CFExMRqKMcYHicRIjCYmYHgw
asJiIEoCrP//n5nd2e1SKIEgOv/mXOa/nvPPP+c2s2e+LT535PjY88iCOfDhRjKMoAunKI11LjSI
nkxy1SnHUEp68EBBOEQ3MhjAgtGn8+bGqWoB52HhmP8U5cAvlFqxHSOARd2bY52R57p7N3du7Ijc
Y3hS2tChuA0DFHizVZDiz6KoPEz5SIo1ppRIPkryD4T3M8lnEyWBRdg/c+usWXbsrrGiwndA8mrJ
R1Ku8InI/CSYGRThX3Mc7zqoTKAH1Fz0oBMd6LrH1P47pFb5xyGACurUpOqahpqa6W21j7dOdS5a
a6v8E+k5HpdBX7sitnFdJlM18jA+zTRteqYeumauKQiR87K4srTZrDNRh0agjfF1Eceyfdk61Tbs
IKofrhZqtI1Ep6GWfiTqlssUypJoQQOaM42ZtmXak6a5TLa0pFU8hnrydNqoIz9IOEvyHErlnlxJ
Rlyj5UCE8crBX749vDVMPP6HeIUI0uD4s97w/52Nr70JvuEm+Lqb4MOD8IcsP3Tcl+SyOB6UsiTu
l3JUPE9KxCFlaTyQbJdxZh+NOmtlWg1i5eZYrG8GY3pHujCNjHm5yIVp2g8/tUHhqPLTGKj8FfQY
2kMBTqkQJeCZAwq/43mQYGKFUIKJ0ZRzM9iyBTOHK7vehIJECZUnSVcIu2lEQWhARSmPouoSzQs8
6ocKKdHYEvqL5vxrNMo4mkjpko6tsQCwqqNrRyyJfFLSTB0jAaoDZmr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5Z5/a99efVpZv1e6+FUD/l
wx95OXcMvNAw9ChkFYinKXGctYMXVMBOmE3AQcgOAofBZzTAOzArlQskVAU+fck6VCLJofD8bCzu
3NDT3du9qS8yf+eGWJeJteVf/XZs1Te8c0H8o49LjlPddw985YEHHnjggQceeOCBBx544IEHDyoM
tf+3zp4+e3hapT70Bu3/G64e5f3/BcA+2gOWwbxw4nPvCkrbKRXA7P95rx6H2ffzq5typM8D3oQ5
HziFzPMApi3pfjHW1dUQWbhtwzRgdTfv4+fm54te2PpzlVXanI3y2YR5q5quNqarTSjUxmiVLby6
u2dLL5N6Rd47N/DAAw888MADDzzwwAMPPPDgvwjOt8C87+V3+fyFH3+ewTtmfqfP/+3hzzR4q8x7
dt6j8/t53vdrm87v/Hmf73xTwnt9Pg8YbdOvU7pxP/7c4sEtYQW66deHCOZjG5U9eGlY8VOOgHJ0
cRxFQuYsacCQF+SScf4vxrCarPdgC9ZLO7YMyzZDCSzl7s/tyu22P7QKYCV2YCv9OqTvC8kLm6RN
jOlDJ9W3DaFnKtnnZ4ifn9u1L9+WpezPIwsbpA0xuQPDa8+sO+h/scv+P0QZTKUAOAAA


--=-v6xqpJ6w3utaSUkDzp0o--



More information about the LibreOffice mailing list