[Libreoffice-commits] .: 2 commits - oox/inc oox/source sc/inc sc/source
Markus Mohrhard
mmohrhard at kemper.freedesktop.org
Thu Oct 27 14:55:23 PDT 2011
oox/inc/oox/xls/workbookhelper.hxx | 8 ++++++++
oox/source/xls/defnamesbuffer.cxx | 11 ++++-------
oox/source/xls/workbookhelper.cxx | 37 +++++++++++++++++++++++++++++++++++++
sc/inc/nameuno.hxx | 10 ++++++----
sc/source/ui/unoobj/nameuno.cxx | 21 +++++++++++----------
5 files changed, 66 insertions(+), 21 deletions(-)
New commits:
commit 67315dcfb0664a35fdd34f86242452bc27df6105
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Oct 27 23:53:34 2011 +0200
use uno for local range name api, it crashs otherwise sometimes
diff --git a/sc/inc/nameuno.hxx b/sc/inc/nameuno.hxx
index 9d7ca93..c082226 100644
--- a/sc/inc/nameuno.hxx
+++ b/sc/inc/nameuno.hxx
@@ -38,6 +38,7 @@
#include <com/sun/star/sheet/XNamedRange.hpp>
#include <com/sun/star/sheet/XFormulaTokens.hpp>
#include <com/sun/star/sheet/XNamedRanges.hpp>
+#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/lang/XServiceName.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
@@ -69,7 +70,7 @@ private:
ScNamedRangesObj* mpParent;
ScDocShell* pDocShell;
String aName;
- ScTableSheetObj* mpSheet;
+ com::sun::star::uno::Reference< com::sun::star::container::XNamed > mxSheet;
private:
ScRangeData* GetRangeData_Impl();
@@ -80,7 +81,8 @@ private:
SCTAB GetTab_Impl();
public:
- ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm, ScTableSheetObj* pSheet = NULL);
+ ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm,
+ com::sun::star::uno::Reference< com::sun::star::container::XNamed > xSheet = com::sun::star::uno::Reference< com::sun::star::container::XNamed > ());
virtual ~ScNamedRangeObj();
virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
@@ -337,9 +339,9 @@ private:
virtual ScRangeName* GetRangeName_Impl();
virtual SCTAB GetTab_Impl();
- ScTableSheetObj* mpSheet;
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed > mxSheet;
public:
- ScLocalNamedRangesObj(ScDocShell* pDocSh, ScTableSheetObj* pSheet);
+ ScLocalNamedRangesObj(ScDocShell* pDocSh, ::com::sun::star::uno::Reference< com::sun::star::container::XNamed > xNamed );
virtual ~ScLocalNamedRangesObj();
};
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index 3726eb7..7e9a52d 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -99,11 +99,11 @@ bool lcl_UserVisibleName(const ScRangeData& rData)
return !rData.HasType(RT_DATABASE) && !rData.HasType(RT_SHARED);
}
-ScNamedRangeObj::ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm, ScTableSheetObj* pSheet) :
+ScNamedRangeObj::ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm, Reference<container::XNamed> xSheet):
mpParent(pParent),
pDocShell( pDocSh ),
aName( rNm ),
- mpSheet( pSheet )
+ mxSheet( xSheet )
{
pDocShell->GetDocument()->AddUnoObject(*this);
}
@@ -147,13 +147,14 @@ ScRangeData* ScNamedRangeObj::GetRangeData_Impl()
SCTAB ScNamedRangeObj::GetTab_Impl()
{
- if (mpSheet)
+ if (mxSheet.is())
{
if (!pDocShell)
return -2;
ScDocument* pDoc = pDocShell->GetDocument();
SCTAB nTab;
- pDoc->GetTable(mpSheet->getName(), nTab);
+ rtl::OUString sName = mxSheet->getName();
+ pDoc->GetTable(sName, nTab);
return nTab;
}
else
@@ -922,9 +923,9 @@ SCTAB ScGlobalNamedRangesObj::GetTab_Impl()
//------------------------------------------------------------------------
-ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell* pDocSh, ScTableSheetObj* pSheet )
+ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell* pDocSh, uno::Reference<container::XNamed> xSheet )
: ScNamedRangesObj(pDocSh),
- mpSheet(pSheet)
+ mxSheet(xSheet)
{
}
@@ -937,7 +938,7 @@ ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName)
{
if ( pDocShell && hasByName( aName ) )
- return new ScNamedRangeObj( this, pDocShell, String(aName), mpSheet);
+ return new ScNamedRangeObj( this, pDocShell, String(aName), mxSheet);
return NULL;
}
@@ -947,7 +948,7 @@ ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex
if (!pDocShell)
return NULL;
- rtl::OUString aName = mpSheet->getName();
+ rtl::OUString aName = mxSheet->getName();
ScDocument* pDoc = pDocShell->GetDocument();
SCTAB nTab;
pDoc->GetTable( aName, nTab );
@@ -963,7 +964,7 @@ ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex
if (lcl_UserVisibleName(*itr))
{
if (nPos == nIndex)
- return new ScNamedRangeObj(this, pDocShell, itr->GetName(), mpSheet);
+ return new ScNamedRangeObj(this, pDocShell, itr->GetName(), mxSheet);
}
++nPos;
}
@@ -979,7 +980,7 @@ ScRangeName* ScLocalNamedRangesObj::GetRangeName_Impl()
SCTAB ScLocalNamedRangesObj::GetTab_Impl()
{
SCTAB nTab;
- pDocShell->GetDocument()->GetTable(mpSheet->getName(), nTab);
+ pDocShell->GetDocument()->GetTable(mxSheet->getName(), nTab);
return nTab;
}
commit 35896a678b004a84bafc54fd3e08dfc97a0d4886
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Oct 27 23:52:35 2011 +0200
add xlsx local range name import
diff --git a/oox/inc/oox/xls/workbookhelper.hxx b/oox/inc/oox/xls/workbookhelper.hxx
index bb9a3d2..e0310b8 100644
--- a/oox/inc/oox/xls/workbookhelper.hxx
+++ b/oox/inc/oox/xls/workbookhelper.hxx
@@ -192,6 +192,14 @@ public:
::rtl::OUString& orName,
sal_Int32 nNameFlags = 0 ) const;
+ /** Creates and returns a defined name on-the-fly in the sheet.
+ The name will not be buffered in the global defined names buffer.
+ @param orName (in/out-parameter) Returns the resulting used name. */
+ ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange >
+ createLocalNamedRangeObject(
+ ::rtl::OUString& orName,
+ sal_Int32 nNameFlags = 0, sal_Int32 nTab = -1 ) const;
+
/** Creates and returns a database range on-the-fly in the Calc document.
The range will not be buffered in the global table buffer.
@param orName (in/out-parameter) Returns the resulting used name. */
diff --git a/oox/source/xls/defnamesbuffer.cxx b/oox/source/xls/defnamesbuffer.cxx
index fce1bfb..e2319ca 100644
--- a/oox/source/xls/defnamesbuffer.cxx
+++ b/oox/source/xls/defnamesbuffer.cxx
@@ -489,12 +489,6 @@ void DefinedName::createNameObject()
maCalcName = isBuiltinName() ? lclGetPrefixedName( mcBuiltinId ) : maModel.maName;
// #163146# do not rename sheet-local names by default, this breaks VBA scripts
-#if 0
- // append sheet index for local names in multi-sheet documents
- if( isWorkbookFile() && !isGlobalName() )
- maCalcName = OUStringBuffer( maCalcName ).append( sal_Unicode( '_' ) ).
- append( static_cast< sal_Int32 >( mnCalcSheet + 1 ) ).makeStringAndClear();
-#endif
// special flags for this name
sal_Int32 nNameFlags = 0;
@@ -507,7 +501,10 @@ void DefinedName::createNameObject()
}
// create the name and insert it into the document, maCalcName will be changed to the resulting name
- mxNamedRange = createNamedRangeObject( maCalcName, nNameFlags );
+ if (maModel.mnSheet >= 0)
+ mxNamedRange = createLocalNamedRangeObject( maCalcName, nNameFlags, maModel.mnSheet );
+ else
+ mxNamedRange = createNamedRangeObject( maCalcName, nNameFlags );
// index of this defined name used in formula token arrays
PropertySet aPropSet( mxNamedRange );
aPropSet.getProperty( mnTokenIndex, PROP_TokenIndex );
diff --git a/oox/source/xls/workbookhelper.cxx b/oox/source/xls/workbookhelper.cxx
index 3c45aeb..3cc56cd 100644
--- a/oox/source/xls/workbookhelper.cxx
+++ b/oox/source/xls/workbookhelper.cxx
@@ -41,6 +41,7 @@
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/table/CellAddress.hpp>
+#include <com/sun/star/container/XNamed.hpp>
#include <osl/thread.h>
#include "oox/drawingml/theme.hxx"
#include "oox/helper/progressbar.hxx"
@@ -68,6 +69,8 @@
#include "oox/xls/workbooksettings.hxx"
#include "oox/xls/worksheetbuffer.hxx"
+#include <iostream>
+
namespace oox {
namespace xls {
@@ -140,6 +143,8 @@ public:
Reference< XStyle > getStyleObject( const OUString& rStyleName, bool bPageStyle ) const;
/** Creates and returns a defined name on-the-fly in the Calc document. */
Reference< XNamedRange > createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const;
+ /** Creates and returns a defined name on the-fly in the correct Calc sheet. */
+ Reference< XNamedRange > createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const;
/** Creates and returns a database range on-the-fly in the Calc document. */
Reference< XDatabaseRange > createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const;
/** Creates and returns an unnamed database range on-the-fly in the Calc document. */
@@ -378,6 +383,33 @@ Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orNa
return xNamedRange;
}
+Reference< XNamedRange > WorkbookGlobals::createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const
+{
+ // create the name and insert it into the Calc document
+ Reference< XNamedRange > xNamedRange;
+ if( orName.getLength() > 0 ) try
+ {
+ // find an unused name
+ Reference< XIndexAccess > xSheets(mxDoc->getSheets(), UNO_QUERY_THROW);
+ Reference< XSpreadsheet > xSheet (xSheets->getByIndex(nTab), UNO_QUERY_THROW);
+ Reference< com::sun::star::container::XNamed > xNamed(xSheet, UNO_QUERY_THROW);
+ rtl::OUString aName = xNamed->getName();
+ std::cout << "sheetName: " << rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
+ PropertySet aSheetProps( xSheet );
+ Reference< XNamedRanges > xNamedRanges( aSheetProps.getAnyProperty( PROP_NamedRanges ), UNO_QUERY_THROW );
+ Reference< XNameAccess > xNameAccess( xNamedRanges, UNO_QUERY_THROW );
+ orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' );
+ // create the named range
+ xNamedRanges->addNewByName( orName, OUString(), CellAddress( 0, 0, 0 ), nNameFlags );
+ xNamedRange.set( xNamedRanges->getByName( orName ), UNO_QUERY );
+ }
+ catch( Exception& )
+ {
+ }
+ OSL_ENSURE( xNamedRange.is(), "WorkbookGlobals::createLocalNamedRangeObject - cannot create defined name" );
+ return xNamedRange;
+}
+
Reference< XDatabaseRange > WorkbookGlobals::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const
{
// validate cell range
@@ -773,6 +805,11 @@ Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orNam
return mrBookGlob.createNamedRangeObject( orName, nNameFlags );
}
+Reference< XNamedRange > WorkbookHelper::createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const
+{
+ return mrBookGlob.createLocalNamedRangeObject( orName, nNameFlags, nTab );
+}
+
Reference< XDatabaseRange > WorkbookHelper::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const
{
return mrBookGlob.createDatabaseRangeObject( orName, rRangeAddr );
More information about the Libreoffice-commits
mailing list