25 #include <com/sun/star/frame/XModel.hpp>
26 #include <com/sun/star/sheet/XSheetCellRange.hpp>
27 #include <com/sun/star/sheet/GlobalSheetSettings.hpp>
28 #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
29 #include <com/sun/star/sheet/XSpreadsheet.hpp>
30 #include <com/sun/star/sheet/XDatabaseRange.hpp>
32 #include <document.hxx>
39 #include <com/sun/star/script/vba/VBAEventId.hpp>
40 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
41 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
42 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
43 #include <com/sun/star/script/ModuleInfo.hpp>
44 #include <com/sun/star/script/ModuleType.hpp>
51 uno::Reference< sheet::XUnnamedDatabaseRanges >
54 uno::Reference< frame::XModel >
xModel;
56 xModel.set( pShell->
GetModel(), uno::UNO_SET_THROW );
57 uno::Reference< beans::XPropertySet > xModelProps( xModel, uno::UNO_QUERY_THROW );
58 uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( xModelProps->getPropertyValue(
"UnnamedDatabaseRanges"), uno::UNO_QUERY_THROW );
59 return xUnnamedDBRanges;
64 uno::Reference< sheet::XDatabaseRange >
67 uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges(
GetUnnamedDataBaseRanges( pShell ), uno::UNO_SET_THROW );
68 uno::Reference< sheet::XDatabaseRange > xDataBaseRange;
69 if (xUnnamedDBRanges->hasByTable( nSheet ) )
71 uno::Reference< sheet::XDatabaseRange > xDBRange( xUnnamedDBRanges->getByTable( nSheet ) , uno::UNO_QUERY_THROW );
72 bool bHasAuto =
false;
73 uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW );
74 xProps->getPropertyValue(
"AutoFilter") >>= bHasAuto;
77 xDataBaseRange=xDBRange;
80 return xDataBaseRange;
85 ScCellRangesBase* pScCellRangesBase = comphelper::getUnoTunnelImplementation<ScCellRangesBase>( xRange );
86 if ( !pScCellRangesBase )
88 throw uno::RuntimeException(
"Failed to access underlying doc shell uno range object" );
93 uno::Reference< XHelperInterface >
96 uno::Reference< sheet::XSheetCellRange > xSheetRange( xRange, uno::UNO_QUERY_THROW );
97 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
101 void implSetZoom(
const uno::Reference< frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs )
111 class PasteCellsWarningReseter
116 static uno::Reference< sheet::XGlobalSheetSettings >
const & getGlobalSheetSettings()
123 static bool getReplaceCellsWarning()
125 return getGlobalSheetSettings()->getReplaceCellsWarning();
129 static void setReplaceCellsWarning(
bool bState )
131 getGlobalSheetSettings()->setReplaceCellsWarning( bState );
135 PasteCellsWarningReseter()
137 bInitialWarningState = getReplaceCellsWarning();
138 if ( bInitialWarningState )
139 setReplaceCellsWarning(
false );
141 ~PasteCellsWarningReseter()
143 if ( bInitialWarningState )
148 setReplaceCellsWarning(
true );
150 catch ( uno::Exception& ){}
160 PasteCellsWarningReseter resetWarningBox;
170 implnCopy(
const uno::Reference< frame::XModel>& xModel )
174 if ( !(pViewShell && pDocShell) )
177 pViewShell->
CopyToClip(
nullptr,
false,
false,
true);
190 implnCut(
const uno::Reference< frame::XModel>& xModel )
194 if ( !(pViewShell && pDocShell) )
211 PasteCellsWarningReseter resetWarningBox;
215 if ( !(pTabViewShell && pDocShell) )
227 nFunction, bSkipEmpty, bTranspose,
false,
235 getDocShell(
const css::uno::Reference< css::frame::XModel>& xModel )
237 uno::Reference< uno::XInterface > xIf( xModel, uno::UNO_QUERY_THROW );
271 uno::Reference< XHelperInterface >
274 uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW );
276 xProps->getPropertyValue(
"CodeName") >>= sCodeName;
285 uno::Reference< XHelperInterface >
288 uno::Reference< container::XEnumerationAccess > xEnumAccess( xRanges, uno::UNO_QUERY_THROW );
289 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
290 uno::Reference< table::XCellRange > xRange( xEnum->nextElement(), uno::UNO_QUERY_THROW );
294 uno::Reference< XHelperInterface >
297 uno::Reference< sheet::XSheetCellRange > xSheetRange( xCell, uno::UNO_QUERY_THROW );
298 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
302 uno::Reference< XHelperInterface >
305 uno::Reference< sheet::XSpreadsheetDocument > xDoc( xModel, uno::UNO_QUERY_THROW );
306 uno::Reference< container::XIndexAccess > xSheets( xDoc->getSheets(), uno::UNO_QUERY_THROW );
307 uno::Reference< sheet::XSpreadsheet > xSheet( xSheets->getByIndex( nTab ), uno::UNO_QUERY_THROW );
313 uno::Reference< frame::XModel >
xModel( xDoc, uno::UNO_QUERY );
318 OUString aPrjName(
"Standard" );
324 uno::Reference<script::XLibraryContainer> xLibContainer = pShell->
GetBasicContainer();
325 uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW );
326 xVBACompat->setVBACompatibilityMode(
true );
328 if( xLibContainer.is() )
330 if( !xLibContainer->hasByName( aPrjName ) )
331 xLibContainer->createLibrary( aPrjName );
332 uno::Any aLibAny = xLibContainer->getByName( aPrjName );
333 uno::Reference< container::XNameContainer > xLib;
337 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW );
338 uno::Reference< lang::XMultiServiceFactory> xSF( pShell->
GetModel(), uno::UNO_QUERY_THROW);
339 uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance(
"ooo.vba.VBAObjectModuleObjectProvider"), uno::UNO_QUERY_THROW );
344 if ( sCodeName.isEmpty() )
346 sCodeName =
"ThisWorkbook";
347 rDoc.SetCodeName( sCodeName );
350 std::vector< OUString > sDocModuleNames;
351 sDocModuleNames.push_back( sCodeName );
356 rDoc.GetCodeName(
index, aName );
357 sDocModuleNames.push_back( aName );
360 for (
const auto& rName : sDocModuleNames )
362 script::ModuleInfo sModuleInfo;
364 uno::Any aName= xVBACodeNamedObjectAccess->getByName( rName );
365 sModuleInfo.ModuleObject.set( aName, uno::UNO_QUERY );
366 sModuleInfo.ModuleType = script::ModuleType::DOCUMENT;
367 xVBAModuleInfo->insertModuleInfo( rName, sModuleInfo );
368 if( xLib->hasByName( rName ) )
369 xLib->replaceByName( rName, uno::makeAny( OUString(
"Option VBASupport 1\n") ) );
371 xLib->insertByName( rName, uno::makeAny( OUString(
"Option VBASupport 1\n" ) ) );
381 uno::Sequence< uno::Any > aArgs;
382 xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs );
384 catch( uno::Exception& )
SfxViewFrame * GetViewFrame() const
void setUpDocumentModules(const uno::Reference< sheet::XSpreadsheetDocument > &xDoc)
SC_DLLPUBLIC bool CopyToClip(ScDocument *pClipDoc, bool bCut, bool bApi=false, bool bIncludeObjects=false, bool bStopEdit=true)
uno::Reference< sheet::XUnnamedDatabaseRanges > GetUnnamedDataBaseRanges(const ScDocShell *pShell)
SC_DLLPUBLIC void RefreshZoom()
ScDocShell * GetDocShell() const
const css::uno::Reference< css::script::vba::XVBAEventProcessor > & GetVbaEventProcessor() const
ScDocShell * GetDocShellFromRange(const uno::Reference< uno::XInterface > &xRange)
css::uno::Reference< css::datatransfer::XTransferable2 > const & GetClipData() const
uno::Reference< XHelperInterface > getUnoDocModule(std::u16string_view aModName, SfxObjectShell const *pShell)
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
css::uno::Reference< css::frame::XModel > GetModel() const
void implnCopy(const uno::Reference< frame::XModel > &xModel)
bool bInitialWarningState
static SfxItemSet * GetDataSet(ScCellRangesBase *pRangeObj)
SC_DLLPUBLIC void CutToClip()
Not used?
uno::Reference< XHelperInterface > getUnoSheetModuleObj(const uno::Reference< table::XCellRange > &xRange)
void SetClipData(const css::uno::Reference< css::datatransfer::XTransferable2 > &xTransferable)
ScDocument * GetDocument() const
SC_DLLPUBLIC void PasteFromSystem()
ScViewData & GetViewData()
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
SfxObjectShell * GetEmbeddedObject() const
SfxViewFrame * getViewFrame(const uno::Reference< frame::XModel > &xModel)
SfxItemSet * GetCurrentDataSet(bool bNoDflt=false)
ScGridWindow * GetActiveWin()
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmpty=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
void implnCut(const uno::Reference< frame::XModel > &xModel)
uno::Reference< sheet::XDatabaseRange > GetAutoFiltRange(const ScDocShell *pShell, sal_Int16 nSheet)
ScTabViewShell * getBestViewShell(const css::uno::Reference< css::frame::XModel > &xModel)
void implnPasteSpecial(const uno::Reference< frame::XModel > &xModel, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bTranspose)
ScTabViewShell * getCurrentBestViewShell(const uno::Reference< uno::XComponentContext > &xContext)
SC_DLLPUBLIC void SetUseInApi(bool bSet)
static SC_DLLPUBLIC ScTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Reference< XComponentContext > getProcessComponentContext()
const ScDocument & GetDocument() const
uno::Reference< frame::XModel > getCurrentExcelDoc(const uno::Reference< uno::XComponentContext > &xContext)
void implnPaste(const uno::Reference< frame::XModel > &xModel)
void SetZoom(const Fraction &rNewX, const Fraction &rNewY, std::vector< SCTAB > &tabs)
Reference< XModel > xModel
const OUString & GetCodeName() const
ScTabViewShell * GetBestViewShell(bool bOnlyVisible=true)
void implSetZoom(const uno::Reference< frame::XModel > &xModel, sal_Int16 nZoom, std::vector< SCTAB > &nTabs)
SC_DLLPUBLIC void CellContentChanged()
BasicManager * GetBasicManager() const
css::uno::Reference< css::script::XLibraryContainer > GetBasicContainer()
void SetName(const OUString &rName)