26#include <com/sun/star/frame/XModel.hpp>
27#include <com/sun/star/sheet/XSheetCellRange.hpp>
28#include <com/sun/star/sheet/GlobalSheetSettings.hpp>
29#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
30#include <com/sun/star/sheet/XSpreadsheet.hpp>
31#include <com/sun/star/sheet/XDatabaseRange.hpp>
33#include <document.hxx>
40#include <com/sun/star/script/vba/VBAEventId.hpp>
41#include <com/sun/star/script/vba/XVBACompatibility.hpp>
42#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
43#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
44#include <com/sun/star/script/ModuleInfo.hpp>
45#include <com/sun/star/script/ModuleType.hpp>
52uno::Reference< sheet::XUnnamedDatabaseRanges >
55 uno::Reference< frame::XModel >
xModel;
58 uno::Reference< beans::XPropertySet > xModelProps(
xModel, uno::UNO_QUERY_THROW );
59 uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( xModelProps->getPropertyValue(
"UnnamedDatabaseRanges"), uno::UNO_QUERY_THROW );
60 return xUnnamedDBRanges;
65uno::Reference< sheet::XDatabaseRange >
68 uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges(
GetUnnamedDataBaseRanges( pShell ), uno::UNO_SET_THROW );
69 uno::Reference< sheet::XDatabaseRange > xDataBaseRange;
70 if (xUnnamedDBRanges->hasByTable( nSheet ) )
72 uno::Reference< sheet::XDatabaseRange > xDBRange( xUnnamedDBRanges->getByTable( nSheet ) , uno::UNO_QUERY_THROW );
73 bool bHasAuto =
false;
74 uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW );
75 xProps->getPropertyValue(
"AutoFilter") >>= bHasAuto;
78 xDataBaseRange=xDBRange;
81 return xDataBaseRange;
86 ScCellRangesBase* pScCellRangesBase =
dynamic_cast<ScCellRangesBase*
>( xRange.get() );
87 if ( !pScCellRangesBase )
89 throw uno::RuntimeException(
"Failed to access underlying doc shell uno range object" );
91 return pScCellRangesBase->GetDocShell();
94uno::Reference< XHelperInterface >
97 uno::Reference< sheet::XSheetCellRange > xSheetRange( xRange, uno::UNO_QUERY_THROW );
98 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
102void implSetZoom(
const uno::Reference< frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs )
112class PasteCellsWarningReseter
117 static uno::Reference< sheet::XGlobalSheetSettings >
const & getGlobalSheetSettings()
124 static bool getReplaceCellsWarning()
126 return getGlobalSheetSettings()->getReplaceCellsWarning();
130 static void setReplaceCellsWarning(
bool bState )
132 getGlobalSheetSettings()->setReplaceCellsWarning( bState );
136 PasteCellsWarningReseter()
140 setReplaceCellsWarning(
false );
142 ~PasteCellsWarningReseter()
149 setReplaceCellsWarning(
true );
151 catch ( uno::Exception& ){}
161 PasteCellsWarningReseter resetWarningBox;
171implnCopy(
const uno::Reference< frame::XModel>& xModel )
175 if ( !(pViewShell && pDocShell) )
178 pViewShell->
CopyToClip(
nullptr,
false,
false,
true);
191implnCut(
const uno::Reference< frame::XModel>& xModel )
195 if ( !(pViewShell && pDocShell) )
212 PasteCellsWarningReseter resetWarningBox;
231 nFunction, bSkipEmpty, bTranspose,
false,
239getDocShell(
const css::uno::Reference< css::frame::XModel>& xModel )
241 uno::Reference< uno::XInterface > xIf(
xModel, uno::UNO_QUERY_THROW );
242 ScModelObj* pModel = comphelper::getFromUnoTunnel< ScModelObj >( xIf );
275uno::Reference< XHelperInterface >
278 uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW );
280 xProps->getPropertyValue(
"CodeName") >>= sCodeName;
289uno::Reference< XHelperInterface >
292 uno::Reference< container::XEnumerationAccess > xEnumAccess( xRanges, uno::UNO_QUERY_THROW );
293 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
294 uno::Reference< table::XCellRange > xRange( xEnum->nextElement(), uno::UNO_QUERY_THROW );
298uno::Reference< XHelperInterface >
301 uno::Reference< sheet::XSheetCellRange > xSheetRange( xCell, uno::UNO_QUERY_THROW );
302 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
306uno::Reference< XHelperInterface >
309 uno::Reference< sheet::XSpreadsheetDocument > xDoc(
xModel, uno::UNO_QUERY_THROW );
310 uno::Reference< container::XIndexAccess > xSheets( xDoc->getSheets(), uno::UNO_QUERY_THROW );
311 uno::Reference< sheet::XSpreadsheet > xSheet( xSheets->getByIndex( nTab ), uno::UNO_QUERY_THROW );
317 uno::Reference< frame::XModel >
xModel( xDoc, uno::UNO_QUERY );
322 OUString aPrjName(
"Standard" );
328 uno::Reference<script::XLibraryContainer> xLibContainer = pShell->
GetBasicContainer();
329 uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW );
330 xVBACompat->setVBACompatibilityMode(
true );
332 if( xLibContainer.is() )
334 if( !xLibContainer->hasByName( aPrjName ) )
335 xLibContainer->createLibrary( aPrjName );
336 uno::Any aLibAny = xLibContainer->getByName( aPrjName );
337 uno::Reference< container::XNameContainer > xLib;
341 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW );
342 uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( pShell->
GetModel()->
createInstance(
"ooo.vba.VBAObjectModuleObjectProvider"), uno::UNO_QUERY_THROW );
347 if ( sCodeName.isEmpty() )
349 sCodeName =
"ThisWorkbook";
353 std::vector< OUString > sDocModuleNames { sCodeName };
359 sDocModuleNames.push_back(
aName );
362 for (
const auto& rName : sDocModuleNames )
364 script::ModuleInfo sModuleInfo;
366 uno::Any aName= xVBACodeNamedObjectAccess->getByName( rName );
367 sModuleInfo.ModuleObject.set(
aName, uno::UNO_QUERY );
368 sModuleInfo.ModuleType = script::ModuleType::DOCUMENT;
369 xVBAModuleInfo->insertModuleInfo( rName, sModuleInfo );
370 if( xLib->hasByName( rName ) )
371 xLib->replaceByName( rName,
uno::Any( OUString(
"Option VBASupport 1\n") ) );
373 xLib->insertByName( rName,
uno::Any( OUString(
"Option VBASupport 1\n" ) ) );
383 uno::Sequence< uno::Any > aArgs;
384 xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs );
386 catch( uno::Exception& )
394 return pRangeObj ? pRangeObj->GetCurrentDataSet(
true ) :
nullptr;
void SetClipData(const css::uno::Reference< css::datatransfer::XTransferable2 > &xTransferable)
const ScDocument & GetDocument() const
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
ScModelObj * GetModel() const
void SetCodeName(const OUString &r)
const css::uno::Reference< css::script::vba::XVBAEventProcessor > & GetVbaEventProcessor() const
const OUString & GetCodeName() const
SC_DLLPUBLIC SCTAB GetTableCount() const
SfxObjectShell * GetEmbeddedObject() const
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(const OUString &aServiceSpecifier) override
XMultiServiceFactory.
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
SC_DLLPUBLIC void RefreshZoom()
ScViewData & GetViewData()
SC_DLLPUBLIC void CellContentChanged()
ScDocument * GetDocument() const
static SC_DLLPUBLIC ScTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
SC_DLLPUBLIC void SetUseInApi(bool bSet)
ScGridWindow * GetActiveWin()
void SetZoom(const Fraction &rNewX, const Fraction &rNewY, std::vector< SCTAB > &tabs)
SC_DLLPUBLIC void CutToClip()
SC_DLLPUBLIC void PasteFromSystem()
SC_DLLPUBLIC bool CopyToClip(ScDocument *pClipDoc, bool bCut, bool bApi=false, bool bIncludeObjects=false, bool bStopEdit=true)
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmptyCells=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
css::uno::Reference< css::script::XLibraryContainer > GetBasicContainer()
BasicManager * GetBasicManager() const
SfxViewFrame * GetViewFrame() const
static SfxItemSet * GetDataSet(ScCellRangesBase *pRangeObj)
bool bInitialWarningState
Reference< XComponentContext > getProcessComponentContext()
ScDocShell * GetDocShellFromRange(const uno::Reference< uno::XInterface > &xRange)
ScTabViewShell * getCurrentBestViewShell(const uno::Reference< uno::XComponentContext > &xContext)
void setUpDocumentModules(const uno::Reference< sheet::XSpreadsheetDocument > &xDoc)
uno::Reference< sheet::XUnnamedDatabaseRanges > GetUnnamedDataBaseRanges(const ScDocShell *pShell)
void implnCut(const uno::Reference< frame::XModel > &xModel)
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
void implnPasteSpecial(const uno::Reference< frame::XModel > &xModel, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bTranspose)
SfxViewFrame * getViewFrame(const uno::Reference< frame::XModel > &xModel)
void implnPaste(const uno::Reference< frame::XModel > &xModel)
ScTabViewShell * getBestViewShell(const css::uno::Reference< css::frame::XModel > &xModel)
void implSetZoom(const uno::Reference< frame::XModel > &xModel, sal_Int16 nZoom, std::vector< SCTAB > &nTabs)
uno::Reference< sheet::XDatabaseRange > GetAutoFiltRange(const ScDocShell *pShell, sal_Int16 nSheet)
void implnCopy(const uno::Reference< frame::XModel > &xModel)
uno::Reference< XHelperInterface > getUnoSheetModuleObj(const uno::Reference< table::XCellRange > &xRange)
uno::Reference< frame::XModel > getCurrentExcelDoc(const uno::Reference< uno::XComponentContext > &xContext)
uno::Reference< XHelperInterface > getUnoDocModule(std::u16string_view aModName, SfxObjectShell const *pShell)
Reference< XModel > xModel