summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-04-15 13:52:40 +0100
committerNoel Power <noel.power@novell.com>2011-04-15 15:00:23 +0100
commitf96c5afd276287d896760e11542918e679069b8c (patch)
treec2fdad725cd02b46ea6e796584d98c5ae91a35ac
parentfe8e63ab25a53799fe79a89ee865f03fe2fdf45d (diff)
fix for fdo#34763 add method Copy to ScVbaWorksheets
-rw-r--r--sc/source/ui/vba/vbaworksheet.cxx117
-rw-r--r--sc/source/ui/vba/vbaworksheet.hxx2
-rw-r--r--sc/source/ui/vba/vbaworksheets.cxx39
-rw-r--r--sc/source/ui/vba/vbaworksheets.hxx1
4 files changed, 110 insertions, 49 deletions
diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx
index 9348f928f..f3c5bb18e 100644
--- a/sc/source/ui/vba/vbaworksheet.cxx
+++ b/sc/source/ui/vba/vbaworksheet.cxx
@@ -229,6 +229,72 @@ const uno::Sequence<sal_Int8>& ScVbaWorksheet::getUnoTunnelId()
return aSeq;
}
+uno::Reference< ov::excel::XWorksheet >
+ScVbaWorksheet::createSheetCopyInNewDoc(rtl::OUString aCurrSheetName)
+{
+ uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
+ uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
+ uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
+ uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
+ if (xRange.is())
+ xRange->Select();
+ excel::implnCopy(mxModel);
+ uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
+ if (xModel.is())
+ {
+ excel::implnPaste(xModel);
+ }
+ uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
+ uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
+ uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
+ //#TODO #FIXME
+ //get proper parent for Worksheet
+ return new ScVbaWorksheet( NULL, mxContext, xSheet, xModel );
+}
+
+css::uno::Reference< ov::excel::XWorksheet >
+ScVbaWorksheet::createSheetCopy(uno::Reference<excel::XWorksheet> xSheet, bool bAfter)
+{
+ rtl::OUString aCurrSheetName = getName();
+ ScVbaWorksheet* pDestSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
+
+ uno::Reference <sheet::XSpreadsheetDocument> xDestDoc( pDestSheet->getModel(), uno::UNO_QUERY );
+ uno::Reference <sheet::XSpreadsheetDocument> xSrcDoc( getModel(), uno::UNO_QUERY );
+
+ SCTAB nDest = 0;
+ SCTAB nSrc = 0;
+ rtl::OUString aSheetName = xSheet->getName();
+ bool bSameDoc = ( pDestSheet->getModel() == getModel() );
+ bool bDestSheetExists = ScVbaWorksheets::nameExists (xDestDoc, aSheetName, nDest );
+ bool bSheetExists = ScVbaWorksheets::nameExists (xSrcDoc, aCurrSheetName, nSrc );
+
+ // set sheet name to be newSheet name
+ aSheetName = aCurrSheetName;
+ if ( bSheetExists && bDestSheetExists )
+ {
+ SCTAB nDummy=0;
+ if(bAfter)
+ nDest++;
+ uno::Reference<sheet::XSpreadsheets> xSheets = xDestDoc->getSheets();
+ if ( bSameDoc || ScVbaWorksheets::nameExists( xDestDoc, aCurrSheetName, nDummy ) )
+ getNewSpreadsheetName(aSheetName,aCurrSheetName,xDestDoc);
+ if ( bSameDoc )
+ xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
+ else
+ {
+ ScDocShell* pDestDocShell = excel::getDocShell( pDestSheet->getModel() );
+ ScDocShell* pSrcDocShell = excel::getDocShell( getModel() );
+ if ( pDestDocShell && pSrcDocShell )
+ pDestDocShell->TransferTab( *pSrcDocShell, static_cast<SCTAB>(nSrc), static_cast<SCTAB>(nDest), true, true );
+ }
+ }
+ // return new sheet
+ uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
+ uno::Reference< excel::XWorksheet > xNewSheet( xApplication->Worksheets( uno::makeAny( aSheetName ) ), uno::UNO_QUERY_THROW );
+ return xNewSheet;
+}
+
::rtl::OUString
ScVbaWorksheet::getName() throw (uno::RuntimeException)
{
@@ -571,60 +637,13 @@ void
ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException)
{
uno::Reference<excel::XWorksheet> xSheet;
- rtl::OUString aCurrSheetName =getName();
if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
{
- uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
- uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
- uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
- uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
- if (xRange.is())
- xRange->Select();
- excel::implnCopy(mxModel);
- uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
- if (xModel.is())
- {
- excel::implnPaste(xModel);
- }
+ createSheetCopyInNewDoc(getName());
return;
}
- ScVbaWorksheet* pDestSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
-
- uno::Reference <sheet::XSpreadsheetDocument> xDestDoc( pDestSheet->getModel(), uno::UNO_QUERY );
- uno::Reference <sheet::XSpreadsheetDocument> xSrcDoc( getModel(), uno::UNO_QUERY );
-
- SCTAB nDest = 0;
- SCTAB nSrc = 0;
- rtl::OUString aSheetName = xSheet->getName();
- bool bSameDoc = ( pDestSheet->getModel() == getModel() );
- bool bDestSheetExists = ScVbaWorksheets::nameExists (xDestDoc, aSheetName, nDest );
- bool bSheetExists = ScVbaWorksheets::nameExists (xSrcDoc, aCurrSheetName, nSrc );
-
- // set sheet name to be newSheet name
- aSheetName = aCurrSheetName;
- if ( bSheetExists && bDestSheetExists )
- {
- SCTAB nDummy=0;
- sal_Bool bAfter = After.hasValue();
- if(bAfter)
- nDest++;
- uno::Reference<sheet::XSpreadsheets> xSheets = xDestDoc->getSheets();
- if ( bSameDoc || ScVbaWorksheets::nameExists( xDestDoc, aCurrSheetName, nDummy ) )
- getNewSpreadsheetName(aSheetName,aCurrSheetName,xDestDoc);
- if ( bSameDoc )
- xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
- else
- {
- ScDocShell* pDestDocShell = excel::getDocShell( pDestSheet->getModel() );
- ScDocShell* pSrcDocShell = excel::getDocShell( getModel() );
- if ( pDestDocShell && pSrcDocShell )
- pDestDocShell->TransferTab( *pSrcDocShell, static_cast<SCTAB>(nSrc), static_cast<SCTAB>(nDest), true, true );
- }
- }
- // active the new sheet
- uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
- uno::Reference< excel::XWorksheet > xNewSheet( xApplication->Worksheets( uno::makeAny( aSheetName ) ), uno::UNO_QUERY_THROW );
+ uno::Reference<excel::XWorksheet> xNewSheet = createSheetCopy(xSheet, After.hasValue());
xNewSheet->Activate();
}
diff --git a/sc/source/ui/vba/vbaworksheet.hxx b/sc/source/ui/vba/vbaworksheet.hxx
index b852b60fb..c9a24255b 100644
--- a/sc/source/ui/vba/vbaworksheet.hxx
+++ b/sc/source/ui/vba/vbaworksheet.hxx
@@ -91,6 +91,8 @@ public:
virtual css::uno::Reference< css::sheet::XSpreadsheet > getSheet()
{ return mxSheet; }
static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
+ css::uno::Reference< ov::excel::XWorksheet > createSheetCopyInNewDoc( rtl::OUString);
+ css::uno::Reference< ov::excel::XWorksheet > createSheetCopy(css::uno::Reference< ov::excel::XWorksheet> xSheet, bool bAfter);
// Attributes
virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException);
diff --git a/sc/source/ui/vba/vbaworksheets.cxx b/sc/source/ui/vba/vbaworksheets.cxx
index 1a0784860..be278b9db 100644
--- a/sc/source/ui/vba/vbaworksheets.cxx
+++ b/sc/source/ui/vba/vbaworksheets.cxx
@@ -55,6 +55,8 @@
#include "vbaworkbook.hxx"
#include "unonames.hxx"
+#include <vector>
+
using namespace ::ooo::vba;
using namespace ::com::sun::star;
@@ -420,6 +422,43 @@ ScVbaWorksheets::Select( const uno::Any& Replace ) throw (uno::RuntimeException)
}
+void SAL_CALL
+ScVbaWorksheets::Copy ( const uno::Any& Before, const uno::Any& After) throw (css::uno::RuntimeException)
+{
+ uno::Reference<excel::XWorksheet> xSheet;
+ sal_Int32 nElems = getCount();
+ bool bAfter = After.hasValue();
+ std::vector< uno::Reference< excel::XWorksheet > > Sheets;
+ sal_Int32 nItem = 0;
+
+ for ( nItem = 1; nItem <= nElems; ++nItem)
+ {
+ uno::Reference<excel::XWorksheet> xWorksheet(Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW );
+ Sheets.push_back(xWorksheet);
+ }
+ bool bNewDoc = (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()));
+
+ uno::Reference< excel::XWorksheet > xSrcSheet;
+ if ( bNewDoc )
+ {
+ bAfter = true;
+ xSrcSheet = Sheets.at(0);
+ ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
+ xSheet = pSrcSheet->createSheetCopyInNewDoc(xSrcSheet->getName());
+ nItem = 1;
+ }
+
+ for (nItem = 0; nItem < nElems; ++nItem )
+ {
+ xSrcSheet = Sheets[nItem];
+ ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
+ if ( bAfter )
+ xSheet = pSrcSheet->createSheetCopy(xSheet, bAfter);
+ else
+ pSrcSheet->createSheetCopy(xSheet, bAfter);
+ }
+}
+
//ScVbaCollectionBaseImpl
uno::Any SAL_CALL
ScVbaWorksheets::Item( const uno::Any& Index, const uno::Any& Index2 ) throw (uno::RuntimeException)
diff --git a/sc/source/ui/vba/vbaworksheets.hxx b/sc/source/ui/vba/vbaworksheets.hxx
index 82001c0d7..d215cfa0b 100644
--- a/sc/source/ui/vba/vbaworksheets.hxx
+++ b/sc/source/ui/vba/vbaworksheets.hxx
@@ -72,6 +72,7 @@ public:
virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::uno::RuntimeException);
virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource );
virtual void SAL_CALL Select( const css::uno::Any& Replace ) throw (css::uno::RuntimeException);
+ virtual void SAL_CALL Copy ( const css::uno::Any& Before, const css::uno::Any& After) throw (css::uno::RuntimeException);
// ScVbaWorksheets_BASE
virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& Index2 ) throw
(css::uno::RuntimeException);