diff options
author | Laurent Godard <lgodard.libre@laposte.net> | 2011-11-21 17:32:13 +0100 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-11-23 15:28:36 -0500 |
commit | 2ee55872ebc5aeb71041c3267d9b3baa9607b85b (patch) | |
tree | 37e4a75499cb58da715b6b46e363c30a76a3ba74 /sc | |
parent | 364a3d2864973935b2cd18b328392d1b556456dd (diff) |
importSheet from an external provided document
define a new interface XSpreadsheets2
clean some String in docuno.cxx while i'm at it.
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/docuno.hxx | 11 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 59 | ||||
-rw-r--r-- | sc/xml/ScTableSheetsObj.xml | 1 |
3 files changed, 59 insertions, 12 deletions
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index 5c5ad863b140..1ca0d7165dd1 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -44,6 +44,7 @@ #include <com/sun/star/sheet/XScenarios.hpp> #include <com/sun/star/sheet/XConsolidatable.hpp> #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets2.hpp> #include <com/sun/star/sheet/XDocumentAuditing.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/util/XProtectable.hpp> @@ -371,7 +372,7 @@ public: class ScTableSheetsObj : public cppu::WeakImplHelper5< - com::sun::star::sheet::XSpreadsheets, + com::sun::star::sheet::XSpreadsheets2, com::sun::star::sheet::XCellRangesAccess, com::sun::star::container::XEnumerationAccess, com::sun::star::container::XIndexAccess, @@ -399,6 +400,14 @@ public: const ::rtl::OUString& aCopy, sal_Int16 nDestination ) throw(::com::sun::star::uno::RuntimeException); + // XSpreadsheets2 + virtual sal_Int32 SAL_CALL importSheet( + const ::com::sun::star::uno::Reference < + ::com::sun::star::sheet::XSpreadsheetDocument > & xDocSrc, + const rtl::OUString& srcName, + const sal_Int32 nDestPosition) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + // XCellRangesAccess virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 46f94f8d52e7..95632e613611 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -2433,8 +2433,7 @@ ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const rtl::OUString& aNa if (pDocShell) { SCTAB nIndex; - String aString(aName); - if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) ) return new ScTableSheetObj( pDocShell, nIndex ); } return NULL; @@ -2462,9 +2461,8 @@ void SAL_CALL ScTableSheetsObj::moveByName( const rtl::OUString& aName, sal_Int1 sal_Bool bDone = false; if (pDocShell) { - String aNamStr(aName); SCTAB nSource; - if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nSource ) ) bDone = pDocShell->MoveTable( nSource, nDestination, false, sal_True ); } if (!bDone) @@ -2479,10 +2477,9 @@ void SAL_CALL ScTableSheetsObj::copyByName( const rtl::OUString& aName, sal_Bool bDone = false; if (pDocShell) { - String aNamStr(aName); String aNewStr(aCopy); SCTAB nSource; - if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nSource ) ) { bDone = pDocShell->MoveTable( nSource, nDestination, sal_True, sal_True ); if (bDone) @@ -2572,14 +2569,14 @@ void SAL_CALL ScTableSheetsObj::replaceByName( const rtl::OUString& aName, const ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface ); if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt? { - String aNamStr(aName); SCTAB nPosition; - if ( pDocShell->GetDocument()->GetTable( aNamStr, nPosition ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nPosition ) ) { ScDocFunc aFunc(*pDocShell); if ( aFunc.DeleteTable( nPosition, sal_True, sal_True ) ) { // InsertTable kann jetzt eigentlich nicht schiefgehen... + String aNamStr(aName); bDone = aFunc.InsertTable( nPosition, aNamStr, sal_True, sal_True ); if (bDone) pSheetObj->InitInsertSheet( pDocShell, nPosition ); @@ -2616,8 +2613,7 @@ void SAL_CALL ScTableSheetsObj::removeByName( const rtl::OUString& aName ) if (pDocShell) { SCTAB nIndex; - String aString(aName); - if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) ) { ScDocFunc aFunc(*pDocShell); bDone = aFunc.DeleteTable( nIndex, sal_True, sal_True ); @@ -2633,6 +2629,47 @@ void SAL_CALL ScTableSheetsObj::removeByName( const rtl::OUString& aName ) throw uno::RuntimeException(); // NoSuchElementException is handled above } +sal_Int32 ScTableSheetsObj::importSheet( + const uno::Reference < sheet::XSpreadsheetDocument > & xDocSrc, + const rtl::OUString& srcName, const sal_Int32 nDestPosition ) + throw( lang::IllegalArgumentException, uno::RuntimeException ) +{ + //pDocShell is the destination + ScDocument* pDocDest = pDocShell->GetDocument(); + + // Source document docShell + if ( !xDocSrc.is() ) + throw uno::RuntimeException(); + ScModelObj* pObj = ScModelObj::getImplementation(xDocSrc); + ScDocShell* pDocShellSrc = static_cast<ScDocShell*>(pObj->GetEmbeddedObject()); + + SCTAB nIndexDest; + nIndexDest = -1; + + // SourceSheet Position and does srcName exists ? + SCTAB nIndexSrc; + if ( !pDocShellSrc->GetDocument()->GetTable( srcName, nIndexSrc ) ) + throw lang::IllegalArgumentException(); + + // control nDestPosition < maxtab + SCTAB nCount = pDocDest->GetTableCount(); + nIndexDest = static_cast<SCTAB>(nDestPosition); + if ( nIndexDest > nCount ) + nIndexDest = nCount; + + // control nDestPosition > 0 + if ( nIndexDest < 0) + nIndexDest = 0; + + // Transfert Tab + bool bInsertNew = true; + bool bNotifyAndPaint = true; + pDocShell->TransferTab( + *pDocShellSrc, nIndexSrc, nIndexDest, bInsertNew, bNotifyAndPaint ); + + return nIndexDest; +} + // XCellRangesAccess uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet ) @@ -2772,7 +2809,7 @@ sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const rtl::OUString& aName ) if (pDocShell) { SCTAB nIndex; - if ( pDocShell->GetDocument()->GetTable( String(aName), nIndex ) ) + if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) ) return sal_True; } return false; diff --git a/sc/xml/ScTableSheetsObj.xml b/sc/xml/ScTableSheetsObj.xml index e17cbb012671..2a7d8dd339d2 100644 --- a/sc/xml/ScTableSheetsObj.xml +++ b/sc/xml/ScTableSheetsObj.xml @@ -216,6 +216,7 @@ <type>com.sun.star.sheet.XSpreadsheet</type> <type>com.sun.star.sheet.XSpreadsheetDocument</type> <type>com.sun.star.sheet.XSpreadsheets</type> + <type>com.sun.star.sheet.XSpreadsheets2</type> <type>com.sun.star.sheet.XSubTotalCalculatable</type> <type>com.sun.star.sheet.XSubTotalDescriptor</type> <type>com.sun.star.sheet.XSubTotalField</type> |