fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbaworksheet.cxx
blobd60e10a25dff66990f1da1324fd6bf583d6a0b9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vbahelper/helperdecl.hxx>
21 #include <cppuhelper/queryinterface.hxx>
23 #include "vbaworksheet.hxx"
24 #include "vbanames.hxx"
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/beans/XIntrospectionAccess.hpp>
28 #include <com/sun/star/beans/XIntrospection.hpp>
29 #include <com/sun/star/container/XNamed.hpp>
30 #include <com/sun/star/util/XProtectable.hpp>
31 #include <com/sun/star/table/XCellRange.hpp>
32 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
33 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
34 #include <com/sun/star/sheet/XCalculatable.hpp>
35 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
36 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
37 #include <com/sun/star/sheet/XSheetCellRange.hpp>
38 #include <com/sun/star/sheet/XSheetCellCursor.hpp>
39 #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
40 #include <com/sun/star/sheet/XUsedAreaCursor.hpp>
41 #include <com/sun/star/sheet/XSpreadsheets.hpp>
42 #include <com/sun/star/sheet/XSheetPastable.hpp>
43 #include <com/sun/star/sheet/XCellAddressable.hpp>
44 #include <com/sun/star/sheet/XSheetOutline.hpp>
45 #include <com/sun/star/sheet/XSheetPageBreak.hpp>
46 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
47 #include <com/sun/star/sheet/XNamedRanges.hpp>
48 #include <com/sun/star/util/XURLTransformer.hpp>
49 #include <com/sun/star/frame/XDispatchProvider.hpp>
50 #include <com/sun/star/frame/Desktop.hpp>
51 #include <com/sun/star/table/XColumnRowRange.hpp>
52 #include <com/sun/star/table/XTableChartsSupplier.hpp>
53 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
54 #include <com/sun/star/drawing/XControlShape.hpp>
55 #include <com/sun/star/form/FormComponentType.hpp>
56 #include <com/sun/star/form/XFormsSupplier.hpp>
57 #include <ooo/vba/excel/XlEnableSelection.hpp>
58 #include <ooo/vba/excel/XlSheetVisibility.hpp>
59 #include <ooo/vba/excel/XWorkbook.hpp>
60 #include <ooo/vba/XControlProvider.hpp>
62 #include <comphelper/processfactory.hxx>
63 #include <comphelper/servicehelper.hxx>
64 #include <vbahelper/vbashapes.hxx>
66 #include <com/sun/star/script/vba/VBAEventId.hpp>
67 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
68 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
69 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
70 #include <com/sun/star/script/ModuleInfo.hpp>
71 #include <com/sun/star/script/ModuleType.hpp>
73 //zhangyun showdataform
74 #include <sfx2/sfxdlg.hxx>
75 #include "scabstdlg.hxx"
76 #include "tabvwsh.hxx"
77 #include "scitems.hxx"
79 #include <svx/svdouno.hxx>
80 #include <svx/svdpage.hxx>
82 #include "cellsuno.hxx"
83 #include "drwlayer.hxx"
84 #include "tabprotection.hxx"
85 #include "scextopt.hxx"
86 #include "vbaoutline.hxx"
87 #include "vbarange.hxx"
88 #include "vbacomments.hxx"
89 #include "vbachartobjects.hxx"
90 #include "vbapivottables.hxx"
91 #include "vbaoleobject.hxx"
92 #include "vbaoleobjects.hxx"
93 #include "vbapagesetup.hxx"
94 #include "vbapagebreaks.hxx"
95 #include "vbaworksheets.hxx"
96 #include "vbahyperlinks.hxx"
97 #include "vbasheetobjects.hxx"
98 #include "markdata.hxx"
99 #include "dbdata.hxx"
101 #include "attrib.hxx"
103 #define STANDARDWIDTH 2267
104 #define STANDARDHEIGHT 427
106 using namespace com::sun::star;
107 using namespace ooo::vba;
109 static void getNewSpreadsheetName (OUString &aNewName, const OUString& aOldName, uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc )
111 if (!xSpreadDoc.is())
112 throw lang::IllegalArgumentException( "getNewSpreadsheetName() xSpreadDoc is null", uno::Reference< uno::XInterface >(), 1 );
113 static const char aUnderScore[] = "_";
114 int currentNum =2;
115 aNewName = aOldName + aUnderScore + OUString::number(currentNum) ;
116 SCTAB nTab = 0;
117 while ( ScVbaWorksheets::nameExists(xSpreadDoc,aNewName, nTab ) )
119 aNewName = aOldName + aUnderScore + OUString::number(++currentNum);
123 static void removeAllSheets( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, const OUString& aSheetName)
125 if (!xSpreadDoc.is())
126 throw lang::IllegalArgumentException( "removeAllSheets() xSpreadDoc is null", uno::Reference< uno::XInterface >(), 1 );
127 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
128 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
130 if ( xIndex.is() )
132 uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
133 for (sal_Int32 i = xIndex->getCount() -1; i>= 1; i--)
135 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY);
136 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
137 if (xNamed.is())
139 xNameContainer->removeByName(xNamed->getName());
143 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY);
144 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
145 if (xNamed.is())
147 xNamed->setName(aSheetName);
152 static uno::Reference<frame::XModel>
153 openNewDoc(const OUString& aSheetName )
155 uno::Reference<frame::XModel> xModel;
158 uno::Reference< uno::XComponentContext > xContext(
159 comphelper::getProcessComponentContext() );
161 uno::Reference <frame::XDesktop2 > xComponentLoader = frame::Desktop::create(xContext);
163 uno::Reference<lang::XComponent > xComponent( xComponentLoader->loadComponentFromURL(
164 OUString( "private:factory/scalc" ),
165 OUString( "_blank" ), 0,
166 uno::Sequence < ::com::sun::star::beans::PropertyValue >() ) );
167 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xComponent, uno::UNO_QUERY_THROW );
168 if ( xSpreadDoc.is() )
170 removeAllSheets(xSpreadDoc,aSheetName);
172 xModel.set(xSpreadDoc,uno::UNO_QUERY_THROW);
174 catch ( uno::Exception & /*e*/ )
177 return xModel;
180 ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
181 const uno::Reference< sheet::XSpreadsheet >& xSheet,
182 const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel), mbVeryHidden( false )
186 ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args,
187 uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException, uno::RuntimeException ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false )
189 if ( args.getLength() < 3 )
190 throw lang::IllegalArgumentException();
192 OUString sSheetName;
193 args[2] >>= sSheetName;
195 uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc( mxModel, uno::UNO_QUERY_THROW );
196 uno::Reference< container::XNameAccess > xNameAccess( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
197 mxSheet.set( xNameAccess->getByName( sSheetName ), uno::UNO_QUERY_THROW );
200 ScVbaWorksheet::~ScVbaWorksheet()
204 namespace
206 class theScVbaWorksheetUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScVbaWorksheetUnoTunnelId > {};
209 const uno::Sequence<sal_Int8>& ScVbaWorksheet::getUnoTunnelId()
211 return theScVbaWorksheetUnoTunnelId::get().getSeq();
214 uno::Reference< ov::excel::XWorksheet >
215 ScVbaWorksheet::createSheetCopyInNewDoc(const OUString& aCurrSheetName)
217 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
218 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
219 uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
220 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
221 if (xRange.is())
222 xRange->Select();
223 excel::implnCopy(mxModel);
224 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
225 if (xModel.is())
227 excel::implnPaste(xModel);
229 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
230 excel::setUpDocumentModules(xSpreadDoc);
231 uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
232 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
233 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
235 ScDocShell* pShell = excel::getDocShell( xModel );
236 OUString aCodeName;
237 pShell->GetDocument().GetCodeName( 0, aCodeName );
238 return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW );
241 css::uno::Reference< ov::excel::XWorksheet >
242 ScVbaWorksheet::createSheetCopy(uno::Reference<excel::XWorksheet> xSheet, bool bAfter)
244 OUString aCurrSheetName = getName();
245 ScVbaWorksheet* pDestSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
247 uno::Reference <sheet::XSpreadsheetDocument> xDestDoc( pDestSheet->getModel(), uno::UNO_QUERY );
248 uno::Reference <sheet::XSpreadsheetDocument> xSrcDoc( getModel(), uno::UNO_QUERY );
250 SCTAB nDest = 0;
251 SCTAB nSrc = 0;
252 OUString aSheetName = xSheet->getName();
253 bool bSameDoc = ( pDestSheet->getModel() == getModel() );
254 bool bDestSheetExists = ScVbaWorksheets::nameExists (xDestDoc, aSheetName, nDest );
255 bool bSheetExists = ScVbaWorksheets::nameExists (xSrcDoc, aCurrSheetName, nSrc );
257 // set sheet name to be newSheet name
258 aSheetName = aCurrSheetName;
259 if ( bSheetExists && bDestSheetExists )
261 SCTAB nDummy=0;
262 if(bAfter)
263 nDest++;
264 uno::Reference<sheet::XSpreadsheets> xSheets = xDestDoc->getSheets();
265 if ( bSameDoc || ScVbaWorksheets::nameExists( xDestDoc, aCurrSheetName, nDummy ) )
266 getNewSpreadsheetName(aSheetName,aCurrSheetName,xDestDoc);
267 if ( bSameDoc )
268 xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
269 else
271 ScDocShell* pDestDocShell = excel::getDocShell( pDestSheet->getModel() );
272 ScDocShell* pSrcDocShell = excel::getDocShell( getModel() );
273 if ( pDestDocShell && pSrcDocShell )
274 pDestDocShell->TransferTab( *pSrcDocShell, static_cast<SCTAB>(nSrc), static_cast<SCTAB>(nDest), true, true );
277 // return new sheet
278 uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
279 uno::Reference< excel::XWorksheet > xNewSheet( xApplication->Worksheets( uno::makeAny( aSheetName ) ), uno::UNO_QUERY_THROW );
280 return xNewSheet;
283 OUString
284 ScVbaWorksheet::getName() throw (uno::RuntimeException, std::exception)
286 uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
287 return xNamed->getName();
290 void
291 ScVbaWorksheet::setName(const OUString &rName ) throw (uno::RuntimeException, std::exception)
293 uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
294 xNamed->setName( rName );
297 sal_Int32
298 ScVbaWorksheet::getVisible() throw (uno::RuntimeException, std::exception)
300 uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
301 bool bVisible = false;
302 xProps->getPropertyValue( "IsVisible" ) >>= bVisible;
303 using namespace ::ooo::vba::excel::XlSheetVisibility;
304 return bVisible ? xlSheetVisible : (mbVeryHidden ? xlSheetVeryHidden : xlSheetHidden);
307 void
308 ScVbaWorksheet::setVisible( sal_Int32 nVisible ) throw (uno::RuntimeException, std::exception)
310 using namespace ::ooo::vba::excel::XlSheetVisibility;
311 bool bVisible = true;
312 switch( nVisible )
314 case xlSheetVisible: case 1: // Excel accepts -1 and 1 for visible sheets
315 bVisible = true;
316 mbVeryHidden = false;
317 break;
318 case xlSheetHidden:
319 bVisible = false;
320 mbVeryHidden = false;
321 break;
322 case xlSheetVeryHidden:
323 bVisible = false;
324 mbVeryHidden = true;
325 break;
326 default:
327 throw uno::RuntimeException();
329 uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
330 xProps->setPropertyValue( "IsVisible", uno::Any( bVisible ) );
333 sal_Int16
334 ScVbaWorksheet::getIndex() throw (uno::RuntimeException, std::exception)
336 return getSheetID() + 1;
339 sal_Int32
340 ScVbaWorksheet::getEnableSelection() throw (uno::RuntimeException, std::exception)
342 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
343 SCTAB nTab = 0;
344 if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
346 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
347 ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
348 ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
349 bool bLockedCells = false;
350 bool bUnlockedCells = false;
351 if( pProtect )
353 bLockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
354 bUnlockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
356 if( bLockedCells )
357 return excel::XlEnableSelection::xlNoRestrictions;
358 if( bUnlockedCells )
359 return excel::XlEnableSelection::xlUnlockedCells;
360 return excel::XlEnableSelection::xlNoSelection;
362 else
363 throw uno::RuntimeException("Sheet Name does not exist." );
366 void
367 ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) throw (uno::RuntimeException, std::exception)
369 if( (nSelection != excel::XlEnableSelection::xlNoRestrictions) &&
370 (nSelection != excel::XlEnableSelection::xlUnlockedCells) &&
371 (nSelection != excel::XlEnableSelection::xlNoSelection) )
373 DebugHelper::runtimeexception(SbERR_BAD_PARAMETER, OUString() );
376 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
377 SCTAB nTab = 0;
378 if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
380 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
381 ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
382 ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
383 // default is xlNoSelection
384 bool bLockedCells = false;
385 bool bUnlockedCells = false;
386 if( nSelection == excel::XlEnableSelection::xlNoRestrictions )
388 bLockedCells = true;
389 bUnlockedCells = true;
391 else if( nSelection == excel::XlEnableSelection::xlUnlockedCells )
393 bUnlockedCells = true;
395 if( pProtect )
397 pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells );
398 pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells );
401 else
402 throw uno::RuntimeException("Sheet Name does not exist." );
406 sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() throw (uno::RuntimeException, std::exception)
408 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
409 ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
410 ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID());
411 if (pDBData)
412 return pDBData->HasAutoFilter();
413 return false;
416 void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) throw (uno::RuntimeException, std::exception)
418 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
419 ScDocShell* pDocShell = excel::getDocShell( xModel );
420 ScDocument& rDoc = pDocShell->GetDocument();
421 ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID());
422 if (pDBData)
424 pDBData->SetAutoFilter(bAutoFilterMode);
425 ScRange aRange;
426 pDBData->GetArea(aRange);
427 if (bAutoFilterMode)
428 rDoc.ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(),
429 aRange.aEnd.Col(), aRange.aStart.Row(),
430 aRange.aStart.Tab(), SC_MF_AUTO );
431 else if (!bAutoFilterMode)
432 rDoc.RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(),
433 aRange.aEnd.Col(), aRange.aStart.Row(),
434 aRange.aStart.Tab(), SC_MF_AUTO );
435 ScRange aPaintRange(aRange.aStart, aRange.aEnd);
436 aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row());
437 pDocShell->PostPaint(aPaintRange, PAINT_GRID);
441 uno::Reference< excel::XRange >
442 ScVbaWorksheet::getUsedRange() throw (uno::RuntimeException, std::exception)
444 uno::Reference< sheet::XSheetCellRange > xSheetCellRange(getSheet(), uno::UNO_QUERY_THROW );
445 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor( getSheet()->createCursorByRange( xSheetCellRange ), uno::UNO_QUERY_THROW );
446 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
447 xUsedCursor->gotoStartOfUsedArea( false );
448 xUsedCursor->gotoEndOfUsedArea( true );
449 uno::Reference< table::XCellRange > xRange( xSheetCellCursor, uno::UNO_QUERY);
450 return new ScVbaRange(this, mxContext, xRange);
453 uno::Reference< excel::XOutline >
454 ScVbaWorksheet::Outline( ) throw (uno::RuntimeException, std::exception)
456 uno::Reference<sheet::XSheetOutline> xOutline(getSheet(),uno::UNO_QUERY_THROW);
457 return new ScVbaOutline( this, mxContext, xOutline);
460 uno::Reference< excel::XPageSetup >
461 ScVbaWorksheet::PageSetup( ) throw (uno::RuntimeException, std::exception)
463 return new ScVbaPageSetup( this, mxContext, getSheet(), getModel() );
466 uno::Any
467 ScVbaWorksheet::HPageBreaks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
469 uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(getSheet(),uno::UNO_QUERY_THROW);
470 uno::Reference< excel::XHPageBreaks > xHPageBreaks( new ScVbaHPageBreaks( this, mxContext, xSheetPageBreak));
471 if ( aIndex.hasValue() )
472 return xHPageBreaks->Item( aIndex, uno::Any());
473 return uno::makeAny( xHPageBreaks );
476 uno::Any
477 ScVbaWorksheet::VPageBreaks( const uno::Any& aIndex ) throw ( uno::RuntimeException, std::exception )
479 uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak( getSheet(), uno::UNO_QUERY_THROW );
480 uno::Reference< excel::XVPageBreaks > xVPageBreaks( new ScVbaVPageBreaks( this, mxContext, xSheetPageBreak ) );
481 if( aIndex.hasValue() )
482 return xVPageBreaks->Item( aIndex, uno::Any());
483 return uno::makeAny( xVPageBreaks );
486 sal_Int32
487 ScVbaWorksheet::getStandardWidth() throw (uno::RuntimeException, std::exception)
489 return STANDARDWIDTH ;
492 sal_Int32
493 ScVbaWorksheet::getStandardHeight() throw (uno::RuntimeException, std::exception)
495 return STANDARDHEIGHT;
498 sal_Bool
499 ScVbaWorksheet::getProtectionMode() throw (uno::RuntimeException, std::exception)
501 return false;
504 sal_Bool
505 ScVbaWorksheet::getProtectContents()throw (uno::RuntimeException, std::exception)
507 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
508 return xProtectable->isProtected();
511 sal_Bool
512 ScVbaWorksheet::getProtectDrawingObjects() throw (uno::RuntimeException, std::exception)
514 SCTAB nTab = 0;
515 OUString aSheetName = getName();
516 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
517 bool bSheetExists = ScVbaWorksheets::nameExists (xSpreadDoc, aSheetName, nTab);
518 if ( bSheetExists )
520 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
521 ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
522 ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
523 if ( pProtect )
524 return pProtect->isOptionEnabled( ScTableProtection::OBJECTS );
526 return false;
529 sal_Bool
530 ScVbaWorksheet::getProtectScenarios() throw (uno::RuntimeException, std::exception)
532 return false;
535 void
536 ScVbaWorksheet::Activate() throw (uno::RuntimeException, std::exception)
538 uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
539 getModel()->getCurrentController(), uno::UNO_QUERY_THROW );
540 xSpreadsheet->setActiveSheet(getSheet());
543 void
544 ScVbaWorksheet::Select() throw (uno::RuntimeException, std::exception)
546 Activate();
549 void
550 ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException, std::exception)
552 uno::Reference<excel::XWorksheet> xSheet;
553 OUString aCurrSheetName = getName();
555 if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
557 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
558 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
559 uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
560 // #FIXME needs worksheet as parent
561 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
562 if (xRange.is())
563 xRange->Select();
564 excel::implnCopy(mxModel);
565 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
566 if (xModel.is())
568 excel::implnPaste(xModel);
569 Delete();
571 return ;
574 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
575 SCTAB nDest = 0;
576 if ( ScVbaWorksheets::nameExists (xSpreadDoc, xSheet->getName(), nDest) )
578 bool bAfter = After.hasValue();
579 if (bAfter)
580 nDest++;
581 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
582 xSheets->moveByName(aCurrSheetName,nDest);
586 void
587 ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException, std::exception)
589 uno::Reference<excel::XWorksheet> xSheet;
590 if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
592 createSheetCopyInNewDoc(getName());
593 return;
596 uno::Reference<excel::XWorksheet> xNewSheet = createSheetCopy(xSheet, After.hasValue());
597 xNewSheet->Activate();
600 void
601 ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ ) throw (uno::RuntimeException, std::exception)
603 // #TODO# #FIXME# Link is not used
604 uno::Reference<excel::XRange> xRange( Destination, uno::UNO_QUERY );
605 if ( xRange.is() )
606 xRange->Select();
607 excel::implnPaste( mxModel );
610 void
611 ScVbaWorksheet::Delete() throw (uno::RuntimeException, std::exception)
613 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
614 OUString aSheetName = getName();
615 if ( xSpreadDoc.is() )
617 SCTAB nTab = 0;
618 if (!ScVbaWorksheets::nameExists(xSpreadDoc, aSheetName, nTab ))
620 return;
622 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
623 uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
624 xNameContainer->removeByName(aSheetName);
625 mxSheet.clear();
629 uno::Reference< excel::XWorksheet >
630 ScVbaWorksheet::getSheetAtOffset(SCTAB offset) throw (uno::RuntimeException)
632 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
633 uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
634 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
636 SCTAB nIdx = 0;
637 if ( !ScVbaWorksheets::nameExists (xSpreadDoc, getName(), nIdx ) )
638 return uno::Reference< excel::XWorksheet >();
639 nIdx = nIdx + offset;
640 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(nIdx), uno::UNO_QUERY_THROW);
641 // parent will be the parent of 'this' worksheet
642 return new ScVbaWorksheet (getParent(), mxContext, xSheet, getModel());
645 uno::Reference< excel::XWorksheet >
646 ScVbaWorksheet::getNext() throw (uno::RuntimeException, std::exception)
648 return getSheetAtOffset(static_cast<SCTAB>(1));
651 uno::Reference< excel::XWorksheet >
652 ScVbaWorksheet::getPrevious() throw (uno::RuntimeException, std::exception)
654 return getSheetAtOffset(-1);
657 void
658 ScVbaWorksheet::Protect( const uno::Any& Password, const uno::Any& /*DrawingObjects*/, const uno::Any& /*Contents*/, const uno::Any& /*Scenarios*/, const uno::Any& /*UserInterfaceOnly*/ ) throw (uno::RuntimeException, std::exception)
660 // #TODO# #FIXME# is there anything we can do with the unused param
661 // can the implementation use anything else here
662 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
663 OUString aPasswd;
664 Password >>= aPasswd;
665 xProtectable->protect( aPasswd );
668 void
669 ScVbaWorksheet::Unprotect( const uno::Any& Password ) throw (uno::RuntimeException, std::exception)
671 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
672 OUString aPasswd;
673 Password >>= aPasswd;
674 xProtectable->unprotect( aPasswd );
677 void
678 ScVbaWorksheet::Calculate() throw (uno::RuntimeException, std::exception)
680 uno::Reference <sheet::XCalculatable> xReCalculate(getModel(), uno::UNO_QUERY_THROW);
681 xReCalculate->calculate();
684 uno::Reference< excel::XRange >
685 ScVbaWorksheet::Range( const ::uno::Any& Cell1, const ::uno::Any& Cell2 ) throw (uno::RuntimeException, std::exception)
687 uno::Reference< excel::XRange > xSheetRange( new ScVbaRange( this, mxContext
688 , uno::Reference< table::XCellRange >( getSheet(), uno::UNO_QUERY_THROW ) ) );
689 return xSheetRange->Range( Cell1, Cell2 );
692 void
693 ScVbaWorksheet::CheckSpelling( const uno::Any& /*CustomDictionary*/,const uno::Any& /*IgnoreUppercase*/,const uno::Any& /*AlwaysSuggest*/, const uno::Any& /*SpellingLang*/ ) throw (uno::RuntimeException, std::exception)
695 // #TODO# #FIXME# unused params above, can we do anything with those
696 OUString url = ".uno:SpellDialog";
697 uno::Reference< frame::XModel > xModel( getModel() );
698 dispatchRequests(xModel,url);
701 uno::Reference< excel::XRange >
702 ScVbaWorksheet::getSheetRange() throw (uno::RuntimeException)
704 uno::Reference< table::XCellRange > xRange( getSheet(),uno::UNO_QUERY_THROW );
705 return uno::Reference< excel::XRange >( new ScVbaRange( this, mxContext, xRange ) );
708 // These are hacks - we prolly (somehow) need to inherit
709 // the vbarange functionality here ...
710 uno::Reference< excel::XRange >
711 ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol )
712 throw (uno::RuntimeException, std::exception)
714 // Performance optimization for often-called Cells method:
715 // Use a common helper method instead of creating a new ScVbaRange object
716 uno::Reference< table::XCellRange > xRange( getSheet(), uno::UNO_QUERY_THROW );
717 return ScVbaRange::CellsHelper( this, mxContext, xRange, nRow, nCol );
720 uno::Reference< excel::XRange >
721 ScVbaWorksheet::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
723 return getSheetRange()->Rows( aIndex );
726 uno::Reference< excel::XRange >
727 ScVbaWorksheet::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
729 return getSheetRange()->Columns( aIndex );
732 uno::Any SAL_CALL
733 ScVbaWorksheet::ChartObjects( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
735 if ( !mxCharts.is() )
737 uno::Reference< table::XTableChartsSupplier > xChartSupplier( getSheet(), uno::UNO_QUERY_THROW );
738 uno::Reference< table::XTableCharts > xTableCharts = xChartSupplier->getCharts();
740 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxSheet, uno::UNO_QUERY_THROW );
741 mxCharts = new ScVbaChartObjects( this, mxContext, xTableCharts, xDrawPageSupplier );
743 if ( Index.hasValue() )
745 uno::Reference< XCollection > xColl( mxCharts, uno::UNO_QUERY_THROW );
746 return xColl->Item( Index, uno::Any() );
748 else
749 return uno::makeAny( mxCharts );
753 uno::Any SAL_CALL
754 ScVbaWorksheet::PivotTables( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
756 uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
757 uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
758 uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
760 uno::Reference< XCollection > xColl( new ScVbaPivotTables( this, mxContext, xIndexAccess ) );
761 if ( Index.hasValue() )
762 return xColl->Item( Index, uno::Any() );
763 return uno::makeAny( xColl );
766 uno::Any SAL_CALL
767 ScVbaWorksheet::Comments( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
769 uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
770 uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
771 uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
772 uno::Reference< container::XIndexAccess > xIndexAccess( xAnnos, uno::UNO_QUERY_THROW );
773 uno::Reference< XCollection > xColl( new ScVbaComments( this, mxContext, mxModel, xIndexAccess ) );
774 if ( Index.hasValue() )
775 return xColl->Item( Index, uno::Any() );
776 return uno::makeAny( xColl );
779 uno::Any SAL_CALL
780 ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
782 /* The worksheet always returns the same Hyperlinks object.
783 See vbahyperlinks.hxx for more details. */
784 if( !mxHlinks.is() )
785 mxHlinks.set( new ScVbaHyperlinks( this, mxContext ) );
786 if( aIndex.hasValue() )
787 return uno::Reference< XCollection >( mxHlinks, uno::UNO_QUERY_THROW )->Item( aIndex, uno::Any() );
788 return uno::Any( mxHlinks );
791 uno::Any SAL_CALL
792 ScVbaWorksheet::Names( const css::uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
794 // fake sheet-local names by returning all global names
795 // #163498# initialize Names object with correct parent (this worksheet)
796 // TODO: real sheet-local names...
797 uno::Reference< beans::XPropertySet > xProps( mxModel, uno::UNO_QUERY_THROW );
798 uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue("NamedRanges"), uno::UNO_QUERY_THROW );
799 uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, mxModel ) );
800 if ( aIndex.hasValue() )
801 return uno::Any( xNames->Item( aIndex, uno::Any() ) );
802 return uno::Any( xNames );
805 uno::Any SAL_CALL
806 ScVbaWorksheet::OLEObjects( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
808 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
809 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
810 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
811 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPage, uno::UNO_QUERY_THROW );
813 uno::Reference< excel::XOLEObjects >xOleObjects( new ScVbaOLEObjects( this, mxContext, xIndexAccess ) );
814 if( Index.hasValue() )
815 return xOleObjects->Item( Index, uno::Any() );
816 return uno::Any( xOleObjects );
819 uno::Any SAL_CALL
820 ScVbaWorksheet::Shapes( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
822 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
823 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
824 uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
825 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
827 uno::Reference< msforms::XShapes> xVbaShapes( new ScVbaShapes( this, mxContext, xIndexAccess, getModel() ) );
828 if ( aIndex.hasValue() )
829 return xVbaShapes->Item( aIndex, uno::Any() );
830 return uno::makeAny( xVbaShapes );
833 uno::Any SAL_CALL
834 ScVbaWorksheet::Buttons( const uno::Any& rIndex ) throw (uno::RuntimeException, std::exception)
836 if( !mxButtons.is() )
837 mxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet ) );
838 else
839 mxButtons->collectShapes();
840 if( rIndex.hasValue() )
841 return mxButtons->Item( rIndex, uno::Any() );
842 return uno::Any( uno::Reference< XCollection >( mxButtons.get() ) );
845 uno::Any SAL_CALL
846 ScVbaWorksheet::CheckBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
848 throw uno::RuntimeException();
851 uno::Any SAL_CALL
852 ScVbaWorksheet::DropDowns( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
854 throw uno::RuntimeException();
857 uno::Any SAL_CALL
858 ScVbaWorksheet::GroupBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
860 throw uno::RuntimeException();
863 uno::Any SAL_CALL
864 ScVbaWorksheet::Labels( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
866 throw uno::RuntimeException();
869 uno::Any SAL_CALL
870 ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
872 throw uno::RuntimeException();
875 uno::Any SAL_CALL
876 ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
878 throw uno::RuntimeException();
881 uno::Any SAL_CALL
882 ScVbaWorksheet::ScrollBars( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
884 throw uno::RuntimeException();
887 uno::Any SAL_CALL
888 ScVbaWorksheet::Spinners( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
890 throw uno::RuntimeException();
893 void SAL_CALL
894 ScVbaWorksheet::ShowDataForm( ) throw (uno::RuntimeException, std::exception)
896 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
897 ScTabViewShell* pTabViewShell = excel::getBestViewShell( xModel );
899 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
900 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
902 AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg(pTabViewShell->GetDialogParent(),
903 pTabViewShell);
904 OSL_ENSURE(pDlg, "Dialog create fail!");
906 pDlg->Execute();
909 uno::Any SAL_CALL
910 ScVbaWorksheet::Evaluate( const OUString& Name ) throw (uno::RuntimeException, std::exception)
912 // #TODO Evaluate allows other things to be evaluated, e.g. functions
913 // I think ( like SIN(3) etc. ) need to investigate that
914 // named Ranges also? e.g. [MyRange] if so need a list of named ranges
915 uno::Any aVoid;
916 return uno::Any( Range( uno::Any( Name ), aVoid ) );
919 uno::Reference< beans::XIntrospectionAccess > SAL_CALL
920 ScVbaWorksheet::getIntrospection( ) throw (uno::RuntimeException, std::exception)
922 return uno::Reference< beans::XIntrospectionAccess >();
925 uno::Any SAL_CALL
926 ScVbaWorksheet::invoke( const OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
928 OSL_TRACE("** ScVbaWorksheet::invoke( %s ), will barf",
929 OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
931 throw uno::RuntimeException(); // unsupported operation
934 void SAL_CALL
935 ScVbaWorksheet::setValue( const OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
937 setDefaultPropByIntrospection( getValue( aPropertyName ), aValue );
939 uno::Any SAL_CALL
940 ScVbaWorksheet::getValue( const OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
942 uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
944 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
945 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext("ooo.vba.ControlProvider", mxContext ), uno::UNO_QUERY_THROW );
946 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
947 return uno::makeAny( xControl );
950 sal_Bool SAL_CALL
951 ScVbaWorksheet::hasMethod( const OUString& /*aName*/ ) throw (uno::RuntimeException, std::exception)
953 return false;
956 uno::Reference< container::XNameAccess >
957 ScVbaWorksheet::getFormControls()
959 uno::Reference< container::XNameAccess > xFormControls;
962 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
963 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
964 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
965 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
966 // get the www-standard container ( maybe we should access the
967 // 'www-standard' by name rather than index, this seems an
968 // implementation detail
969 if( xIndexAccess->hasElements() )
970 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
973 catch( uno::Exception& )
976 return xFormControls;
979 sal_Bool SAL_CALL
980 ScVbaWorksheet::hasProperty( const OUString& aName ) throw (uno::RuntimeException, std::exception)
982 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
983 if ( xFormControls.is() )
984 return xFormControls->hasByName( aName );
985 return false;
988 uno::Any
989 ScVbaWorksheet::getControlShape( const OUString& sName )
991 // ideally we would get an XControl object but it appears an XControl
992 // implementation only exists for a Control implementation optained from the
993 // view ( e.g. in basic you would get this from
994 // thiscomponent.currentcontroller.getControl( controlModel ) )
995 // and the thing to realise is that it is only possible to get an XControl
996 // for a currently displayed control :-( often we would want to modify
997 // a control not on the active sheet. But.. you can always access the
998 // XControlShape from the DrawPage whether that is the active drawpage or not
1000 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getSheet(), uno::UNO_QUERY_THROW );
1001 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
1003 sal_Int32 nCount = xIndexAccess->getCount();
1004 for( int index = 0; index < nCount; index++ )
1006 uno::Any aUnoObj = xIndexAccess->getByIndex( index );
1007 // It seems there are some drawing objects that can not query into Control shapes?
1008 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
1009 if( xControlShape.is() )
1011 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
1012 if( sName.equals( xNamed->getName() ))
1014 return aUnoObj;
1018 return uno::Any();
1021 OUString
1022 ScVbaWorksheet::getServiceImplName()
1024 return OUString("ScVbaWorksheet");
1027 void SAL_CALL
1028 ScVbaWorksheet::setEnableCalculation( sal_Bool bEnableCalculation ) throw ( script::BasicErrorException, uno::RuntimeException, std::exception)
1030 uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
1031 xCalculatable->enableAutomaticCalculation( bEnableCalculation);
1033 sal_Bool SAL_CALL
1034 ScVbaWorksheet::getEnableCalculation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException, std::exception)
1036 uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
1037 return xCalculatable->isAutomaticCalculationEnabled();
1040 uno::Sequence< OUString >
1041 ScVbaWorksheet::getServiceNames()
1043 static uno::Sequence< OUString > aServiceNames;
1044 if ( aServiceNames.getLength() == 0 )
1046 aServiceNames.realloc( 1 );
1047 aServiceNames[ 0 ] = "ooo.vba.excel.Worksheet";
1049 return aServiceNames;
1052 OUString SAL_CALL
1053 ScVbaWorksheet::getCodeName() throw (css::uno::RuntimeException, std::exception)
1055 uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW );
1056 return xSheetProp->getPropertyValue("CodeName").get< OUString >();
1059 sal_Int16
1060 ScVbaWorksheet::getSheetID() throw (uno::RuntimeException)
1062 uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxSheet, uno::UNO_QUERY_THROW ); // if ActiveSheet, mxSheet is null.
1063 return xAddressable->getRangeAddress().Sheet;
1066 void SAL_CALL
1067 ScVbaWorksheet::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName, const uno::Any& IgnorePrintAreas ) throw (uno::RuntimeException, std::exception)
1069 sal_Int32 nTo = 0;
1070 sal_Int32 nFrom = 0;
1071 sal_Int16 nCopies = 1;
1072 bool bCollate = false;
1073 bool bSelection = false;
1074 bool bIgnorePrintAreas = false;
1075 From >>= nFrom;
1076 To >>= nTo;
1077 Copies >>= nCopies;
1078 IgnorePrintAreas >>= bIgnorePrintAreas;
1079 if ( nCopies > 1 ) // Collate only useful when more that 1 copy
1080 Collate >>= bCollate;
1082 if ( !( nFrom || nTo ) )
1083 bSelection = true;
1085 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
1086 PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection );
1089 sal_Int64 SAL_CALL
1090 ScVbaWorksheet::getSomething(const uno::Sequence<sal_Int8 > & rId) throw(uno::RuntimeException, std::exception)
1092 if (rId.getLength() == 16 &&
1093 0 == memcmp( ScVbaWorksheet::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ))
1095 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1097 return 0;
1100 namespace worksheet
1102 namespace sdecl = comphelper::service_decl;
1103 sdecl::vba_service_class_<ScVbaWorksheet, sdecl::with_args<true> > serviceImpl;
1104 extern sdecl::ServiceDecl const serviceDecl(
1105 serviceImpl,
1106 "ScVbaWorksheet",
1107 "ooo.vba.excel.Worksheet" );
1110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */