From 5f43ea17a724aad3e3181d970d6f74057dbecc3b Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 13 May 2011 21:55:11 -0400 Subject: Fixed incorrect exporting of global named database ranges. --- sc/inc/dbcolect.hxx | 2 ++ sc/source/filter/xml/XMLExportDatabaseRanges.cxx | 38 +++++++++++++++++------- sc/source/filter/xml/xmldrani.cxx | 12 ++++---- sc/source/filter/xml/xmldrani.hxx | 6 ++-- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/sc/inc/dbcolect.hxx b/sc/inc/dbcolect.hxx index 280c59e77..bf2a0324c 100644 --- a/sc/inc/dbcolect.hxx +++ b/sc/inc/dbcolect.hxx @@ -161,6 +161,8 @@ public: class SC_DLLPUBLIC ScDBCollection { public: + enum RangeType { GlobalNamed, GlobalAnonymous, SheetAnonymous }; + /** * Stores global named database ranges. */ diff --git a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx index 25fa489a7..b81f17979 100644 --- a/sc/source/filter/xml/XMLExportDatabaseRanges.cxx +++ b/sc/source/filter/xml/XMLExportDatabaseRanges.cxx @@ -576,12 +576,25 @@ namespace { class WriteDatabaseRange : public ::std::unary_function { + ScXMLExport& mrExport; + ScDocument* mpDoc; + sal_Int32 mnCounter; + ScDBCollection::RangeType meRangeType; public: + WriteDatabaseRange(ScXMLExport& rExport, ScDocument* pDoc) : - mrExport(rExport), mpDoc(pDoc), mnCounter(0) {} + mrExport(rExport), mpDoc(pDoc), mnCounter(0), meRangeType(ScDBCollection::GlobalNamed) {} + + void setRangeType(ScDBCollection::RangeType eNew) + { + meRangeType = eNew; + } void operator() (const ::std::pair& r) { + if (meRangeType != ScDBCollection::SheetAnonymous) + return; + // name OUStringBuffer aBuf; aBuf.appendAscii(STR_DB_LOCAL_NONAME); @@ -592,12 +605,17 @@ public: void operator() (const ScDBData& rData) { - // name - OUStringBuffer aBuf; - aBuf.appendAscii(STR_DB_GLOBAL_NONAME); - aBuf.append(++mnCounter); // 1-based, for entirely arbitrary reasons. The numbers are ignored on import. + if (meRangeType == ScDBCollection::GlobalAnonymous) + { + // name + OUStringBuffer aBuf; + aBuf.appendAscii(STR_DB_GLOBAL_NONAME); + aBuf.append(++mnCounter); // 1-based, for entirely arbitrary reasons. The numbers are ignored on import. - write(aBuf.makeStringAndClear(), rData); + write(aBuf.makeStringAndClear(), rData); + } + else if (meRangeType == ScDBCollection::GlobalNamed) + write(rData.GetName(), rData); } private: @@ -1075,11 +1093,6 @@ private: } } } - -private: - ScXMLExport& mrExport; - ScDocument* mpDoc; - sal_Int32 mnCounter; }; } @@ -1123,15 +1136,18 @@ void ScXMLExportDatabaseRanges::WriteDatabaseRanges() if (pDBCollection) { // Write global named ranges. + func.setRangeType(ScDBCollection::GlobalNamed); const ScDBCollection::NamedDBs& rNamedDBs = pDBCollection->getNamedDBs(); ::std::for_each(rNamedDBs.begin(), rNamedDBs.end(), func); // Add global anonymous DB ranges. + func.setRangeType(ScDBCollection::GlobalAnonymous); const ScDBCollection::AnonDBs& rAnonDBs = pDBCollection->getAnonDBs(); ::std::for_each(rAnonDBs.begin(), rAnonDBs.end(), func); } // Write sheet-local ranges. + func.setRangeType(ScDBCollection::SheetAnonymous); ::std::for_each(aSheetDBs.begin(), aSheetDBs.end(), func); } diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx index b9cea6aad..bef1205b3 100644 --- a/sc/source/filter/xml/xmldrani.cxx +++ b/sc/source/filter/xml/xmldrani.cxx @@ -151,7 +151,7 @@ ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( ScXMLImport& rImport, bFilterSkipDuplicates(false), bFilterUseRegularExpressions(false), bFilterConditionSourceRange(false), - meRangeType(GlobalNamed) + meRangeType(ScDBCollection::GlobalNamed) { nSourceType = sheet::DataImportMode_NONE; sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; @@ -223,9 +223,9 @@ ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( ScXMLImport& rImport, } if (sDatabaseRangeName.matchAsciiL(STR_DB_LOCAL_NONAME, strlen(STR_DB_LOCAL_NONAME))) - meRangeType = SheetAnonymous; + meRangeType = ScDBCollection::SheetAnonymous; else if (sDatabaseRangeName.matchAsciiL(STR_DB_GLOBAL_NONAME, strlen(STR_DB_GLOBAL_NONAME))) - meRangeType = GlobalAnonymous; + meRangeType = ScDBCollection::GlobalAnonymous; } ScXMLDatabaseRangeContext::~ScXMLDatabaseRangeContext() @@ -476,7 +476,7 @@ void ScXMLDatabaseRangeContext::EndElement() if (!pDoc) return; - if (meRangeType == SheetAnonymous) + if (meRangeType == ScDBCollection::SheetAnonymous) { OUString aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)); ::std::auto_ptr pData(ConvertToDBData(aName)); @@ -491,7 +491,7 @@ void ScXMLDatabaseRangeContext::EndElement() } return; } - else if (meRangeType == GlobalAnonymous) + else if (meRangeType == ScDBCollection::GlobalAnonymous) { OUString aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_GLOBAL_NONAME)); ::std::auto_ptr pData(ConvertToDBData(aName)); @@ -503,7 +503,7 @@ void ScXMLDatabaseRangeContext::EndElement() } return; } - else if (meRangeType == GlobalNamed) + else if (meRangeType == ScDBCollection::GlobalNamed) { ::std::auto_ptr pData(ConvertToDBData(sDatabaseRangeName)); diff --git a/sc/source/filter/xml/xmldrani.hxx b/sc/source/filter/xml/xmldrani.hxx index 80b65247b..0f4d9c6cb 100644 --- a/sc/source/filter/xml/xmldrani.hxx +++ b/sc/source/filter/xml/xmldrani.hxx @@ -39,6 +39,8 @@ #include #include +#include "dbcolect.hxx" + class ScDBData; class ScXMLImport; @@ -72,8 +74,6 @@ struct ScSubTotalRule class ScXMLDatabaseRangeContext : public SvXMLImportContext { - enum RangeType { GlobalNamed, GlobalAnonymous, SheetAnonymous }; - rtl::OUString sDatabaseRangeName; rtl::OUString sConnectionRessource; rtl::OUString sRangeAddress; @@ -109,7 +109,7 @@ class ScXMLDatabaseRangeContext : public SvXMLImportContext sal_Bool bFilterSkipDuplicates; sal_Bool bFilterUseRegularExpressions; sal_Bool bFilterConditionSourceRange; - RangeType meRangeType; + ScDBCollection::RangeType meRangeType; const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); } ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); } -- cgit v1.2.3