25#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26#include <com/sun/star/container/XEnumerationAccess.hpp>
27#include <com/sun/star/sheet/XSpreadsheet.hpp>
28#include <com/sun/star/container/XNamed.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30#include <com/sun/star/script/XTypeConverter.hpp>
32#include <ooo/vba/excel/XApplication.hpp>
48typedef std::vector< uno::Reference< sheet::XSpreadsheet > >
SheetMap;
55class WorkSheetsEnumeration :
public ::cppu::WeakImplHelper< container::XEnumeration >
58 SheetMap::iterator mIt;
60 explicit WorkSheetsEnumeration(
SheetMap&& sMap ) : mSheetMap( std::move(sMap) ), mIt( mSheetMap.begin() ) {}
61 virtual sal_Bool SAL_CALL hasMoreElements( )
override
63 return ( mIt != mSheetMap.end() );
65 virtual uno::Any SAL_CALL nextElement( )
override
67 if ( !hasMoreElements() )
68 throw container::NoSuchElementException();
69 uno::Reference< sheet::XSpreadsheet > xSheet( *mIt++ );
74class SheetCollectionHelper :
public ::cppu::WeakImplHelper< container::XNameAccess,
75 container::XIndexAccess,
76 container::XEnumerationAccess >
79 SheetMap::iterator cachePos;
81 explicit SheetCollectionHelper(
SheetMap&& sMap ) : mSheetMap( std::move(sMap) ), cachePos(mSheetMap.begin()) {}
84 virtual sal_Bool SAL_CALL hasElements( )
override {
return ( !mSheetMap.empty() ); }
86 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
88 if ( !hasByName(
aName) )
89 throw container::NoSuchElementException();
92 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
94 uno::Sequence< OUString > sNames( mSheetMap.size() );
95 OUString* pString = sNames.getArray();
97 for (
const auto& rItem : mSheetMap )
99 uno::Reference< container::XNamed > xName( rItem, uno::UNO_QUERY_THROW );
100 *pString = xName->getName();
105 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override
107 cachePos = mSheetMap.begin();
108 SheetMap::iterator it_end = mSheetMap.end();
109 for ( ; cachePos != it_end; ++cachePos )
111 uno::Reference< container::XNamed > xName( *cachePos, uno::UNO_QUERY_THROW );
112 if (
aName == xName->getName() )
115 return ( cachePos != it_end );
119 virtual ::sal_Int32 SAL_CALL getCount( )
override {
return mSheetMap.size(); }
120 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
123 throw lang::IndexOutOfBoundsException();
129 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
131 return new WorkSheetsEnumeration( std::vector(mSheetMap) );
137 uno::Reference< frame::XModel >
m_xModel;
140 SheetsEnumeration(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration, uno::Reference< frame::XModel >
xModel ) :
EnumerationHelperImpl( xParent, xContext, xEnumeration ),
m_xModel(std::move(
xModel )) {}
142 virtual uno::Any SAL_CALL nextElement( )
override
144 uno::Reference< sheet::XSpreadsheet > xSheet( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
178uno::Reference< container::XEnumeration >
183 uno::Reference< container::XEnumerationAccess > xAccess(
m_xIndexAccess, uno::UNO_QUERY_THROW );
184 return xAccess->createEnumeration();
186 uno::Reference< container::XEnumerationAccess > xEnumAccess(
m_xSheets, uno::UNO_QUERY_THROW );
187 return new SheetsEnumeration(
this,
mxContext, xEnumAccess->createEnumeration(),
mxModel );
193 uno::Reference< sheet::XSpreadsheet > xSheet( aSource, uno::UNO_QUERY );
216 OUString aStringSheet;
218 SCTAB nSheetIndex = 0;
220 Count >>= nNewSheets;
224 uno::Reference< excel::XWorksheet > xBeforeAfterSheet;
228 if (
Before >>= xBeforeAfterSheet )
229 aStringSheet = xBeforeAfterSheet->getName();
234 if (aStringSheet.isEmpty() && After.
hasValue() )
236 if ( After >>= xBeforeAfterSheet )
237 aStringSheet = xBeforeAfterSheet->getName();
239 After >>= aStringSheet;
242 if (aStringSheet.isEmpty())
244 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
245 aStringSheet = xApplication->getActiveWorkbook()->getActiveSheet()->getName();
251 uno::Reference< sheet::XSpreadsheet > xSheet(
m_xIndexAccess->getByIndex(
i), uno::UNO_QUERY);
252 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
253 if (xNamed->getName() == aStringSheet)
264 OUString aStringBase(
"Sheet" );
266 for (
SCTAB i=0;
i < nNewSheets;
i++, nSheetName++)
268 OUString aStringName = aStringBase + OUString::number(nSheetName);
272 aStringName = aStringBase + OUString::number(nSheetName);
274 m_xSheets->insertNewByName(aStringName, nSheetIndex +
i);
277 uno::Reference< excel::XWorksheet > xNewSheet(
result, uno::UNO_QUERY );
278 if ( xNewSheet.is() )
279 xNewSheet->Activate();
291 for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem )
293 uno::Reference< excel::XWorksheet > xSheet(
Item(
uno::Any( nItem ),
uno::Any() ), uno::UNO_QUERY_THROW );
309 bool bSelection =
false;
313 if ( !( nFrom || nTo ) )
324 uno::Reference< container::XEnumeration > xEnum(
createEnumeration(), uno::UNO_SET_THROW );
325 while ( xEnum->hasMoreElements() )
327 uno::Reference< excel::XWorksheet > xSheet( xEnum->nextElement(), uno::UNO_QUERY_THROW );
328 if ( xSheet->getVisible() == 0 )
341 if ( !(_visible >>= bState) )
342 throw uno::RuntimeException(
"Visible property doesn't support non boolean #FIXME" );
344 uno::Reference< container::XEnumeration > xEnum(
createEnumeration(), uno::UNO_SET_THROW );
345 while ( xEnum->hasMoreElements() )
347 uno::Reference< excel::XWorksheet > xSheet( xEnum->nextElement(), uno::UNO_QUERY_THROW );
348 xSheet->setVisible( bState ? 1 : 0 );
358 throw uno::RuntimeException(
"Cannot obtain view shell" );
361 bool bReplace =
true;
366 bool bSelectSingle = bReplace;
368 for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem )
370 uno::Reference< excel::XWorksheet > xSheet(
Item(
uno::Any( nItem ),
uno::Any() ), uno::UNO_QUERY_THROW );
371 ScVbaWorksheet* pSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
375 bSelectSingle =
false;
386 uno::Reference<excel::XWorksheet> xSheet;
389 std::vector< uno::Reference< excel::XWorksheet > >
Sheets;
392 for ( nItem = 1; nItem <= nElems; ++nItem)
394 uno::Reference<excel::XWorksheet> xWorksheet(
Item(
uno::Any( nItem ),
uno::Any() ), uno::UNO_QUERY_THROW );
395 Sheets.push_back(xWorksheet);
397 bool bNewDoc = (!(
Before >>= xSheet) && !(After >>=xSheet)&& !(
Before.hasValue()) && !(After.
hasValue()));
399 uno::Reference< excel::XWorksheet > xSrcSheet;
404 ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
413 for (; nItem < nElems; ++nItem )
415 xSrcSheet =
Sheets[nItem];
416 ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
428 if (
Index.getValueTypeClass() == uno::TypeClass_SEQUENCE )
433 uno::Sequence< uno::Any > sIndices;
434 aConverted >>= sIndices;
435 for(
const auto& rIndex : std::as_const(sIndices) )
438 ScVbaWorksheet* pWorkSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xWorkSheet );
439 uno::Reference< sheet::XSpreadsheet > xSheet( pWorkSheet->
getSheet() , uno::UNO_SET_THROW );
440 uno::Reference< container::XNamed > xName( xSheet, uno::UNO_QUERY_THROW );
441 aSheets.push_back( xSheet );
443 uno::Reference< container::XIndexAccess > xIndexAccess =
new SheetCollectionHelper( std::move(aSheets) );
453 return "ScVbaWorksheets";
456css::uno::Sequence<OUString>
459 static uno::Sequence< OUString >
const sNames
461 "ooo.vba.excel.Worksheets"
468 if (!xSpreadDoc.is())
469 throw lang::IllegalArgumentException(
"nameExists() xSpreadDoc is null", uno::Reference< uno::XInterface >(), 1 );
470 uno::Reference <container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
476 uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(
i), uno::UNO_QUERY_THROW );
477 if (xNamed->getName() ==
name)
512 for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem )
514 uno::Reference< excel::XWorksheet > xSheet(
Item(
uno::Any( nItem ),
uno::Any() ), uno::UNO_QUERY_THROW );
515 ScVbaWorksheet* pSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
Reference< XComponentContext > m_xContext
css::uno::Reference< css::frame::XModel2 > mxModel
EnumerationHelperImpl(const css::uno::Reference< ov::XHelperInterface > &xParent, css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Reference< css::container::XEnumeration > xEnumeration)
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any SAL_CALL Application() override
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
ScSheetLimits & GetSheetLimits() const
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
void SelectTable(SCTAB nTab, bool bNew)
void SelectOneTable(SCTAB nTab)
void SetSelectedTabs(const MarkedTabsType &rTabs)
std::set< SCTAB > MarkedTabsType
SC_DLLPUBLIC void SetPageNo(tools::Long nPage)
SC_DLLPUBLIC void SetSelectedTabs(const ScMarkData &rMark)
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
SC_DLLPUBLIC tools::Long GetFirstPage(SCTAB nTab)
const ScMarkData::MarkedTabsType & GetSelectedTabs() const
ScViewData & GetViewData()
css::uno::Reference< css::container::XNameAccess > m_xNameAccess
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual ::sal_Int32 SAL_CALL getCount() override
virtual css::uno::Any getItemByStringIndex(const OUString &sIndex)
sal_Int16 getSheetID() const
css::uno::Reference< ov::excel::XWorksheet > createSheetCopyInNewDoc(const OUString &)
css::uno::Reference< ov::excel::XWorksheet > createSheetCopy(css::uno::Reference< ov::excel::XWorksheet > const &xSheet, bool bAfter)
const css::uno::Reference< css::sheet::XSpreadsheet > & getSheet() const
ScVbaWorksheets(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xSheets, css::uno::Reference< css::frame::XModel > xModel)
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL Copy(const css::uno::Any &Before, const css::uno::Any &After) override
virtual void SAL_CALL Select(const css::uno::Any &Replace) override
virtual void SAL_CALL setVisible(const css::uno::Any &_visible) override
virtual OUString getServiceImplName() override
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) override
static bool nameExists(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xSpreadDoc, std::u16string_view name, SCTAB &nTab)
bool isSelectedSheets() const
virtual void SAL_CALL PrintPreview(const css::uno::Any &EnableChanges) override
virtual css::uno::Any SAL_CALL getVisible() override
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &Before, const css::uno::Any &After, const css::uno::Any &Count, const css::uno::Any &Type) override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual void SAL_CALL Delete() override
css::uno::Reference< css::frame::XModel > mxModel
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Reference< css::sheet::XSpreadsheets > m_xSheets
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &Index2) override
ScMarkData & GetMarkData()
ScDocument & GetDocument() const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
SfxFrame & GetFrame() const
SfxViewFrame & GetViewFrame() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Get(const css::uno::Reference< css::frame::XController > &i_rController)
css::uno::Type const & get()
Reference< frame::XModel > m_xModel
Reference< XTypeConverter > xConverter
ScTabViewShell * getBestViewShell(const css::uno::Reference< css::frame::XModel > &xModel)
uno::Reference< XHelperInterface > getUnoSheetModuleObj(const uno::Reference< table::XCellRange > &xRange)
VBAHELPER_DLLPUBLIC void PrintOutHelper(SfxViewShell const *pViewShell, 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, bool bSelection)
void WaitUntilPreviewIsClosed(SfxViewFrame *pViewFrame)
VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > const & getTypeConverter(const css::uno::Reference< css::uno::XComponentContext > &xContext)
void dispatchExecute(SfxViewShell const *pViewShell, sal_uInt16 nSlot)
Reference< XModel > xModel
std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets
std::vector< uno::Reference< sheet::XSpreadsheet > > SheetMap