26#include <osl/file.hxx>
29#include <com/sun/star/beans/PropertyAttribute.hpp>
30#include <com/sun/star/beans/PropertyExistException.hpp>
31#include <com/sun/star/frame/XModel.hpp>
32#include <com/sun/star/sheet/XSheetCellRange.hpp>
33#include <com/sun/star/sheet/GlobalSheetSettings.hpp>
34#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
35#include <com/sun/star/sheet/XSpreadsheet.hpp>
36#include <com/sun/star/sheet/XDatabaseRange.hpp>
37#include <com/sun/star/system/SystemShellExecute.hpp>
38#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
39#include <com/sun/star/util/XCloneable.hpp>
41#include <document.hxx>
48#include <com/sun/star/script/vba/VBAEventId.hpp>
49#include <com/sun/star/script/vba/XVBACompatibility.hpp>
50#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
51#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
52#include <com/sun/star/script/ModuleInfo.hpp>
53#include <com/sun/star/script/ModuleType.hpp>
60uno::Reference< sheet::XUnnamedDatabaseRanges >
63 uno::Reference< frame::XModel >
xModel;
66 uno::Reference< beans::XPropertySet > xModelProps(
xModel, uno::UNO_QUERY_THROW );
67 uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( xModelProps->getPropertyValue(
"UnnamedDatabaseRanges"), uno::UNO_QUERY_THROW );
68 return xUnnamedDBRanges;
73uno::Reference< sheet::XDatabaseRange >
76 uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges(
GetUnnamedDataBaseRanges( pShell ), uno::UNO_SET_THROW );
77 uno::Reference< sheet::XDatabaseRange > xDataBaseRange;
78 if (xUnnamedDBRanges->hasByTable( nSheet ) )
80 uno::Reference< sheet::XDatabaseRange > xDBRange( xUnnamedDBRanges->getByTable( nSheet ) , uno::UNO_QUERY_THROW );
81 bool bHasAuto =
false;
82 uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW );
83 xProps->getPropertyValue(
"AutoFilter") >>= bHasAuto;
86 xDataBaseRange=xDBRange;
89 return xDataBaseRange;
94 ScCellRangesBase* pScCellRangesBase =
dynamic_cast<ScCellRangesBase*
>( xRange.get() );
95 if ( !pScCellRangesBase )
97 throw uno::RuntimeException(
"Failed to access underlying doc shell uno range object" );
99 return pScCellRangesBase->GetDocShell();
102uno::Reference< XHelperInterface >
105 uno::Reference< sheet::XSheetCellRange > xSheetRange( xRange, uno::UNO_QUERY_THROW );
106 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
110void implSetZoom(
const uno::Reference< frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs )
120class PasteCellsWarningReseter
125 static uno::Reference< sheet::XGlobalSheetSettings >
const & getGlobalSheetSettings()
132 static bool getReplaceCellsWarning()
134 return getGlobalSheetSettings()->getReplaceCellsWarning();
138 static void setReplaceCellsWarning(
bool bState )
140 getGlobalSheetSettings()->setReplaceCellsWarning( bState );
144 PasteCellsWarningReseter()
148 setReplaceCellsWarning(
false );
150 ~PasteCellsWarningReseter()
157 setReplaceCellsWarning(
true );
159 catch ( uno::Exception& ){}
169 PasteCellsWarningReseter resetWarningBox;
179implnCopy(
const uno::Reference< frame::XModel>& xModel )
183 if ( !(pViewShell && pDocShell) )
186 pViewShell->
CopyToClip(
nullptr,
false,
false,
true);
199implnCut(
const uno::Reference< frame::XModel>& xModel )
203 if ( !(pViewShell && pDocShell) )
220 PasteCellsWarningReseter resetWarningBox;
239 nFunction, bSkipEmpty, bTranspose,
false,
247getDocShell(
const css::uno::Reference< css::frame::XModel>& xModel )
249 uno::Reference< uno::XInterface > xIf(
xModel, uno::UNO_QUERY_THROW );
250 ScModelObj* pModel = comphelper::getFromUnoTunnel< ScModelObj >( xIf );
283uno::Reference< XHelperInterface >
286 uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW );
288 xProps->getPropertyValue(
"CodeName") >>= sCodeName;
297uno::Reference< XHelperInterface >
300 uno::Reference< container::XEnumerationAccess > xEnumAccess( xRanges, uno::UNO_QUERY_THROW );
301 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
302 uno::Reference< table::XCellRange > xRange( xEnum->nextElement(), uno::UNO_QUERY_THROW );
306uno::Reference< XHelperInterface >
309 uno::Reference< sheet::XSheetCellRange > xSheetRange( xCell, uno::UNO_QUERY_THROW );
310 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetRange->getSpreadsheet(), uno::UNO_SET_THROW );
314uno::Reference< XHelperInterface >
317 uno::Reference< sheet::XSpreadsheetDocument > xDoc(
xModel, uno::UNO_QUERY_THROW );
318 uno::Reference< container::XIndexAccess > xSheets( xDoc->getSheets(), uno::UNO_QUERY_THROW );
319 uno::Reference< sheet::XSpreadsheet > xSheet( xSheets->getByIndex( nTab ), uno::UNO_QUERY_THROW );
325 uno::Reference< frame::XModel >
xModel( xDoc, uno::UNO_QUERY );
330 OUString aPrjName(
"Standard" );
336 uno::Reference<script::XLibraryContainer> xLibContainer = pShell->
GetBasicContainer();
337 uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW );
338 xVBACompat->setVBACompatibilityMode(
true );
340 if( xLibContainer.is() )
342 if( !xLibContainer->hasByName( aPrjName ) )
343 xLibContainer->createLibrary( aPrjName );
344 uno::Any aLibAny = xLibContainer->getByName( aPrjName );
345 uno::Reference< container::XNameContainer > xLib;
349 uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW );
350 uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( pShell->
GetModel()->
createInstance(
"ooo.vba.VBAObjectModuleObjectProvider"), uno::UNO_QUERY_THROW );
355 if ( sCodeName.isEmpty() )
357 sCodeName =
"ThisWorkbook";
361 std::vector< OUString > sDocModuleNames { sCodeName };
367 sDocModuleNames.push_back(
aName );
370 for (
const auto& rName : sDocModuleNames )
372 script::ModuleInfo sModuleInfo;
374 uno::Any aName= xVBACodeNamedObjectAccess->getByName( rName );
375 sModuleInfo.ModuleObject.set(
aName, uno::UNO_QUERY );
376 sModuleInfo.ModuleType = script::ModuleType::DOCUMENT;
377 xVBAModuleInfo->insertModuleInfo( rName, sModuleInfo );
378 if( xLib->hasByName( rName ) )
379 xLib->replaceByName( rName,
uno::Any( OUString(
"Option VBASupport 1\n") ) );
381 xLib->insertByName( rName,
uno::Any( OUString(
"Option VBASupport 1\n" ) ) );
391 uno::Sequence< uno::Any > aArgs;
392 xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs );
394 catch( uno::Exception& )
400 const uno::Reference< frame::XModel >& xModel,
const css::uno::Reference< XApplication >& xApplication,
401 const css::uno::Any&
Type,
const css::uno::Any& FileName,
const css::uno::Any& Quality,
402 const css::uno::Any& IncludeDocProperties,
const css::uno::Any& From,
403 const css::uno::Any& To,
const css::uno::Any& OpenAfterPublish)
414 FileName >>= sFileName;
416 osl::FileBase::getFileURLFromSystemPath(sFileName, sRelURL);
431 OUString sWorkPath = xApplication->getDefaultFilePath();
433 osl::FileBase::getFileURLFromSystemPath(sWorkPath, sWorkURL);
434 aURL.SetURL(sWorkURL);
438 if (!sFileName.isEmpty())
445 if (
aURL.removeExtension())
446 aURL.setExtension(
u"pdf");
458 OUString sRange(
"-");
460 css::uno::Sequence<css::beans::PropertyValue> aFilterData;
464 sRange = OUString::number(nFrom) + sRange;
466 sRange += OUString::number(nTo);
468 aFilterData.realloc(aFilterData.getLength() + 1);
473 if (Quality >>= sQuality)
475 if (sQuality.equalsIgnoreAsciiCase(
u"xlQualityMinimum") || sQuality ==
"1")
477 aFilterData.realloc(aFilterData.getLength() + 1);
480 else if (sQuality.equalsIgnoreAsciiCase(
u"xlQualityStandard") || sQuality ==
"0")
482 aFilterData.realloc(aFilterData.getLength() + 1);
494 css::uno::Sequence<css::beans::PropertyValue> storeProps{
500 bool bIncludeDocProperties =
true;
501 if ((IncludeDocProperties >>= bIncludeDocProperties) && !bIncludeDocProperties)
503 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
xModel, uno::UNO_QUERY);
506 uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
507 uno::Reference<util::XCloneable> xCloneable(xDocProps, uno::UNO_QUERY_THROW);
508 uno::Reference<document::XDocumentProperties> xOldDocProps(xCloneable->createClone(), uno::UNO_QUERY_THROW);
511 xDocProps->resetUserData(OUString());
513 uno::Reference< frame::XStorable > xStor(
xModel, uno::UNO_QUERY_THROW);
515 xStor->storeToURL(sURL, storeProps);
517 catch (
const uno::Exception&)
528 uno::Reference< frame::XStorable > xStor(
xModel, uno::UNO_QUERY_THROW);
529 xStor->storeToURL(sURL, storeProps);
532 bool bOpenAfterPublish =
false;
533 if ((OpenAfterPublish >>= bOpenAfterPublish) && bOpenAfterPublish)
535 uno::Reference<css::system::XSystemShellExecute> xSystemShellExecute(css::system::SystemShellExecute::create(::comphelper::getProcessComponentContext()));
541 const uno::Reference< frame::XModel >& xModel,
542 const uno::Reference< css::document::XDocumentProperties>& i_xOldDocProps)
544 uno::Reference<document::XDocumentPropertiesSupplier>
const
545 xModelDocPropsSupplier(
xModel, uno::UNO_QUERY_THROW);
546 uno::Reference<document::XDocumentProperties>
const xDocPropsToFill =
547 xModelDocPropsSupplier->getDocumentProperties();
548 uno::Reference< beans::XPropertySet >
const xPropSet(
549 i_xOldDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
551 uno::Reference< util::XModifiable > xModifiable(
xModel, uno::UNO_QUERY);
552 if (!xModifiable.is())
553 throw uno::RuntimeException();
555 bool bIsModified = xModifiable->isModified();
559 uno::Reference< beans::XPropertySet >
const xSet(
560 xDocPropsToFill->getUserDefinedProperties(), uno::UNO_QUERY);
561 uno::Reference< beans::XPropertyContainer > xContainer(xSet, uno::UNO_QUERY);
562 uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
563 const uno::Sequence< beans::Property > lProps = xSetInfo->getProperties();
564 for (
const beans::Property& rProp : lProps)
566 uno::Any aValue = xPropSet->getPropertyValue(rProp.Name);
567 if (rProp.Attributes & css::beans::PropertyAttribute::REMOVABLE)
572 xContainer->addProperty(rProp.Name, rProp.Attributes, aValue);
574 catch (beans::PropertyExistException
const&) {}
578 xSet->setPropertyValue(rProp.Name, aValue);
580 catch (
const uno::Exception&) {}
585 xDocPropsToFill->setAuthor(i_xOldDocProps->getAuthor());
586 xDocPropsToFill->setGenerator(i_xOldDocProps->getGenerator());
587 xDocPropsToFill->setCreationDate(i_xOldDocProps->getCreationDate());
588 xDocPropsToFill->setTitle(i_xOldDocProps->getTitle());
589 xDocPropsToFill->setSubject(i_xOldDocProps->getSubject());
590 xDocPropsToFill->setDescription(i_xOldDocProps->getDescription());
591 xDocPropsToFill->setKeywords(i_xOldDocProps->getKeywords());
592 xDocPropsToFill->setModifiedBy(i_xOldDocProps->getModifiedBy());
593 xDocPropsToFill->setModificationDate(i_xOldDocProps->getModificationDate());
594 xDocPropsToFill->setPrintedBy(i_xOldDocProps->getPrintedBy());
595 xDocPropsToFill->setPrintDate(i_xOldDocProps->getPrintDate());
596 xDocPropsToFill->setAutoloadURL(i_xOldDocProps->getAutoloadURL());
597 xDocPropsToFill->setAutoloadSecs(i_xOldDocProps->getAutoloadSecs());
598 xDocPropsToFill->setDefaultTarget(i_xOldDocProps->getDefaultTarget());
599 xDocPropsToFill->setEditingCycles(i_xOldDocProps->getEditingCycles());
600 xDocPropsToFill->setEditingDuration(i_xOldDocProps->getEditingDuration());
602 catch (
const uno::Exception&) {}
605 if (bIsModified !=
bool(xModifiable->isModified()))
606 xModifiable->setModified(bIsModified);
612 return pRangeObj ? pRangeObj->GetCurrentDataSet(
true ) :
nullptr;
void SetName(const OUString &rName)
static OUString GetAbsURL(std::u16string_view rTheBaseURIRef, OUString const &rTheRelURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
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()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
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)
void ExportAsFixedFormatHelper(const uno::Reference< frame::XModel > &xModel, const css::uno::Reference< XApplication > &xApplication, const css::uno::Any &Type, const css::uno::Any &FileName, const css::uno::Any &Quality, const css::uno::Any &IncludeDocProperties, const css::uno::Any &From, const css::uno::Any &To, const css::uno::Any &OpenAfterPublish)
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)
void SetDocInfoState(const uno::Reference< frame::XModel > &xModel, const uno::Reference< css::document::XDocumentProperties > &i_xOldDocProps)
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